-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
262 lines (203 loc) · 7.39 KB
/
Copy pathtest.js
File metadata and controls
262 lines (203 loc) · 7.39 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
import Hand from './handsolver.js';
describe('A 5 card high card hand', () => {
const hand = new Hand(['As', '2c', '3c', '5s', '9h']);
const cards = hand.cards.map((c) => {
return c.toString();
})
it('is properly sorted', () => {
expect(cards).toEqual(['As', '9h', '5s', '3c', '2c']);
});
it('is properly ranked', () => {
expect(hand.name).toBe("High Card");
expect(hand.description).toBe("A High");
});
});
describe('A 7 card high card hand', () => {
const hand = new Hand(['9h', '3c', '7h', '2s', 'js', 'kd', 'As']);
const cards = hand.cards.map((c) => {
return c.toString();
});
it('is properly sorted', () => {
expect(cards).toEqual(['As', 'Kd', 'Js', '9h', '7h', '3c', '2s']);
});
it('is properly ranked', () => {
expect(hand.name).toBe("High Card");
expect(hand.description).toBe("A High");
});
it('has the correct best 5 cards', () => {
const best = hand.best.map((c) => {
return c.toString();
});
expect(best).toEqual(['As', 'Kd', 'Js', '9h', '7h']);
});
});
describe("An 8 card hand with one pair", () => {
const hand = new Hand(['Ah', 'As', '2c', '3c', '6d', '8h', 'Ks', 'Jd']);
const cards = hand.cards.map((c) => {
return c.toString();
});
it("is properly sorted", () => {
expect(cards).toEqual(['As', 'Ah', 'Ks', 'Jd', '8h', '6d', '3c', '2c']);
});
it("is properly ranked", () => {
expect(hand.name).toBe("One Pair");
expect(hand.description).toBe("One Pair - As");
});
it("has the correct best 5 cards", () => {
const best = hand.best.map(c => {
return c.toString();
})
expect(best).toEqual(['As', 'Ah', 'Ks', 'Jd', '8h']);
});
});
describe("An 8 card hand with a low-ranked pair", () => {
const hand = new Hand(['2c', '2d', '3s', '5h', '9h', 'js', 'kh', 'Td']);
const cards = hand.cards.map((c) => {
return c.toString();
});
it("is properly sorted", () => {
expect(cards).toEqual(['Kh', 'Js', 'Td', '9h', '5h', '3s', '2d', '2c']);
});
it("is properly ranked", () => {
expect(hand.name).toBe("One Pair");
expect(hand.description).toBe("One Pair - 2s");
});
it("has the correct best 5 cards", () => {
const best = hand.best.map(c => {
return c.toString();
})
expect(best).toEqual(['2d', '2c', 'Kh', 'Js', 'Td']);
});
})
describe('A 7 card 3 pair hand', () => {
const hand = new Hand(['As', '2c', 'Ah', '2d', '7h', '8d', '8s'])
it('is properly ranked as 2 pair', () => {
expect(hand.name).toBe("Two Pair");
expect(hand.description).toBe("Two Pair - As and 8s");
});
it('has the correct best 5 cards', () => {
const best = hand.best.map(c => {
return c.toString();
});
expect(best).toEqual(['As', 'Ah', '8s', '8d', '7h']);
});
});
describe('A hand with trips', () => {
const hand = new Hand(['As', '3s', '6c', 'Kd', '6d', 'Jh', '6s']);
it('is properly ranked as Three of a Kind', () => {
expect(hand.name).toBe("Three of a Kind");
expect(hand.description).toBe("Three of a Kind - 6s");
});
it('has the correct best 5 cards', () => {
const best = hand.best.map(c => {
return c.toString();
});
expect(best).toEqual(['6s', '6d', '6c', 'As', 'Kd']);
})
})
describe('A hand with a straight', () => {
const hand = new Hand(['Qs', '8h', '9d', 'Tc', 'As', '4c', 'Js']);
it('is properly ranked as a Straight', () => {
expect(hand.name).toBe("Straight");
expect(hand.description).toBe("Q High Straight");
});
it('has the correct best 5 cards', () => {
const best = hand.best.map(c => {
return c.toString();
});
expect(best).toEqual(['Qs', 'Js', 'Tc', '9d', '8h']);
});
});
describe("A hand with a wheel", () => {
const hand = new Hand(['As', '2c', '3c', '4d', '5h', '9s', 'Ks']);
it('is properly ranked as a Straight', () => {
expect(hand.name).toBe("Straight");
expect(hand.description).toBe('5 High Straight');
});
it('has the correct best 5 cards', () => {
const best = hand.best.map(c => {
return c.toString();
});
expect(best).toEqual(['5h', '4d', '3c', '2c', 'As']);
});
});
describe("A flush", () => {
const hand = new Hand(['3s', '9s', '4s', '3d', 'ks', 'js', 'ts']);
it('is properly ranked as a flush', () => {
expect(hand.name).toBe('Flush');
expect(hand.description).toBe('K High Flush');
});
it('has the correct best 5 cards', () => {
const best = hand.best.map(c => {
return c.toString();
});
expect(best).toEqual(['Ks', 'Js', 'Ts', '9s', '4s']);
});
});
describe("A full house", () => {
const hand = new Hand(['3s', '3c', '3d', 'as', 'ac', 'ad', '5s']);
it('is properly ranked as a full house', () => {
expect(hand.name).toBe('Full House');
expect(hand.description).toBe('As Full of 3s');
});
it('has the correct best 5 cards', () => {
const best = hand.best.map(c => {
return c.toString();
});
expect(best).toEqual(['As', 'Ad', 'Ac', '3s', '3d' ]);
});
})
describe('A hand with 4 of a kind', () => {
const hand = new Hand(['ts', 'tc', 'td', 'th', 'as', 'js', 'qs', 'kd']);
it('is properly ranked as four of a kind', () => {
expect(hand.name).toBe('Four of a Kind');
expect(hand.description).toBe('Four of a Kind - Ts');
});
it('has the correct best 5 cards', () => {
const best = hand.best.map(c => {
return c.toString();
});
expect(best).toEqual(['Ts', 'Th', 'Td', 'Tc', 'As']);
})
});
describe("A straight flush", () => {
const hand = new Hand(['9s', 'ts', 'js', '4s', '3c', '2c', '8s', 'qs']);
it('is properly ranked as straight flush', () => {
expect(hand.name).toBe("Straight Flush");
expect(hand.description).toBe('Q High Straight Flush');
})
it('has the correct best 5 cards', () => {
const best = hand.best.map(c => {
return c.toString();
});
expect(best).toEqual(['Qs', 'Js', 'Ts', '9s', '8s']);
})
});
describe("The Steel Wheel", () => {
const hand = new Hand(['5c', '3c', 'Ac', '9s', 'ts', 'td', '4c', '2c']);
it('is properly ranked as straight flush', () => {
expect(hand.name).toBe("Straight Flush");
expect(hand.description).toBe('5 High Straight Flush');
});
it('has the correct best 5 cards', () => {
const best = hand.best.map(c => {
return c.toString();
});
expect(best).toEqual(['5c', '4c', '3c', '2c', 'Ac']);
});
});
test('Compare a straight flush vs a full house', () => {
const a = new Hand(['6c', '5c', '4c', '3c', '2c']);
const b = new Hand(['as', 'ad', 'ac', '5h', '5d']);
expect(Hand.compare(a, b)).toBe(1);
});
test('Compare a 6 high straight flush vs the steel wheel', () => {
const a = new Hand(['6c', '5c', '4c', '3c', '2c']);
const b = new Hand(['5c', '4c', '3c', '2c', 'ac']);
expect(Hand.compare(a, b)).toBe(1);
});
test('Compare two same rank boats', () => {
const a = new Hand(['ac', 'ad', 'as', 'ks', 'kd']);
const b = new Hand(['ac', 'ad', 'ah', 'ks', 'kd']);
expect(Hand.compare(a, b)).toBe(0);
});