Skip to content

Commit 2916bad

Browse files
committed
✅: Add unit tests for all drugs behaviours
These unit test will ensure system still works after refactoring.
1 parent 26e8f98 commit 2916bad

File tree

1 file changed

+81
-4
lines changed

1 file changed

+81
-4
lines changed

src/model/pharmacy/pharmacy.test.ts

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,86 @@ import { Drug } from '../drug/drug';
22
import { Pharmacy } from './pharmacy';
33

44
describe('Pharmacy', () => {
5-
it('should decrease the benefit and expiresIn', () => {
6-
expect(new Pharmacy([new Drug('test', 2, 3)]).updateBenefitValue()).toEqual(
7-
[new Drug('test', 1, 2)]
8-
);
5+
describe('drug', () => {
6+
it('should decrease the benefit and expiresIn', () => {
7+
expect(
8+
new Pharmacy([new Drug('test', 2, 3)]).updateBenefitValue()
9+
).toEqual([new Drug('test', 1, 2)]);
10+
});
11+
12+
it('should decrease twice as fast if expired', () => {
13+
expect(
14+
new Pharmacy([new Drug('test', -2, 3)]).updateBenefitValue()
15+
).toEqual([new Drug('test', -3, 1)]);
16+
});
17+
18+
it('should not decrease benefit under 0', () => {
19+
expect(
20+
new Pharmacy([new Drug('test', -2, 1)]).updateBenefitValue()
21+
).toEqual([new Drug('test', -3, 0)]);
22+
expect(
23+
new Pharmacy([new Drug('test', -2, 0)]).updateBenefitValue()
24+
).toEqual([new Drug('test', -3, 0)]);
25+
});
26+
});
27+
28+
describe('Fervex', () => {
29+
it('should increase benefit with time', () => {
30+
expect(
31+
new Pharmacy([new Drug('Fervex', 30, 1)]).updateBenefitValue()
32+
).toEqual([new Drug('Fervex', 29, 2)]);
33+
});
34+
35+
test('benefit + 2 if 10 >= expiresIn > 5', () => {
36+
expect(
37+
new Pharmacy([new Drug('Fervex', 10, 1)]).updateBenefitValue()
38+
).toEqual([new Drug('Fervex', 9, 3)]);
39+
expect(
40+
new Pharmacy([new Drug('Fervex', 6, 1)]).updateBenefitValue()
41+
).toEqual([new Drug('Fervex', 5, 3)]);
42+
});
43+
44+
test('benefit + 3 if 5 >= expiresIn > 0', () => {
45+
expect(
46+
new Pharmacy([new Drug('Fervex', 5, 1)]).updateBenefitValue()
47+
).toEqual([new Drug('Fervex', 4, 4)]);
48+
expect(
49+
new Pharmacy([new Drug('Fervex', 1, 1)]).updateBenefitValue()
50+
).toEqual([new Drug('Fervex', 0, 4)]);
51+
});
52+
53+
test('benefit drops to 0 if 0 >= expiresIn > -∞', () => {
54+
expect(
55+
new Pharmacy([new Drug('Fervex', 0, 1)]).updateBenefitValue()
56+
).toEqual([new Drug('Fervex', -1, 0)]);
57+
});
58+
});
59+
60+
describe('Herbal Tea', () => {
61+
it('should increase benefit with time', () => {
62+
expect(
63+
new Pharmacy([new Drug('Herbal Tea', 30, 1)]).updateBenefitValue()
64+
).toEqual([new Drug('Herbal Tea', 29, 2)]);
65+
});
66+
67+
it('should increase benefit twice as much if expired', () => {
68+
expect(
69+
new Pharmacy([new Drug('Herbal Tea', 0, 1)]).updateBenefitValue()
70+
).toEqual([new Drug('Herbal Tea', -1, 3)]);
71+
});
72+
});
73+
74+
describe('Magic Pill', () => {
75+
it('should not change expiration or benefit with time', () => {
76+
expect(
77+
new Pharmacy([new Drug('Magic Pill', 30, 1)]).updateBenefitValue()
78+
).toEqual([new Drug('Magic Pill', 30, 1)]);
79+
expect(
80+
new Pharmacy([new Drug('Magic Pill', 0, 1)]).updateBenefitValue()
81+
).toEqual([new Drug('Magic Pill', 0, 1)]);
82+
expect(
83+
new Pharmacy([new Drug('Magic Pill', -30, 1)]).updateBenefitValue()
84+
).toEqual([new Drug('Magic Pill', -30, 1)]);
85+
});
986
});
1087
});

0 commit comments

Comments
 (0)