1- fn get_total_subscription_price ( number_of_subscriptions : u32 ) -> Result < u32 , String > {
1+ fn get_unit_price ( number_of_subscriptions : u32 ) -> Result < u32 , String > {
22 const FIRST_UNIT_PRICE : u32 = 299 ;
33 const SECOND_UNIT_PRICE : u32 = 239 ;
44 const THIRD_UNIT_PRICE : u32 = 219 ;
@@ -7,14 +7,18 @@ fn get_total_subscription_price(number_of_subscriptions: u32) -> Result<u32, Str
77
88 match number_of_subscriptions {
99 0 => Err ( "Error" . to_string ( ) ) ,
10- 1 |2 => Ok ( FIRST_UNIT_PRICE * number_of_subscriptions ) ,
11- 3 ..=10 => Ok ( SECOND_UNIT_PRICE * number_of_subscriptions ) ,
12- 11 ..=25 => Ok ( THIRD_UNIT_PRICE * number_of_subscriptions ) ,
13- 26 ..=50 => Ok ( FOURTH_UNIT_PRICE * number_of_subscriptions ) ,
14- _ => Ok ( FIFTH_UNIT_PRICE * number_of_subscriptions ) ,
10+ 1 |2 => Ok ( FIRST_UNIT_PRICE ) ,
11+ 3 ..=10 => Ok ( SECOND_UNIT_PRICE ) ,
12+ 11 ..=25 => Ok ( THIRD_UNIT_PRICE ) ,
13+ 26 ..=50 => Ok ( FOURTH_UNIT_PRICE ) ,
14+ _ => Ok ( FIFTH_UNIT_PRICE ) ,
1515 }
1616}
1717
18+ fn get_total_subscription_price ( number_of_subscriptions : u32 ) -> Result < u32 , String > {
19+ Ok ( number_of_subscriptions * get_unit_price ( number_of_subscriptions) ?)
20+ }
21+
1822#[ cfg( test) ]
1923mod tests {
2024 use crate :: tiered_pricing:: get_total_subscription_price;
0 commit comments