77
88#[ derive( Debug ) ]
99struct Package {
10- from : String ,
11- to : String ,
12- weight : f32
10+ sender_country : String ,
11+ recipient_country : String ,
12+ weight_in_grams : i32 ,
1313}
1414
1515impl Package {
16- fn new ( from : String , to : String , weight : f32 ) -> Package {
17- if weight <= 0. 0 {
16+ fn new ( sender_country : String , recipient_country : String , weight_in_grams : i32 ) -> Package {
17+ if weight_in_grams <= 0 {
1818 // Something goes here...
1919 } else {
20- return Package { from , to , weight } ;
20+ return Package { sender_country , recipient_country , weight_in_grams } ;
2121 }
2222 }
2323
2424 fn is_international ( & self ) -> ??? {
2525 // Something goes here...
2626 }
2727
28- fn get_fees ( & self , cost_per_kg : f32 ) -> ??? {
29- // Something goes here...
28+ fn get_fees ( & self , cents_per_kg : i32 ) -> ??? {
29+ // Something goes here... (beware of grams to kg conversion)
3030 }
3131}
3232
@@ -37,31 +37,31 @@ mod tests {
3737 #[ test]
3838 #[ should_panic]
3939 fn fail_creating_weightless_package ( ) {
40- let country_from = String :: from ( "Spain" ) ;
41- let country_to = String :: from ( "Austria" ) ;
40+ let sender_country = String :: from ( "Spain" ) ;
41+ let recipient_country = String :: from ( "Austria" ) ;
4242
43- Package :: new ( country_from , country_to , -2.21 ) ;
43+ Package :: new ( sender_country , recipient_country , -2210 ) ;
4444 }
4545
4646 #[ test]
4747 fn create_international_package ( ) {
48- let country_from = String :: from ( "Spain" ) ;
49- let country_to = String :: from ( "Russia" ) ;
48+ let sender_country = String :: from ( "Spain" ) ;
49+ let recipient_country = String :: from ( "Russia" ) ;
5050
51- let package = Package :: new ( country_from , country_to , 1.2 ) ;
51+ let package = Package :: new ( sender_country , recipient_country , 1200 ) ;
5252
5353 assert ! ( package. is_international( ) ) ;
5454 }
5555
5656 #[ test]
5757 fn calculate_transport_fees ( ) {
58- let country_from = String :: from ( "Spain" ) ;
59- let country_to = String :: from ( "Spain" ) ;
58+ let sender_country = String :: from ( "Spain" ) ;
59+ let recipient_country = String :: from ( "Spain" ) ;
6060
61- let country_fee = ???;
61+ let cents_per_kg = ???;
6262
63- let package = Package :: new ( country_from , country_to , 22.0 ) ;
63+ let package = Package :: new ( sender_country , recipient_country , 1500 ) ;
6464
65- assert_eq ! ( package. get_fees( country_fee ) , 176.0 ) ;
65+ assert_eq ! ( package. get_fees( cents_per_kg ) , 4500 ) ;
6666 }
6767}
0 commit comments