Skip to content

Commit f35ec40

Browse files
committed
feat(tiered_pricing): 🔵 refactoring implementation first pricing range
1 parent dab27bf commit f35ec40

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package tv.codely.checkout;
22

33
public 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
}

exercises/tiered_pricing/solutions/oflorez/src/test/java/tv/codely/checkout/TieredPricingShould.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@
22

33
import org.junit.jupiter.api.Test;
44

5+
import java.util.stream.IntStream;
6+
57
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
import static tv.codely.checkout.TieredPricing.*;
69

710
public 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
}

0 commit comments

Comments
 (0)