forked from libeo-tech/take-home-test-inato
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pharmacy.test.js
218 lines (181 loc) · 6.23 KB
/
pharmacy.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
import { Drug, Pharmacy } from "./pharmacy";
/**
* Pharmacy Test
*/
describe("Pharmacy", () => {
it("check on drug property", () => {
expect(new Drug("test", 10, 5).name).toEqual("test");
expect(new Drug("Doliprane", 10, 5).name).toEqual("Doliprane");
expect(new Drug("Herbal Tea", 10, 5).name).toEqual("Herbal Tea");
expect(new Drug("Fervex", 10, 5).name).toEqual("Fervex");
expect(new Drug("Magic Pill", 10, 5).name).toEqual("Magic Pill");
expect(new Drug("Dafalgan", 10, 5).name).toEqual("Dafalgan");
expect(new Drug("test", 10, 5).benefit).toEqual(5);
expect(new Drug("test", 10, 5).expiresIn).toEqual(10);
})
it("should return an empty array", () => {
expect(new Pharmacy([]).drugs).toEqual([])
});
it("should return same number of elements (10 elements)", () => {
expect(new Pharmacy([
new Drug("test", 2, 3),
new Drug("test", 2, 3),
new Drug("test", 2, 3),
new Drug("test", 2, 3),
new Drug("test", 2, 3),
new Drug("test", 2, 3),
new Drug("test", 2, 3),
new Drug("test", 2, 3),
new Drug("test", 2, 3),
new Drug("test", 2, 3),
])
.updateBenefitValue()).toHaveLength(10);
})
it("should decrease in benefit and expiresIn", () => {
expect(new Pharmacy([new Drug("test", 2, 3)])
.updateBenefitValue())
.toEqual([new Drug("test", 1, 2)]);
});
it("benefit value should be between 0 and 50", () => {
expect(new Drug("test", 2, 53).benefit).toEqual(50);
expect(new Drug("test", 2, -20).benefit).toEqual(0);
})
});
/**
* Generic Drugs Test
*/
describe("Generic drugs", () => {
it("ExpiresIn should decrease", () => {
expect(new Pharmacy([new Drug('test', 10, 1)])
.updateBenefitValue())
.toEqual([new Drug('test', 9, 0)]);
})
it("Benefit should decrease by one unit", () => {
expect(new Pharmacy([new Drug('test', 10, 1)])
.updateBenefitValue())
.toEqual([new Drug('test', 9, 0)]);
})
it("should decrease twice as fast when expiration date has passed", () => {
expect(new Pharmacy([new Drug('Doliprane', -1, 2)])
.updateBenefitValue())
.toEqual([new Drug('Doliprane', -2, 0)]);
})
it("should never be lesser than 0 in benefit", () => {
expect(new Pharmacy([new Drug('test', 5, 0)])
.updateBenefitValue())
.toEqual([new Drug('test', 4, 0)]);
})
})
/**
* Herbal Tea Test
*/
describe("Herbal Tea", () => {
it("ExpiresIn should decrease", () => {
expect(new Pharmacy([new Drug('Herbal Tea', 10, 1)])
.updateBenefitValue())
.not
.toEqual([new Drug('test', 10, 2)]);
})
it("should increase in benefit the older it gets", () => {
expect(new Pharmacy([new Drug('Herbal Tea', 10, 9)])
.updateBenefitValue())
.toEqual([new Drug('Herbal Tea', 9, 10)]);
})
it("should increase in benefit by two unit after expiration date", () => {
expect(new Pharmacy([new Drug('Herbal Tea', -1, 10)])
.updateBenefitValue())
.toEqual([new Drug('Herbal Tea', -2, 12)]);
})
it("should not be greater than 50 in benefit", () => {
expect(new Pharmacy([new Drug('Herbal Tea', 10, 50)])
.updateBenefitValue())
.toEqual([new Drug('Herbal Tea', 9, 50)]);
expect(new Pharmacy([new Drug('Herbal Tea', -9, 49)])
.updateBenefitValue())
.toEqual([new Drug('Herbal Tea', -10, 50)]);
})
})
/**
* Fervex Test
*/
describe("Fervex", () => {
it("ExpiresIn should decrease", () => {
expect(new Pharmacy([new Drug('Fervex', 20, 1)])
.updateBenefitValue())
.not
.toEqual([new Drug('Fervex', 20, 2)]);
})
it("should increase in benefit the older it gets", () => {
expect(new Pharmacy([new Drug('Fervex', 20, 9)])
.updateBenefitValue())
.toEqual([new Drug('Fervex', 19, 10)]);
})
it("should increase by one unit before 10 days expiration date", () => {
expect(new Pharmacy([new Drug('Fervex', 15, 9)])
.updateBenefitValue())
.toEqual([new Drug('Fervex', 14, 10)]);
})
it("should increase by two unit after 10 days expiration date", () => {
expect(new Pharmacy([new Drug('Fervex', 10, 10)])
.updateBenefitValue())
.toEqual([new Drug('Fervex', 9, 12)]);
expect(new Pharmacy([new Drug('Fervex', 6, 8)])
.updateBenefitValue())
.toEqual([new Drug('Fervex', 5, 10)]);
})
it("should increase by three unit after 5 days expiration date", () => {
expect(new Pharmacy([new Drug('Fervex', 5, 10)])
.updateBenefitValue())
.toEqual([new Drug('Fervex', 4, 13)]);
expect(new Pharmacy([new Drug('Fervex', 2, 5)])
.updateBenefitValue())
.toEqual([new Drug('Fervex', 1, 8)]);
})
it("should drop to 0 after expiration date", () => {
expect(new Pharmacy([new Drug('Fervex', 0, 10)])
.updateBenefitValue())
.toEqual([new Drug('Fervex', -1, 0)]);
expect(new Pharmacy([new Drug('Fervex', -4, 0)])
.updateBenefitValue())
.toEqual([new Drug('Fervex', -5, 0)]);
})
})
/**
* Magic Pill Test
*/
describe("Magic Pill", () => {
it("should not increase or decrease expiresIn", () => {
expect(new Pharmacy([new Drug('Magic Pill', 20, 40)])
.updateBenefitValue())
.toEqual([new Drug('Magic Pill', 20, 40)]);
})
it("should not increase or decrease in benefit", () => {
expect(new Pharmacy([new Drug('Magic Pill', 20, 10)])
.updateBenefitValue())
.toEqual([new Drug('Magic Pill', 20, 10)]);
})
})
/**
* Dafalgan Test
*/
describe("Dafalgan", () => {
it("ExpiresIn should decrease", () => {
expect(new Pharmacy([new Drug('Dafalgan', 10, 5)])
.updateBenefitValue())
.not
.toEqual([new Drug('Dafalgan', 10, 3)]);
})
it ("should not be lesser than 0", () => {
expect(new Pharmacy([new Drug('Dafalgan', 0, 1)])
.updateBenefitValue())
.toEqual([new Drug('Dafalgan', -1, 0)]);
expect(new Pharmacy([new Drug('Dafalgan', 2, 0)])
.updateBenefitValue())
.toEqual([new Drug('Dafalgan', 1, 0)]);
})
it("should decrease benefit by two unit", () => {
expect(new Pharmacy([new Drug('Dafalgan', 20, 10)])
.updateBenefitValue())
.toEqual([new Drug('Dafalgan', 19, 8)]);
})
})