Evaluations/Write 20k Rust Code Snippets & Unit Tests
main
prompts.parquet
text → text
QwenQwen/Qwen 2.5 Coder 32B Instruct
Fireworks AI Fireworks AI
code_and_tests
You are a pragmatic Rust programmer who enjoys test driven development. Given the following question, write a Rust function to complete the task. Make the code simple and easy to understand. The code should pass `cargo build` and `cargo clippy`. Do not add a main function. Try to limit library usage to the standard library std. Respond with only the Rust function and nothing else. Be careful with your types, and try to limit yourself to the basic built in types and standard library functions.

When writing the function you can think through how to solve the problem and perform reasoning in the comments above the function.

Then write unit tests for the function you defined. Write three unit tests for the function. The tests should be a simple line delimited list of assert! or assert_eq! statements. An example output should look like the following:

```rust
/// Reasoning goes here
/// and can be multi-line
fn add_nums(x: i32, y: i32) -> i32 {
  x + y
}
```

```tests
// Test adding small positive numbers
assert_eq!(add_nums(1, 2), 3);
// Test adding two negative numbers
assert_eq!(add_nums(-10, -2), -14);
// Test adding a positive and a negative number
assert_eq!(add_nums(-10, 2), 8);
```

Make sure to only respond with two blocks, a ```rust``` block and a ```tests``` block.

Here is the question:
{rust_prompt}
Mar 1, 2025, 1:13 AM UTC
Mar 1, 2025, 1:14 AM UTC
00:00:30
5 row sample
4310 tokens$ 0.0039
5 rows processed, 4310 tokens used ($0.0039)
Estimated cost for all 20000 rows: $15.52
Sample Results completed
3 columns, 1-5 of 20000 rows
task_id
rust_prompt
task_0
Implement a function `echo_nums(x, y)` that takes two integers, `x` and `y`, and returns a vector of all numerical values within the range from `x` to `y`, inclusive. The function should handle cases where `x` is greater than `y` by returning an empty vector.
task_1
Given the coordinates of a point on the x-axis and the center coordinates of a circle, along with the radius of the circle, write a function `circle_y_coordinate(x: f32, r: f32, cx: f32, cy: f32) -> f32` that returns the y-coordinate of the point on the circumference of the circle. The y-coordinate should be calculated using the formula for a circle: y = sqrt(r^2 - (x - cx)^2) + cy, where (cx, cy) is the center of the circle. If the point (x, y) does not lie within the circle, the function should return -1. The function should handle cases where the square root calculation results in a negative number by returning -1 for those cases. The inputs are guaranteed to be valid f32 numbers.
task_2
You are given a vector of integer vectors, where each inner vector represents a group of integers. Write a function that takes this vector and returns a new vector of integers, where each integer is the sum of the integers in the corresponding inner vector. The input vector will not be empty and each inner vector will contain at least one integer. Your function should be able to handle vectors of varying lengths. Implement the function `aggregate_sums(int_lists: Vec<Vec<i32>>) -> Vec<i32>`.
task_3
You are tasked with creating a function that simulates basic operations of a banking system. The function should allow users to manage multiple accounts by creating accounts, depositing funds, withdrawing funds, and checking account balances. The function should take the following parameters: a vector of operations, where each operation is a tuple consisting of an action and its relevant parameters. The actions can be 'create', 'deposit', 'withdraw', or 'check'. The function should return a vector of results for each 'check' operation. If a withdrawal is attempted for an amount greater than the available balance, the function should return "Insufficient Funds" for that operation. Your function should maintain account balances separately for each account number. Implement the function `banking_system(operations: Vec<(String, Vec<String>)>) -> Vec<String>` where: - `operations` is a vector of tuples, each containing an action and its parameters. - An action 'create' has the parameter: (account_number). - An action 'deposit' has the parameters: (account_number, amount). - An action 'withdraw' has the parameters: (account_number, amount). - An action 'check' has the parameter: (account_number).
task_4
You are given two integers, num1 and num2. Your task is to create a function that takes these two integers as input and performs the following operations based on a user's choice: 1 for addition, 2 for multiplication, 3 for finding the greater number, and 4 for entering new numbers. The function should return the result of the chosen operation. If the user chooses to enter new numbers, the function should return a tuple of the new numbers instead. The function should also handle invalid choices by returning 'Invalid choice'. The input to the function will be a vector of operations where each operation is represented by a struct containing the operation type and the necessary input values. Design your function to process these operations sequentially and return the results.