File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
src/using-polymorphism-for-variation/rating Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -36,11 +36,15 @@ export class Rating {
3636
3737 get voyageAndHistoryLengthFactor ( ) {
3838 let result = 0 ;
39- if ( this . history . length > 8 ) result += 1 ;
39+ result += this . historyLengthFactor ;
4040 if ( this . voyage . length > 14 ) result -= 1 ;
4141 return result ;
4242 }
4343
44+ get historyLengthFactor ( ) {
45+ return this . history . length > 8 ? 1 : 0 ;
46+ }
47+
4448 get hasChinaHistory ( ) {
4549 return this . history . some ( v => 'china' === v . zone ) ;
4650 }
Original file line number Diff line number Diff line change @@ -140,6 +140,20 @@ describe('Rating', () => {
140140 expect ( rating . voyageAndHistoryLengthFactor ) . toEqual ( - 1 ) ;
141141 } ) ;
142142 } ) ;
143+
144+ describe ( 'historyLengthFactor' , ( ) => {
145+ it ( 'should return 0 if history length is less than 8' , ( ) => {
146+ const history = Array . from ( { length : 7 } , ( ) => latamVoyage ) ;
147+ const rating = new Rating ( latamVoyage , history ) ;
148+ expect ( rating . historyLengthFactor ) . toEqual ( 0 ) ;
149+ } ) ;
150+
151+ it ( 'should return 1 if history length is more than 8' , ( ) => {
152+ const history = Array . from ( { length : 9 } , ( ) => latamVoyage ) ;
153+ const rating = new Rating ( latamVoyage , history ) ;
154+ expect ( rating . historyLengthFactor ) . toEqual ( 1 ) ;
155+ } ) ;
156+ } ) ;
143157} ) ;
144158
145159describe ( 'ExperiencedChinaRating' , ( ) => {
You can’t perform that action at this time.
0 commit comments