Skip to content

Commit 807ee95

Browse files
committed
🔴 Add test for 0 subscriptions
1 parent b4354ee commit 807ee95

File tree

1 file changed

+41
-26
lines changed

1 file changed

+41
-26
lines changed
Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
fn get_total_subscription_price(number_of_subscriptions: u32) -> u32 {
1+
fn get_total_subscription_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;
55
const FOURTH_UNIT_PRICE: u32 = 199;
66
const FIFTH_UNIT_PRICE: u32 = 149;
77

88
match number_of_subscriptions {
9-
1|2 => FIRST_UNIT_PRICE * number_of_subscriptions,
10-
3..=10 => SECOND_UNIT_PRICE * number_of_subscriptions,
11-
11..=25 => THIRD_UNIT_PRICE * number_of_subscriptions,
12-
26..=50 => FOURTH_UNIT_PRICE * number_of_subscriptions,
13-
_ => FIFTH_UNIT_PRICE * number_of_subscriptions,
9+
1|2 => Ok(FIRST_UNIT_PRICE * number_of_subscriptions),
10+
3..=10 => Ok(SECOND_UNIT_PRICE * number_of_subscriptions),
11+
11..=25 => Ok(THIRD_UNIT_PRICE * number_of_subscriptions),
12+
26..=50 => Ok(FOURTH_UNIT_PRICE * number_of_subscriptions),
13+
_ => Ok(FIFTH_UNIT_PRICE * number_of_subscriptions),
1414
}
1515
}
1616

@@ -19,52 +19,67 @@ mod tests {
1919
use crate::tiered_pricing::get_total_subscription_price;
2020

2121
#[test]
22-
fn when_get_a_subscription_return_299_euros() {
23-
assert_eq!(299, get_total_subscription_price(1));
22+
fn when_get_a_subscription_return_299_euros() -> Result<(), String> {
23+
assert_eq!(299, get_total_subscription_price(1)?);
24+
Ok(())
2425
}
2526

2627
#[test]
27-
fn when_get_2_subscriptions_return_598_euros() {
28-
assert_eq!(598, get_total_subscription_price(2));
28+
fn when_get_2_subscriptions_return_598_euros() -> Result<(), String> {
29+
assert_eq!(598, get_total_subscription_price(2)?);
30+
Ok(())
2931
}
3032

3133
#[test]
32-
fn when_get_3_subscriptions_return_717_euros() {
33-
assert_eq!(717, get_total_subscription_price(3));
34+
fn when_get_3_subscriptions_return_717_euros() -> Result<(), String> {
35+
assert_eq!(717, get_total_subscription_price(3)?);
36+
Ok(())
3437
}
3538

3639
#[test]
37-
fn when_get_10_subscriptions_return_2390_euros() {
38-
assert_eq!(2390, get_total_subscription_price(10));
40+
fn when_get_10_subscriptions_return_2390_euros() -> Result<(), String> {
41+
assert_eq!(2390, get_total_subscription_price(10)?);
42+
Ok(())
3943
}
4044

4145
#[test]
42-
fn when_get_11_subscriptions_return_2409_euros() {
43-
assert_eq!(2409, get_total_subscription_price(11));
46+
fn when_get_11_subscriptions_return_2409_euros() -> Result<(), String> {
47+
assert_eq!(2409, get_total_subscription_price(11)?);
48+
Ok(())
4449
}
4550

4651
#[test]
47-
fn when_get_25_subscriptions_return_5475_euros() {
48-
assert_eq!(5475, get_total_subscription_price(25));
52+
fn when_get_25_subscriptions_return_5475_euros() -> Result<(), String> {
53+
assert_eq!(5475, get_total_subscription_price(25)?);
54+
Ok(())
4955
}
5056

5157
#[test]
52-
fn when_get_26_subscriptions_return_5174_euros() {
53-
assert_eq!(5174, get_total_subscription_price(26));
58+
fn when_get_26_subscriptions_return_5174_euros() -> Result<(), String> {
59+
assert_eq!(5174, get_total_subscription_price(26)?);
60+
Ok(())
5461
}
5562

5663
#[test]
57-
fn when_get_50_subscriptions_return_9950_euros() {
58-
assert_eq!(9950, get_total_subscription_price(50));
64+
fn when_get_50_subscriptions_return_9950_euros() -> Result<(), String> {
65+
assert_eq!(9950, get_total_subscription_price(50)?);
66+
Ok(())
5967
}
6068

6169
#[test]
62-
fn when_get_51_subscriptions_return_7599_euros() {
63-
assert_eq!(7599, get_total_subscription_price(51));
70+
fn when_get_51_subscriptions_return_7599_euros() -> Result<(), String> {
71+
assert_eq!(7599, get_total_subscription_price(51)?);
72+
Ok(())
6473
}
6574

6675
#[test]
67-
fn when_get_52_subscriptions_return_7748_euros() {
68-
assert_eq!(7748, get_total_subscription_price(52));
76+
fn when_get_52_subscriptions_return_7748_euros() -> Result<(), String> {
77+
assert_eq!(7748, get_total_subscription_price(52)?);
78+
Ok(())
79+
}
80+
81+
#[test]
82+
fn when_get_0_subscriptions_return_error() {
83+
assert!(get_total_subscription_price(0).is_err());
6984
}
7085
}

0 commit comments

Comments
 (0)