File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
exercises/tiered_pricing/solutions/mperezi/src
main/java/tv/codely/checkout
test/java/tv/codely/checkout Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -8,12 +8,17 @@ private enum Tier {
88 FIRST (299.0 , 1 , 2 ),
99 SECOND (239.0 , 3 , 10 ),
1010 THIRD (219.0 , 11 , 25 ),
11- FOURTH (199.0 , 26 , 50 );
11+ FOURTH (199.0 , 26 , 50 ),
12+ LAST (149.0 , 51 );
1213
1314 final double unitPrice ;
1415 final int startRange ;
1516 final int endRange ;
1617
18+ Tier (double unitPrice , int startRange ) {
19+ this (unitPrice , startRange , -1 );
20+ }
21+
1722 Tier (double unitPrice , int startRange , int endRange ) {
1823 this .unitPrice = unitPrice ;
1924 this .startRange = startRange ;
@@ -24,7 +29,7 @@ static Tier of(int subscriptions) {
2429 return Arrays .stream (values ())
2530 .filter (tier -> subscriptions >= tier .startRange && subscriptions <= tier .endRange )
2631 .findFirst ()
27- .orElseThrow (() -> new IllegalArgumentException ( "Invalid number of subscriptions: " + subscriptions ) );
32+ .orElse ( LAST );
2833 }
2934 }
3035
Original file line number Diff line number Diff line change 33import org .junit .jupiter .api .BeforeEach ;
44import org .junit .jupiter .params .ParameterizedTest ;
55import org .junit .jupiter .params .provider .MethodSource ;
6+ import org .junit .jupiter .params .provider .ValueSource ;
67
78import java .util .stream .IntStream ;
89import java .util .stream .Stream ;
@@ -50,6 +51,14 @@ void returnTotalPriceForFourthTier(int subscriptions) {
5051 assertThat (totalPrice ).isEqualTo (subscriptions * 199.0 );
5152 }
5253
54+ @ ParameterizedTest
55+ @ ValueSource (ints = {51 , 1000 })
56+ void returnTotalPriceForLastTier (int subscriptions ) {
57+ double totalPrice = tieredPricing .totalPrice (subscriptions );
58+
59+ assertThat (totalPrice ).isEqualTo (subscriptions * 149.0 );
60+ }
61+
5362 private static Stream <Integer > rangeFirstTier () {
5463 return IntStream .rangeClosed (1 , 2 ).boxed ();
5564 }
You can’t perform that action at this time.
0 commit comments