File tree Expand file tree Collapse file tree 2 files changed +50
-2
lines changed
exercises/tiered_pricing/solutions/aortiz_typescript Expand file tree Collapse file tree 2 files changed +50
-2
lines changed Original file line number Diff line number Diff line change 11export 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}
Original file line number Diff line number Diff 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} ) ;
You can’t perform that action at this time.
0 commit comments