Skip to content

Commit 30f5d44

Browse files
committed
implement obvious implementation
1 parent 391bf18 commit 30f5d44

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed
Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
11
export class Subscription {
2-
constructor(private units: number) {}
2+
private tieredPrice!: number;
3+
4+
constructor(private units: number) {
5+
this.setTieredPrice();
6+
}
7+
8+
private setTieredPrice() {
9+
if (this.units < 3) {
10+
this.tieredPrice = 299;
11+
} else if (this.units < 11) {
12+
this.tieredPrice = 239;
13+
} else if (this.units < 26) {
14+
this.tieredPrice = 219;
15+
} else if (this.units < 51) {
16+
this.tieredPrice = 199;
17+
} else {
18+
this.tieredPrice = 149;
19+
}
20+
}
321

422
getTotalPrice() {
5-
return 299;
23+
return this.tieredPrice * this.units;
624
}
725
}

exercises/tiered_pricing/solutions/aortiz_typescript/tests/Subscription.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,34 @@ describe("Subscription", () => {
1010

1111
expect(subscription.getTotalPrice()).toBe(299);
1212
});
13+
14+
it("can be calculate subscription price of 2 unit", () => {
15+
const subscription = new Subscription(1);
16+
17+
expect(subscription.getTotalPrice()).toBe(598);
18+
});
19+
20+
it("can be calculate subscription price of 10 units", () => {
21+
const subscription = new Subscription(10);
22+
23+
expect(subscription.getTotalPrice()).toBe(2390);
24+
});
25+
26+
it("can be calculate subscription price of 25 units", () => {
27+
const subscription = new Subscription(25);
28+
29+
expect(subscription.getTotalPrice()).toBe(5475);
30+
});
31+
32+
it("can be calculate subscription price of 50 units", () => {
33+
const subscription = new Subscription(50);
34+
35+
expect(subscription.getTotalPrice()).toBe(9950);
36+
});
37+
38+
it("can be calculate subscription price of 68 units", () => {
39+
const subscription = new Subscription(68);
40+
41+
expect(subscription.getTotalPrice()).toBe(10132);
42+
});
1343
});

0 commit comments

Comments
 (0)