Skip to content

Commit e941856

Browse files
committed
ex-2: move call to historyLengthFactor to Rating superclass
1 parent cc25aa5 commit e941856

File tree

2 files changed

+1
-14
lines changed

2 files changed

+1
-14
lines changed

src/using-polymorphism-for-variation/rating/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ export class Rating {
3030
let result = 2;
3131
if (this.voyage.zone === 'china') result += 1;
3232
if (this.voyage.zone === 'east-indies') result += 1;
33+
result += this.historyLengthFactor;
3334
result += this.voyageAndHistoryLengthFactor;
3435
return result;
3536
}
3637

3738
get voyageAndHistoryLengthFactor() {
3839
let result = 0;
39-
result += this.historyLengthFactor;
4040
if (this.voyage.length > 14) result -= 1;
4141
return result;
4242
}
@@ -59,7 +59,6 @@ export class ExperiencedChinaRating extends Rating {
5959
get voyageAndHistoryLengthFactor() {
6060
let result = 0;
6161
result += 3;
62-
result += this.historyLengthFactor;
6362
if (this.voyage.length > 12) result += 1;
6463
if (this.voyage.length > 18) result -= 1;
6564
return result;

src/using-polymorphism-for-variation/rating/index.test.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,6 @@ describe('Rating', () => {
128128
expect(rating.voyageAndHistoryLengthFactor).toEqual(0);
129129
});
130130

131-
it('should add 1 point if history has more than 8 trips', () => {
132-
const history = Array.from({ length: 9 }, () => latamVoyage);
133-
const rating = new Rating(latamVoyage, history);
134-
expect(rating.voyageAndHistoryLengthFactor).toEqual(1);
135-
});
136-
137131
it('should remove 1 point if voyage length is greater than 14', () => {
138132
const voyage = { zone: 'latam', length: 15 };
139133
const rating = new Rating(voyage, emptyHistory);
@@ -248,12 +242,6 @@ describe('ExperiencedChinaRating', () => {
248242
expect(rating.voyageAndHistoryLengthFactor).toEqual(3);
249243
});
250244

251-
it('should add 1 point if history has more than 10 trips', () => {
252-
const history = createHistory({ length: 11, zone: 'china' });
253-
const rating = new ExperiencedChinaRating(chinaVoyage, history);
254-
expect(rating.voyageAndHistoryLengthFactor).toEqual(4);
255-
});
256-
257245
it('should add 1 point if voyage length is greater than 12', () => {
258246
const longChinaVoyage = { ...chinaVoyage, length: 13 };
259247
const history = Array.from({ length: 5 }, () => chinaVoyage);

0 commit comments

Comments
 (0)