rustlings

solving rustlings ft. dracuxan
git clone [email protected]:dracuxan/rustlings.git
Log | Files | Refs

quiz1.rs (762B)


      1 // Mary is buying apples. The price of an apple is calculated as follows:
      2 // - An apple costs 2 rustbucks.
      3 // - However, if Mary buys more than 40 apples, the price of each apple in the
      4 // entire order is reduced to only 1 rustbuck!
      5 
      6 fn calculate_price_of_apples(n_apples: u64) -> u64 {
      7     if n_apples > 40 {
      8         n_apples
      9     } else {
     10         2 * n_apples
     11     }
     12 }
     13 
     14 fn main() {
     15     // You can optionally experiment here.
     16 }
     17 
     18 // Don't change the tests!
     19 #[cfg(test)]
     20 mod tests {
     21     use super::*;
     22 
     23     #[test]
     24     fn verify_test() {
     25         assert_eq!(calculate_price_of_apples(35), 70);
     26         assert_eq!(calculate_price_of_apples(40), 80);
     27         assert_eq!(calculate_price_of_apples(41), 41);
     28         assert_eq!(calculate_price_of_apples(65), 65);
     29     }
     30 }