-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathScoreCalculator.test.ts
More file actions
385 lines (296 loc) · 9.73 KB
/
ScoreCalculator.test.ts
File metadata and controls
385 lines (296 loc) · 9.73 KB
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
import { ScoreCalculator } from "./ScoreCalculator";
import { Player } from "../types/Player";
describe('ScoringCalculator', () => {
describe('Ones', () => {
const calculate = ScoreCalculator.calculators['ones'];
test('calculates no ones correctly', () => {
const dice = [2, 3, 4, 5, 6];
expect(calculate(dice)).toBe(0);
});
test('calculates two ones correctly', () => {
const dice = [1, 1, 4, 5, 6];
expect(calculate(dice)).toBe(2);
});
test('calculates all ones correctly', () => {
const dice = [1, 1, 1, 1, 1];
expect(calculate(dice)).toBe(5);
});
});
describe('Twos', () => {
const calculate = ScoreCalculator.calculators['twos'];
test('calculates no twos correctly', () => {
const dice = [1, 3, 4, 5, 6];
expect(calculate(dice)).toBe(0);
});
test('calculates two twos correctly', () => {
const dice = [2, 2, 4, 5, 6];
expect(calculate(dice)).toBe(4);
});
test('calculates all twos correctly', () => {
const dice = [2, 2, 2, 2, 2];
expect(calculate(dice)).toBe(10);
});
});
describe('Threes', () => {
const calculate = ScoreCalculator.calculators['threes'];
test('calculates no threes correctly', () => {
const dice = [1, 2, 4, 5, 6];
expect(calculate(dice)).toBe(0);
});
test('calculates two threes correctly', () => {
const dice = [3, 3, 4, 5, 6];
expect(calculate(dice)).toBe(6);
});
test('calculates all threes correctly', () => {
const dice = [3, 3, 3, 3, 3];
expect(calculate(dice)).toBe(15);
});
});
describe('Fours', () => {
const calculate = ScoreCalculator.calculators['fours'];
test('calculates no fours correctly', () => {
const dice = [1, 2, 3, 5, 6];
expect(calculate(dice)).toBe(0);
});
test('calculates two fours correctly', () => {
const dice = [3, 4, 4, 5, 6];
expect(calculate(dice)).toBe(8);
});
test('calculates all ones correctly', () => {
const dice = [4, 4, 4, 4, 4];
expect(calculate(dice)).toBe(20);
});
});
describe('Fives', () => {
const calculate = ScoreCalculator.calculators['fives'];
test('calculates no fives correctly', () => {
const dice = [1, 2, 3, 4, 6];
expect(calculate(dice)).toBe(0);
});
test('calculates two fives correctly', () => {
const dice = [1, 2, 3, 5, 5];
expect(calculate(dice)).toBe(10);
});
test('calculates all fives correctly', () => {
const dice = [5, 5, 5, 5, 5];
expect(calculate(dice)).toBe(25);
});
});
describe('Sixes', () => {
const calculate = ScoreCalculator.calculators['sixes'];
test('calculates no sixes correctly', () => {
const dice = [1, 2, 3, 4, 5];
expect(calculate(dice)).toBe(0);
});
test('calculates two sixes correctly', () => {
const dice = [3, 4, 5, 6, 6];
expect(calculate(dice)).toBe(12);
});
test('calculates all sixes correctly', () => {
const dice = [6, 6, 6, 6, 6];
expect(calculate(dice)).toBe(30);
});
});
describe('One Pair', () => {
const calculate = ScoreCalculator.calculators['onePair'];
test('calculates all different correctly', () => {
const dice = [1, 2, 3, 4, 5];
expect(calculate(dice)).toBe(0);
});
test('calculates one pair correctly', () => {
const dice = [1, 1, 2, 3, 4];
expect(calculate(dice)).toBe(2);
});
test('calculates two pair correctly', () => {
const dice = [1, 1, 2, 2, 3];
expect(calculate(dice)).toBe(4);
});
test('calculates yatzy correctly', () => {
const dice = [1, 1, 1, 1, 1];
expect(calculate(dice)).toBe(2);
});
});
describe('Two Pairs', () => {
const calculate = ScoreCalculator.calculators['twoPairs'];
test('calculates all different correctly', () => {
const dice = [1, 3, 4, 5, 6];
expect(calculate(dice)).toBe(0);
});
test('calculates two pairs correctly', () => {
const dice = [1, 1, 2, 2, 3];
expect(calculate(dice)).toBe(6);
});
test('calculates full house correctly', () => {
const dice = [1, 1, 1, 2, 2];
expect(calculate(dice)).toBe(6);
});
test('calculates four of a kind correctly', () => {
const dice = [1, 1, 1, 1, 2];
expect(calculate(dice)).toBe(0);
});
});
describe('Three of a Kind', () => {
const calculate = ScoreCalculator.calculators['threeOfAKind'];
test('calculates all different correctly', () => {
const dice = [1, 3, 4, 5, 6];
expect(calculate(dice)).toBe(0);
});
test('calculates three of a kind correctly', () => {
const dice = [1, 1, 1, 2, 2];
expect(calculate(dice)).toBe(3);
});
test('calculates four of a kind correctly', () => {
const dice = [1, 1, 1, 1, 2];
expect(calculate(dice)).toBe(3);
});
test('calculates yatzy correctly', () => {
const dice = [1, 1, 1, 1, 1];
expect(calculate(dice)).toBe(3);
});
});
describe('Four of a Kind', () => {
const calculate = ScoreCalculator.calculators['fourOfAKind'];
test('calculates all different correctly', () => {
const dice = [1, 3, 4, 5, 6];
expect(calculate(dice)).toBe(0);
});
test('calculates three of a kind correctly', () => {
const dice = [1, 1, 1, 2, 2];
expect(calculate(dice)).toBe(0);
});
test('calculates four of a kind correctly', () => {
const dice = [1, 1, 1, 1, 2];
expect(calculate(dice)).toBe(4);
});
test('calculates yatzy correctly', () => {
const dice = [1, 1, 1, 1, 1];
expect(calculate(dice)).toBe(4);
});
});
describe('Small Straight', () => {
const calculate = ScoreCalculator.calculators['smallStraight'];
test('calculates all different correctly', () => {
const dice = [1, 3, 4, 5, 6];
expect(calculate(dice)).toBe(0);
});
test('calculates large straight correctly', () => {
const dice = [2, 3, 4, 5, 6];
expect(calculate(dice)).toBe(0);
});
test('calculates small straight correctly', () => {
const dice = [1, 2, 3, 4, 5];
expect(calculate(dice)).toBe(15);
});
test('calculates large straight out of order correctly', () => {
const dice = [5, 3, 1, 4, 2];
expect(calculate(dice)).toBe(15);
});
});
describe('Large Straight', () => {
const calculate = ScoreCalculator.calculators['largeStraight'];
test('calculates all different correctly', () => {
const dice = [1, 3, 4, 5, 6];
expect(calculate(dice)).toBe(0);
});
test('calculates small straight correctly', () => {
const dice = [1, 2, 3, 4, 5];
expect(calculate(dice)).toBe(0);
});
test('calculates large straight correctly', () => {
const dice = [2, 3, 4, 5, 6];
expect(calculate(dice)).toBe(20);
});
test('calculates large straight out of order correctly', () => {
const dice = [6, 4, 2, 5, 3];
expect(calculate(dice)).toBe(20);
});
});
describe('Full House', () => {
const calculate = ScoreCalculator.calculators['fullHouse'];
test('calculates all different correctly', () => {
const dice = [1, 2, 3, 4, 5];
expect(calculate(dice)).toBe(0);
});
test('calculates four ones correctly', () => {
const dice = [1, 1, 1, 1, 2];
expect(calculate(dice)).toBe(0);
});
test('calculates all ones correctly', () => {
const dice = [1, 1, 1, 1, 1];
expect(calculate(dice)).toBe(0);
});
test('calculates ones full of twos correctly', () => {
const dice = [1, 1, 1, 2, 2];
expect(calculate(dice)).toBe(7);
});
test('calculates sixes full of fives correctly', () => {
const dice = [6, 5, 6, 5, 6];
expect(calculate(dice)).toBe(28);
});
});
describe('chance', () => {
const calculate = ScoreCalculator.calculators['chance'];
test('calculates all different correctly', () => {
const dice = [1, 2, 3, 4, 5];
expect(calculate(dice)).toBe(15);
});
test('calculates four ones correctly', () => {
const dice = [1, 1, 1, 1, 2];
expect(calculate(dice)).toBe(6);
});
test('calculates all sixes correctly', () => {
const dice = [6, 6, 6, 6, 6];
expect(calculate(dice)).toBe(30);
});
});
describe('yatzy', () => {
const calculate = ScoreCalculator.calculators['yatzy'];
test('calculates all different correctly', () => {
const dice = [1, 2, 3, 4, 5];
expect(calculate(dice)).toBe(0);
});
test('calculates four ones correctly', () => {
const dice = [1, 1, 1, 1, 2];
expect(calculate(dice)).toBe(0);
});
test('calculates all ones correctly', () => {
const dice = [1, 1, 1, 1, 1];
expect(calculate(dice)).toBe(50);
});
});
describe('calculates', () => {
const player: Player = {
id: "0",
name: "Player 1",
scoring: {
ones: 3,
twos: 6,
threes: 9,
fours: 12,
fives: 15,
sixes: 18,
onePair: 12,
twoPairs: 24,
threeOfAKind: 18,
fourOfAKind: 24,
smallStraight: 15,
largeStraight: 20,
fullHouse: 28,
chance: 30,
yatzy: 50,
}
};
test('calculates upper section total correctly', () => {
expect(ScoreCalculator.calculateUpperSectionTotal(player)).toBe(63);
});
test('calculates upper section bonus correctly', () => {
expect(ScoreCalculator.calculateUpperSectionBonus(player)).toBe(50);
});
test('calculates lower section total correctly', () => {
expect(ScoreCalculator.calculateLowerSectionTotal(player)).toBe(221);
});
test('calculates total correctly', () => {
expect(ScoreCalculator.calculateTotal(player)).toBe(334);
});
});
});