Skip to content

Commit 091533c

Browse files
committed
move medicalExam to Score's constructor
1 parent f8408b4 commit 091533c

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
export function score(candidate, medicalExam, scoringGuide) {
2-
return new Scorer(candidate).execute(medicalExam, scoringGuide);
2+
return new Scorer(candidate, medicalExam).execute(scoringGuide);
33
}
44

55
export class Scorer {
6-
constructor(candidate) {
6+
constructor(candidate, medicalExam) {
77
this._candidate = candidate;
8+
this._medicalExam = medicalExam;
89
}
910

10-
execute(medicalExam, scoringGuide) {
11+
execute(scoringGuide) {
1112
let result = 0;
1213
let healthLevel = 0;
1314
let highMedicalRiskFlag = false;
1415

15-
if (medicalExam.isSmoker) {
16+
if (this._medicalExam.isSmoker) {
1617
healthLevel += 10;
1718
highMedicalRiskFlag = true;
1819
}

src/index.test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,34 +40,34 @@ describe('Scorer', () => {
4040
const medicalExam = { isSmoker: false };
4141
const scoringGuide = { stateWithLowCertification: () => false };
4242

43-
const scorer = new Scorer(candidate);
44-
expect(scorer.execute(medicalExam, scoringGuide)).toBe(0);
43+
const scorer = new Scorer(candidate, medicalExam);
44+
expect(scorer.execute(scoringGuide)).toBe(0);
4545
});
4646

4747
it('should return -5 if candidate is not a smoker and has a low certification grade', () => {
4848
const candidate = { originState: 'FL' };
4949
const medicalExam = { isSmoker: false };
5050
const scoringGuide = { stateWithLowCertification: () => true };
5151

52-
const scorer = new Scorer(candidate);
53-
expect(scorer.execute(medicalExam, scoringGuide)).toBe(-5);
52+
const scorer = new Scorer(candidate, medicalExam);
53+
expect(scorer.execute(scoringGuide)).toBe(-5);
5454
});
5555

5656
it('should return -5 if candidate is a smoker and has a regular certification grade', () => {
5757
const candidate = { originState: 'FL' };
5858
const medicalExam = { isSmoker: true };
5959
const scoringGuide = { stateWithLowCertification: () => false };
6060

61-
const scorer = new Scorer(candidate);
62-
expect(scorer.execute(medicalExam, scoringGuide)).toBe(-5);
61+
const scorer = new Scorer(candidate, medicalExam);
62+
expect(scorer.execute(scoringGuide)).toBe(-5);
6363
});
6464

6565
it('should return -10 if candidate is a smoker and has a low certification grade', () => {
6666
const candidate = { originState: 'FL' };
6767
const medicalExam = { isSmoker: true };
6868
const scoringGuide = { stateWithLowCertification: () => true };
6969

70-
const scorer = new Scorer(candidate);
71-
expect(scorer.execute(medicalExam, scoringGuide)).toBe(-10);
70+
const scorer = new Scorer(candidate, medicalExam);
71+
expect(scorer.execute(scoringGuide)).toBe(-10);
7272
});
7373
});

0 commit comments

Comments
 (0)