diff options
| author | fmoko <mokou@posteo.de> | 2020-06-22 00:09:09 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-22 00:09:09 +0200 |
| commit | 75c0053bb1332850fb98407b1ece2c8e3e1c6f64 (patch) | |
| tree | 6a6a7e40d1fb0917909c1f7ac3137ba025ecaad3 | |
| parent | 113cdae2d4e4c55905e8056ad326ede7fd7de356 (diff) | |
| parent | 9ca08b8f2b09366e97896a4a8cf9ff3bb4d54380 (diff) | |
Merge pull request #433 from SebastienCaunes/fix#432
fix : Use of integer for prices, therefore also for weight
| -rw-r--r-- | exercises/structs/structs3.rs | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/exercises/structs/structs3.rs b/exercises/structs/structs3.rs index 77cc154..5503ce1 100644 --- a/exercises/structs/structs3.rs +++ b/exercises/structs/structs3.rs @@ -7,17 +7,17 @@ #[derive(Debug)] struct Package { - from: String, - to: String, - weight: f32 + sender_country: String, + recipient_country: String, + weight_in_grams: i32, } impl Package { - fn new(from: String, to: String, weight: f32) -> Package { - if weight <= 0.0 { + fn new(sender_country: String, recipient_country: String, weight_in_grams: i32) -> Package { + if weight_in_grams <= 0 { // Something goes here... } else { - return Package {from, to, weight}; + return Package {sender_country, recipient_country, weight_in_grams}; } } @@ -25,8 +25,8 @@ impl Package { // Something goes here... } - fn get_fees(&self, cost_per_kg: f32) -> ??? { - // Something goes here... + fn get_fees(&self, cents_per_kg: i32) -> ??? { + // Something goes here... (beware of grams to kg conversion) } } @@ -37,31 +37,31 @@ mod tests { #[test] #[should_panic] fn fail_creating_weightless_package() { - let country_from = String::from("Spain"); - let country_to = String::from("Austria"); + let sender_country = String::from("Spain"); + let recipient_country = String::from("Austria"); - Package::new(country_from, country_to, -2.21); + Package::new(sender_country, recipient_country, -2210); } #[test] fn create_international_package() { - let country_from = String::from("Spain"); - let country_to = String::from("Russia"); + let sender_country = String::from("Spain"); + let recipient_country = String::from("Russia"); - let package = Package::new(country_from, country_to, 1.2); + let package = Package::new(sender_country, recipient_country, 1200); assert!(package.is_international()); } #[test] fn calculate_transport_fees() { - let country_from = String::from("Spain"); - let country_to = String::from("Spain"); + let sender_country = String::from("Spain"); + let recipient_country = String::from("Spain"); - let country_fee = ???; + let cents_per_kg = ???; - let package = Package::new(country_from, country_to, 22.0); + let package = Package::new(sender_country, recipient_country, 1500); - assert_eq!(package.get_fees(country_fee), 176.0); + assert_eq!(package.get_fees(cents_per_kg), 4500); } } |
