mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-09 12:19:18 +00:00
Solve quiz1.
This commit is contained in:
parent
6611ddff66
commit
93723faa6f
@ -7,17 +7,21 @@
|
||||
// more than 40 at once, each apple only costs 1! Write a function that calculates
|
||||
// the price of an order of apples given the quantity bought. No hints this time!
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
// Put your function here!
|
||||
// fn ..... {
|
||||
fn calculate_apple_price(quantity: u32) -> u32 {
|
||||
if quantity <= 40 {
|
||||
quantity * 2
|
||||
} else {
|
||||
quantity
|
||||
}
|
||||
}
|
||||
|
||||
// Don't modify this function!
|
||||
#[test]
|
||||
fn verify_test() {
|
||||
let price1 = calculate_apple_price(35);
|
||||
let price2 = calculate_apple_price(40);
|
||||
let price3 = calculate_apple_price(65);
|
||||
let price1: u32 = calculate_apple_price(35);
|
||||
let price2: u32 = calculate_apple_price(40);
|
||||
let price3: u32 = calculate_apple_price(65);
|
||||
|
||||
assert_eq!(70, price1);
|
||||
assert_eq!(80, price2);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user