-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
313 lines (264 loc) · 10.6 KB
/
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
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
var fs = require('fs');
var expect = require('chai').expect;
var handParser = require('./parser').handParser;
var testHands = require('./testHands').testHands;
var createParsedHand = require('./parser').createParsedHand;
var checkRunTwice = require('./parser').checkRunTwice;
var prepareHandHistory = require('./parser').prepareHandHistory;
var getHandIdentifier = require('./parser').getHandIdentifier;
var getHandStyle = require('./parser').getHandStyle;
var Player = require('./parser').Player;
describe("Hand Parser", function() {
// var hand1 = handParser(testHands[0]);
// var hand2 = handParser(testHands[1]);
var hand3 = handParser(testHands[2]);
var hand4 = handParser(testHands[3]);
var hand5 = handParser(testHands[4]);
// omaha
var hand6 = handParser(testHands[5]);
var hand7 = handParser(testHands[6]);
var hand10 = handParser(testHands[9]);
console.log(hand10);
// run it twice
var hand8 = handParser(testHands[7]);
var hand9 = handParser(testHands[8]);
it("should learn where the hand came from" ,function(){
// expect(hand1.platforms === "PS").to.be.true;
expect(hand3.platforms === "PS").to.be.true;
expect(hand4.platforms === "PS").to.be.true;
expect(hand6.platforms === "PS").to.be.true;
});
it("should learn the game style" ,function(){
// expect(hand1.gameStyle).to.equal("Hold'em No Limit");
expect(hand3.gameStyle).to.equal("Hold'em No Limit");
expect(hand4.gameStyle).to.equal("Hold'em No Limit");
expect(hand5.gameStyle).to.equal("Hold'em No Limit");
expect(hand6.gameStyle).to.equal("Omaha Pot Limit");
expect(hand7.gameStyle).to.equal("Omaha Pot Limit");
});
it("should learn the game's language", function(){
// expect(hand1.language).to.equal("pt");
// expect(hand2.language).to.equal("pt");
expect(hand3.language).to.equal("en");
expect(hand4.language).to.equal("en");
expect(hand5.language).to.equal("en");
expect(hand6.language).to.equal("en");
});
it("should learn the ammount of players" ,function(){
// expect(hand1.players.length).to.equal(6);
// expect(hand2.players.length).to.equal(2);
expect(hand3.players.length).to.equal(4);
expect(hand4.players.length).to.equal(9);
expect(hand6.players.length).to.equal(6);
expect(hand7.players.length).to.equal(6);
});
it("should learn the ammount of chips players have" ,function(){
// expect(hand1.players[0][1]).to.equal(500);
// expect(hand2.players[0][1]).to.equal(1140);
expect(hand3.players[0].chips).to.equal('$574.70');
expect(hand4.players[0].chips).to.equal('3000');
expect(hand5.players[0].chips).to.equal('3370');
expect(hand6.players[5].chips).to.equal('$105.05');
expect(hand7.players[2].chips).to.equal('$200');
expect(hand8.players[2].chips).to.equal('$513.38');
});
it("should learn the ante", function(){
expect(hand9.ante).to.equal('40');
});
it("should learn players positions", function(){
expect(hand6.players[2].position).to.equal("BB");
expect(hand9.players[2].position).to.equal("UTG");
});
it("should learn the guy's hand if its available", function(){
expect(hand3.ownHand).to.eql(["Ad","Ts"]);
expect(hand5.ownHand).to.eql(["Ad","2d"]);
expect(hand6.ownHand).to.eql(["6h", "Ad", "4s", "5d"]);
expect(hand8.ownHand).to.eql([]);
});
it("should store the pre flop actions", function(){
expect(hand3.preFlopActions[0]).to.eql("sphinmx: posts small blind $2.50");
expect(hand3.preFlopActions[2]).to.eql("zerfer03: folds");
expect(hand4.preFlopActions[0]).to.eql("Llkee: posts small blind 10");
expect(hand4.preFlopActions[2]).to.eql("Hinrekas: folds ");
expect(hand5.preFlopActions[0]).to.eql("ruslanmd: posts small blind 10");
expect(hand5.preFlopActions[2]).to.eql("MaximSG: folds ");
expect(hand6.preFlopActions[0]).to.eql("10K-in-Clay: posts small blind $1");
expect(hand6.preFlopActions[2]).to.eql("Runchuks: folds ");
expect(hand7.preFlopActions[4]).to.eql("Roxie Hart: raises $4 to $6");
expect(hand8.preFlopActions[11]).to.eql("Flufferd: calls $410.21");
});
it("should learn the flop cards" ,function(){
// expect(hand1.flop).to.eql(["8c", "2d", "6s"]);
// expect(hand2.flop).to.eql(["Qs", "3c", "Kc"]);
expect(hand3.flop).to.eql(["Tc", "8d", "Td"]);
expect(hand4.flop).to.eql([]);
expect(hand5.flop).to.eql(["3h", "Th", "Jc"]);
expect(hand6.flop).to.eql([]);
expect(hand7.flop).to.eql(["2s", "5s", "4d"]);
expect(hand8.flop).to.eql(["3d", "2h", "7h"]);
});
it("should store the flop actions", function(){
expect(hand3.flopActions[0]).to.eql('sphinmx: checks');
expect(hand4.flopActions[0]).to.be.undefined;
expect(hand5.flopActions[1]).to.eql("konnh4nd: bets 68");
expect(hand7.flopActions[2]).to.eql("lipreTTT: raises $32.42 to $42.42");
expect(hand8.flopActions[2]).to.be.undefined;
});
it("should learn the turn card", function(){
// expect(hand1.turn).to.equal("");
// expect(hand2.turn).to.equal("Ac");
expect(hand3.turn).to.equal("Js");
expect(hand5.turn).to.equal("8d");
expect(hand7.turn).to.equal("Ks");
expect(hand8.turn).to.equal("6h");
});
it("should store the turn actions", function(){
expect(hand3.turnActions[0]).to.eql('sphinmx: bets $458.48 and is all-in');
expect(hand5.turnActions[0]).to.eql('jordanblg: checks ');
expect(hand7.turnActions[0]).to.be.undefined;
});
it("should learn the river card", function(){
// expect(hand1.river).to.eql("");
// expect(hand3.river).to.eql("Qs");
expect(hand5.river).to.eql("6d");
expect(hand7.river).to.eql("Ac");
expect(hand8.river).to.eql("9c");
});
it("should store the river actions", function(){
// expect(hand1.riverActions[0]).to.be.undefined;
expect(hand3.riverActions[0]).to.be.undefined;
expect(hand5.riverActions[0]).to.eql("jordanblg: bets 140");
expect(hand7.riverActions[0]).to.be.undefined;
expect(hand8.riverActions[0]).to.be.undefined;
});
it("should know if the hand was run twice", function(){
// expect(hand1.runTwice).to.be.false;
expect(hand4.runTwice).to.be.false;
expect(hand7.runTwice).to.be.false;
expect(hand8.runTwice).to.be.true;
});
it("should learn the second flop cards", function(){
// expect(hand1.secondFlop).to.be.undefined;
expect(hand8.secondFlop).to.eql(["6d", "Qs", "8d"]);
});
it("should learn the second turn cards", function(){
// expect(hand1.secondTurn).to.be.undefined;
expect(hand8.secondTurn).to.eql('9d');
});
it("should learn the second river cards", function(){
// expect(hand1.secondRiver).to.be.undefined;
expect(hand8.secondRiver).to.eql('2d');
});
it("should learn the pot", function(){
expect(hand8.pot).to.eql('Total pot $1037.81 | Rake $2.80.');
});
describe("Initial Configs", function(){
xit("should initialize config", function(){
// mock functions and test if they were invoked
});
it("should create parsedHand", function(){
var parsed = createParsedHand();
expect(createParsedHand).to.be.a('function');
expect(parsed).to.be.an('object');
expect(parsed).to.eql({
platforms: '',
gameStyle: '',
language: '',
turn: '',
river: '',
pot: '',
ante: '',
blinds: '',
flopPot: 0,
turnPot: 0,
riverPot: 0,
players: [],
ownHand: [],
preFlopActions: [],
table: [],
flop: [],
flopActions: [],
turnActions: [],
riverActions: [],
hero: {}
});
});
it("should prepare hand history", function(done){
expect(prepareHandHistory).to.be.a('function');
fs.readFile('./testHand.txt', function(err, doc){
if(err) return done(err);
expect(prepareHandHistory(doc.toString())).to.eql(prepareHandHistory(testHands[6]));
done();
});
});
describe("Player constructor", function(){
it("should be a function", function(){
expect(Player).to.be.a('function');
});
it("should return a Player Object with name and chip properties", function(){
var player = new Player("iago", 400);
expect(player).to.be.an('object');
expect(player).to.eql({
name: "iago",
chips: "400",
position: '',
hand: [],
invested: 0
});
});
});
describe("Run Twice Setup", function(){
it("should be function", function(){
expect(checkRunTwice).to.be.a('function');
});
it("should not config variables if the hand wasnt ran twice", function(){
var parsed = createParsedHand();
checkRunTwice(parsed, testHands[6]);
expect(parsed).to.have.ownProperty('runTwice');
expect(parsed.runTwice).to.be.false;
expect(parsed).to.not.have.ownProperty('secondFlop');
expect(parsed).to.not.have.ownProperty('secondTurn');
expect(parsed).to.not.have.ownProperty('secondRiver');
});
it("should config variables if the hand was ran twice", function(){
var parsed = createParsedHand();
checkRunTwice(parsed, testHands[7]);
expect(parsed).to.have.ownProperty('runTwice');
expect(parsed.runTwice).to.be.true;
expect(parsed).to.have.ownProperty('secondFlop');
expect(parsed.secondFlop).to.eql([]);
expect(parsed).to.have.ownProperty('secondTurn');
expect(parsed.secondTurn).to.eql('');
expect(parsed).to.have.ownProperty('secondRiver');
expect(parsed.secondRiver).to.eql('');
});
});
});
describe("Pre-Flop Parsing", function(){
it("should get hand identifier", function(){
expect(getHandIdentifier(prepareHandHistory(testHands[3]))).to.eql("PokerStars Hand #129546885146: Tournament #1118959248, $10+$1 USD Hold'em No Limit - Level I (10/20) - 2015/01/29 12:15:12 ET");
});
xit("should get hand style", function(){
expect();
});
});
describe("Street Pots", function(){
it("should get the pot value before the flop", function(){
expect(hand3.flopPot).to.eql(90);
expect(hand6.flopPot).to.eql(3);
expect(hand8.flopPot).to.eql(1037.81);
});
it("should get the pot value before the turn", function(){
expect(hand3.turnPot).to.eql(330)
expect(hand4.turnPot).to.eql(70);
expect(hand7.turnPot).to.eql(220);
});
it("should get the pot value before the river", function(){
// need to deal with uncalled bets to handle this one
// expect(hand3.riverPot).to.eql(1223.70);
expect(hand4.riverPot).to.eql(70);
expect(hand5.riverPot).to.eql(234);
expect(hand7.riverPot).to.eql(220);
});
});
});