7
7
8
8
#[ derive( Debug ) ]
9
9
struct Package {
10
- from : String ,
11
- to : String ,
12
- weight : f32
10
+ sender_country : String ,
11
+ recipient_country : String ,
12
+ weight_in_grams : i32 ,
13
13
}
14
14
15
15
impl 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 {
18
18
// Something goes here...
19
19
} else {
20
- return Package { from , to , weight } ;
20
+ return Package { sender_country , recipient_country , weight_in_grams } ;
21
21
}
22
22
}
23
23
24
24
fn is_international ( & self ) -> ??? {
25
25
// Something goes here...
26
26
}
27
27
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)
30
30
}
31
31
}
32
32
@@ -37,31 +37,31 @@ mod tests {
37
37
#[ test]
38
38
#[ should_panic]
39
39
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" ) ;
42
42
43
- Package :: new ( country_from , country_to , -2.21 ) ;
43
+ Package :: new ( sender_country , recipient_country , -2210 ) ;
44
44
}
45
45
46
46
#[ test]
47
47
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" ) ;
50
50
51
- let package = Package :: new ( country_from , country_to , 1.2 ) ;
51
+ let package = Package :: new ( sender_country , recipient_country , 1200 ) ;
52
52
53
53
assert ! ( package. is_international( ) ) ;
54
54
}
55
55
56
56
#[ test]
57
57
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" ) ;
60
60
61
- let country_fee = ???;
61
+ let cents_per_kg = ???;
62
62
63
- let package = Package :: new ( country_from , country_to , 22.0 ) ;
63
+ let package = Package :: new ( sender_country , recipient_country , 1500 ) ;
64
64
65
- assert_eq ! ( package. get_fees( country_fee ) , 176.0 ) ;
65
+ assert_eq ! ( package. get_fees( cents_per_kg ) , 4500 ) ;
66
66
}
67
67
}
0 commit comments