File tree Expand file tree Collapse file tree 2 files changed +14
-12
lines changed
exercises/tiered_pricing/solutions/oflorez/src
main/java/tv/codely/checkout
test/java/tv/codely/checkout Expand file tree Collapse file tree 2 files changed +14
-12
lines changed Original file line number Diff line number Diff line change 11package tv .codely .checkout ;
22
33public class TieredPricing {
4- public int calculateTotalPrice (int i ) {
5- if (i == 2 ) return 598 ;
6- return 299 ;
4+
5+ public static final int FIRST_RANGE_UNIT_PRICE = 299 ;
6+ public static final int FIRST_RANGE_LOWER_LIMIT = 1 ;
7+ public static final int FIRST_RANGE_UPPER_LIMIT = 2 ;
8+
9+ public int calculateTotalPrice (int amount_subscriptions ) {
10+ if (amount_subscriptions >= FIRST_RANGE_LOWER_LIMIT && amount_subscriptions <= FIRST_RANGE_UPPER_LIMIT ) return amount_subscriptions * FIRST_RANGE_UNIT_PRICE ;
11+ return 0 ;
712 }
813}
Original file line number Diff line number Diff line change 22
33import org .junit .jupiter .api .Test ;
44
5+ import java .util .stream .IntStream ;
6+
57import static org .junit .jupiter .api .Assertions .assertEquals ;
8+ import static tv .codely .checkout .TieredPricing .*;
69
710public class TieredPricingShould {
811
912 @ Test
10- void return_total_price_299_for_1_subscription () {
13+ void calculate_total_value_for_first_pricing_range () {
1114 var pricing = new TieredPricing ();
12- assertEquals (299 , pricing .calculateTotalPrice (1 ));
15+ var subscription = IntStream .rangeClosed (FIRST_RANGE_LOWER_LIMIT , FIRST_RANGE_UPPER_LIMIT ).findAny ().getAsInt ();
16+ assertEquals (FIRST_RANGE_UNIT_PRICE * subscription , pricing .calculateTotalPrice (subscription ));
1317 }
14-
15- @ Test
16- void return_total_price_299_for_2_subscription () {
17- var pricing = new TieredPricing ();
18- assertEquals (598 , pricing .calculateTotalPrice (2 ));
19- }
20-
2118}
You can’t perform that action at this time.
0 commit comments