Skip to content

Commit 3310680

Browse files
committed
introduce Scorer class
1 parent 038f96f commit 3310680

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

src/index.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,27 @@ export function score(candidate, medicalExam, scoringGuide) {
1919

2020
return result;
2121
}
22+
23+
export class Scorer {
24+
execute(candidate, medicalExam, scoringGuide) {
25+
let result = 0;
26+
let healthLevel = 0;
27+
let highMedicalRiskFlag = false;
28+
29+
if (medicalExam.isSmoker) {
30+
healthLevel += 10;
31+
highMedicalRiskFlag = true;
32+
}
33+
34+
let certificationGrade = 'regular';
35+
if (scoringGuide.stateWithLowCertification(candidate.originState)) {
36+
certificationGrade = 'low';
37+
result -= 5;
38+
}
39+
40+
// lots more code like this
41+
result -= Math.max(healthLevel - 5, 0);
42+
43+
return result;
44+
}
45+
}

src/index.test.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { score } from './index';
1+
import { score, Scorer } from './index';
22

33
describe('score', () => {
44
it('should return 0 if candidate is not a smoker and has a regular certification grade', () => {
@@ -33,3 +33,41 @@ describe('score', () => {
3333
expect(score(candidate, medicalExam, scoringGuide)).toBe(-10);
3434
});
3535
});
36+
37+
describe('Scorer', () => {
38+
it('should return 0 if candidate is not a smoker and has a regular certification grade', () => {
39+
const candidate = { originState: 'FL' };
40+
const medicalExam = { isSmoker: false };
41+
const scoringGuide = { stateWithLowCertification: () => false };
42+
43+
const scorer = new Scorer();
44+
expect(scorer.execute(candidate, medicalExam, scoringGuide)).toBe(0);
45+
});
46+
47+
it('should return -5 if candidate is not a smoker and has a low certification grade', () => {
48+
const candidate = { originState: 'FL' };
49+
const medicalExam = { isSmoker: false };
50+
const scoringGuide = { stateWithLowCertification: () => true };
51+
52+
const scorer = new Scorer();
53+
expect(scorer.execute(candidate, medicalExam, scoringGuide)).toBe(-5);
54+
});
55+
56+
it('should return -5 if candidate is a smoker and has a regular certification grade', () => {
57+
const candidate = { originState: 'FL' };
58+
const medicalExam = { isSmoker: true };
59+
const scoringGuide = { stateWithLowCertification: () => false };
60+
61+
const scorer = new Scorer();
62+
expect(scorer.execute(candidate, medicalExam, scoringGuide)).toBe(-5);
63+
});
64+
65+
it('should return -10 if candidate is a smoker and has a low certification grade', () => {
66+
const candidate = { originState: 'FL' };
67+
const medicalExam = { isSmoker: true };
68+
const scoringGuide = { stateWithLowCertification: () => true };
69+
70+
const scorer = new Scorer();
71+
expect(scorer.execute(candidate, medicalExam, scoringGuide)).toBe(-10);
72+
});
73+
});

0 commit comments

Comments
 (0)