-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
195 lines (157 loc) · 5.01 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
const test = require('tape')
const Player = require('./Player')
const gameStateFixture = require('./test/game-state.json')
const gameStateFixture2 = require('./test/game-state-2.json')
const gameStateFixture3 = require('./test/game-state-3.json')
const gameStateFixture4 = require('./test/game-state-4.json')
const gameStateFixture5 = require('./test/game-state-5.json')
const gameStateFixture6 = require('./test/game-state-6.json')
const cards2Table = require('./cards-2-table')
const myStack = require('./my-stack')
const effectiveStack = require('./effective-stack')
const headsUp = require('./heads-up')
// test.skip('correct card value',
// function (t) {
// t.equal(playerJs.toNum('J'), 11)
// t.end()
// }
// )
test('should work1', function (t) {
Player.betRequest(gameStateFixture, function (bet) {
// console.log(bet)
t.equals(bet, 0)
t.end()
})
})
test('should work2', function (t) {
Player.betRequest(gameStateFixture2, function (bet) {
t.equals(bet, 0)
t.end()
})
})
test('should work3', function (t) {
Player.betRequest(gameStateFixture3, function (bet) {
t.equals(bet, 10000)
t.end()
})
})
test('should work4', function (t) {
const myGameState = JSON.parse(JSON.stringify(gameStateFixture3))
myGameState.pot = 150
Player.betRequest(myGameState, function (bet) {
t.equals(bet, 10000)
t.end()
})
})
test('should work5', function (t) {
Player.betRequest(gameStateFixture5, function (bet) {
t.equals(bet, 0)
t.end()
})
})
test('should work6', function (t) {
const myGameState = JSON.parse(JSON.stringify(gameStateFixture5))
myGameState.players[myGameState.in_action].stack = 20
Player.betRequest(myGameState, function (bet) {
t.equals(bet, 20)
t.end()
})
})
test('should work7', function (t) {
const myGameState = JSON.parse(JSON.stringify(gameStateFixture3))
myGameState.pot = 150
Player.betRequest(myGameState, function (bet) {
t.equals(bet, 10000)
t.end()
})
})
test('should work8', function (t) {
const myGameState = JSON.parse(JSON.stringify(gameStateFixture6))
// myGameState.pot = 150
Player.betRequest(myGameState, function (bet) {
t.equals(bet, 900)
t.end()
})
})
test('cards 2 table convert should work', (t) => {
let cards = [{rank: '4', suit: 'spades'}, {rank: '5', suit: 'spades'}]
t.equal(cards2Table.convert(cards), '54s')
cards = [{rank: '4', suit: 'spades'}, {rank: '4', suit: 'spades'}]
t.equal(cards2Table.convert(cards), '44')
cards = [{rank: '4', suit: 'spades'}, {rank: '5', suit: 'hearts'}]
t.equal(cards2Table.convert(cards), '54o')
cards = [{rank: '10', suit: 'spades'}, {rank: '4', suit: 'hearts'}]
t.equal(cards2Table.convert(cards), 'T4o')
t.end()
})
test('cards 2 table percentage should work', (t) => {
let cards = [{rank: 'A', suit: 'spades'}, {rank: 'A', suit: 'spades'}]
t.equal(cards2Table.getPercentage(cards), 0.5)
cards = [{rank: 'J', suit: 'spades'}, {rank: 'K', suit: 'spades'}]
t.equal(cards2Table.getPercentage(cards), 12.2)
cards = [{rank: 'A', suit: 'spades'}, {rank: 'Q', suit: 'clubs'}]
t.equal(cards2Table.getPercentage(cards), 4.7)
cards = [{rank: 'J', suit: 'spades'}, {rank: 'J', suit: 'clubs'}]
t.equal(cards2Table.getPercentage(cards), 3)
cards = [{rank: '8', suit: 'spades'}, {rank: '5', suit: 'clubs'}]
t.equal(cards2Table.getPercentage(cards), 78.3)
t.end()
})
test('my stack', (t) => {
const resp = myStack.calculate(gameStateFixture)
t.equal(resp, 79.5)
// console.log(resp)
t.end()
})
test('eff stack 1', (t) => {
const resp = effectiveStack.calculate(gameStateFixture)
// console.log(resp)
t.equal(resp, (1010 + 320) / 20)
t.end()
})
test('eff stack 2', (t) => {
const resp = effectiveStack.calculate(gameStateFixture4)
t.equal(resp, 43.5)
t.end()
})
test('heads up should be false', (t) => {
const isHeadsUp = headsUp.calculate(gameStateFixture4)
t.equal(isHeadsUp, false)
t.end()
})
test('heads up should be true', (t) => {
const isHeadsUp = headsUp.calculate(gameStateFixture)
t.equal(isHeadsUp, true)
t.end()
})
// test('strategy table', (t) => {
// let query = {effStack: 50, playersBehind: 2, folded: true}
// t.equal(strategyTable.query(query, strategyTableFixture), 13)
// t.end()
// })
// test('poshelper poshelper', (t) => {
// let pos = posHelper.posHelper(4, 2, 5)
// t.eq(pos, {pos: 4, after: 1})
// pos = posHelper.posHelper(2, 4, 5)
// t.eq(pos, {pos: 3, after: 2})
// t.end()
// })
// test('poshelper getPosition', (t) => {
// let pos = posHelper.posHelper(4, 2, 5)
// t.eq(pos, {pos: 4, after: 1})
// pos = posHelper.posHelper(2, 4, 5)
// t.eq(pos, {pos: 3, after: 2})
// pos = posHelper.posHelper(2, 4, 4)
// t.eq(pos, {pos: 3, after: 2})
// pos = posHelper.posHelper(1, 2, 3)
// t.eq(pos, {pos: 3, after: 2})
// pos = posHelper.posHelper(2, 1, 3)
// t.eq(pos, {pos: 3, after: 2})
// t.end()
// })
// test('bet request should work', (t) => {
// const spy = sinon.spy()
// Player.betRequest(gameState, spy)
// t.equal(spy.calledOnce, true)
// t.end()
// })