Skip to content

Commit 095c48a

Browse files
committed
✨: Add Dafalgan implementation
1 parent 26d004e commit 095c48a

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Dafalgan should be serializable to JSON 1`] = `
4+
Object {
5+
"benefit": 5,
6+
"expiresIn": 30,
7+
"name": "Dafalgan",
8+
}
9+
`;
10+
11+
exports[`Dafalgan should be serializable to string 1`] = `"{\\"name\\":\\"Dafalgan\\",\\"expiresIn\\":30,\\"benefit\\":5}"`;
12+
13+
exports[`Dafalgan should decrease benefit twice as much if expired 1`] = `
14+
Object {
15+
"benefit": 1,
16+
"expiresIn": -1,
17+
"name": "Dafalgan",
18+
}
19+
`;
20+
21+
exports[`Dafalgan should decrease expiresIn and benefit over time 1`] = `
22+
Object {
23+
"benefit": 3,
24+
"expiresIn": 29,
25+
"name": "Dafalgan",
26+
}
27+
`;
28+
29+
exports[`Dafalgan should not allow for a benefit greater than 50 1`] = `
30+
Object {
31+
"benefit": 50,
32+
"expiresIn": 30,
33+
"name": "Dafalgan",
34+
}
35+
`;
36+
37+
exports[`Dafalgan should not allow for a negative benefit 1`] = `
38+
Object {
39+
"benefit": 0,
40+
"expiresIn": 30,
41+
"name": "Dafalgan",
42+
}
43+
`;

src/model/drug/dafalgan.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { Dafalgan } from './dafalgan';
2+
3+
describe('Dafalgan', () => {
4+
let dafalgan: Dafalgan;
5+
6+
beforeEach(() => {
7+
dafalgan = new Dafalgan(30, 5);
8+
});
9+
10+
it('should not allow for a negative benefit', () => {
11+
dafalgan.benefit = -5;
12+
expect(dafalgan).toMatchSnapshot();
13+
});
14+
15+
it('should not allow for a benefit greater than 50', () => {
16+
dafalgan.benefit = 51;
17+
expect(dafalgan).toMatchSnapshot();
18+
});
19+
20+
it('should return expiration status', () => {
21+
expect(dafalgan.isExpired()).toBe(false);
22+
dafalgan.expiresIn = 0;
23+
expect(dafalgan.isExpired()).toBe(true);
24+
});
25+
26+
it('should decrease expiresIn and benefit over time', () => {
27+
dafalgan.updateValues();
28+
expect(dafalgan).toMatchSnapshot();
29+
});
30+
31+
it('should decrease benefit twice as much if expired', () => {
32+
dafalgan.expiresIn = 0;
33+
dafalgan.updateValues();
34+
expect(dafalgan).toMatchSnapshot();
35+
});
36+
37+
it('should be serializable to JSON', () => {
38+
expect(dafalgan.toJSON()).toMatchSnapshot();
39+
});
40+
41+
it('should be serializable to string', () => {
42+
expect(dafalgan.toString()).toMatchSnapshot();
43+
});
44+
});

src/model/drug/dafalgan.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { DrugName } from '../../type/DrugName';
2+
import { Drug } from './drug';
3+
4+
export class Dafalgan extends Drug {
5+
constructor(expiresIn: number, benefit: number) {
6+
super(DrugName.DAFALGAN, expiresIn, benefit);
7+
}
8+
9+
public updateValues(): this {
10+
this.benefit -= this.isExpired() ? 4 : 2;
11+
this.expiresIn -= 1;
12+
13+
return this;
14+
}
15+
}

src/type/DrugName.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export enum DrugName {
2+
DAFALGAN = 'Dafalgan',
23
DOLIPRANE = 'Doliprane',
34
HERBAL_TEA = 'Herbal Tea',
45
FERVEX = 'Fervex',

0 commit comments

Comments
 (0)