mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-10 12:49: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
|
// 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!
|
// the price of an order of apples given the quantity bought. No hints this time!
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
// Put your function here!
|
// Put your function here!
|
||||||
// fn ..... {
|
fn calculate_apple_price(quantity: u32) -> u32 {
|
||||||
|
if quantity <= 40 {
|
||||||
|
quantity * 2
|
||||||
|
} else {
|
||||||
|
quantity
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Don't modify this function!
|
// Don't modify this function!
|
||||||
#[test]
|
#[test]
|
||||||
fn verify_test() {
|
fn verify_test() {
|
||||||
let price1 = calculate_apple_price(35);
|
let price1: u32 = calculate_apple_price(35);
|
||||||
let price2 = calculate_apple_price(40);
|
let price2: u32 = calculate_apple_price(40);
|
||||||
let price3 = calculate_apple_price(65);
|
let price3: u32 = calculate_apple_price(65);
|
||||||
|
|
||||||
assert_eq!(70, price1);
|
assert_eq!(70, price1);
|
||||||
assert_eq!(80, price2);
|
assert_eq!(80, price2);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user