File tree Expand file tree Collapse file tree 2 files changed +24
-7
lines changed
examples/js/js-bonus-01_base Expand file tree Collapse file tree 2 files changed +24
-7
lines changed Original file line number Diff line number Diff line change 11export class DailyBonusPointsCalculator {
2- POINTS_PER_DAY = 10 ;
2+ PREMIUM_USER_POINTS_PER_DAY = 20 ;
3+ NORMAL_USER_POINTS_PER_DAY = 10 ;
34
4- calculate ( consecutiveDays ) {
5- return consecutiveDays * this . POINTS_PER_DAY ;
5+ calculate ( consecutiveDays , isPremium ) {
6+ if ( isPremium ) {
7+ return consecutiveDays * this . PREMIUM_USER_POINTS_PER_DAY ;
8+ } else {
9+ return consecutiveDays * this . NORMAL_USER_POINTS_PER_DAY ;
10+ }
611 }
712}
Original file line number Diff line number Diff line change 11import { DailyBonusPointsCalculator } from "../src/DailyBonusPointsCalculator" ;
22
33describe ( 'DailyBonusPointsCalculator should' , ( ) => {
4- it ( 'Calculate points for a user on its first day' , ( ) => {
4+ it ( 'Calculate points for a normal user on its first day' , ( ) => {
55 const calculator = new DailyBonusPointsCalculator ( ) ;
66
7- expect ( calculator . calculate ( 1 ) ) . toBe ( 10 ) ;
7+ expect ( calculator . calculate ( 1 , false ) ) . toBe ( 10 ) ;
88 } ) ;
99
10- it ( 'Calculate points for a user on its second consecutive week' , ( ) => {
10+ it ( 'Calculate points for a normal user on its second consecutive week' , ( ) => {
1111 const calculator = new DailyBonusPointsCalculator ( ) ;
1212
13- expect ( calculator . calculate ( 14 ) ) . toBe ( 140 ) ;
13+ expect ( calculator . calculate ( 14 , false ) ) . toBe ( 140 ) ;
14+ } ) ;
15+
16+ it ( 'Calculate points for a premium user on its first day' , ( ) => {
17+ const calculator = new DailyBonusPointsCalculator ( ) ;
18+
19+ expect ( calculator . calculate ( 1 , true ) ) . toBe ( 20 ) ;
20+ } ) ;
21+
22+ it ( 'Calculate points for a premium user on its second consecutive week' , ( ) => {
23+ const calculator = new DailyBonusPointsCalculator ( ) ;
24+
25+ expect ( calculator . calculate ( 14 , true ) ) . toBe ( 280 ) ;
1426 } ) ;
1527} ) ;
You can’t perform that action at this time.
0 commit comments