@@ -3,6 +3,7 @@ import { expect } from "chai";
3
3
import { Player } from "src/state/TeamState" ;
4
4
import { GameState } from "src/state/GameState" ;
5
5
import { PacketState , Tossup , Bonus } from "src/state/PacketState" ;
6
+ import { Cycle } from "src/state/Cycle" ;
6
7
7
8
const firstTeamPlayer : Player = new Player ( "Alice" , "A" , /* isStarter */ true ) ;
8
9
const secondTeamPlayer : Player = new Player ( "Bob" , "B" , /* isStarter */ true ) ;
@@ -62,6 +63,7 @@ describe("GameStateTests", () => {
62
63
} ) ;
63
64
it ( "Uneven game, protests don't matter" , ( ) => {
64
65
const game : GameState = createDefaultGame ( ) ;
66
+ // 20-0
65
67
game . cycles [ 0 ] . addCorrectBuzz (
66
68
{ player : firstTeamPlayer , points : 10 , position : 2 , isLastWord : false } ,
67
69
0 ,
@@ -71,6 +73,7 @@ describe("GameStateTests", () => {
71
73
) ;
72
74
game . cycles [ 0 ] . setBonusPartAnswer ( 0 , firstTeamPlayer . teamName , 10 ) ;
73
75
76
+ // 60-0
74
77
game . cycles [ 1 ] . addCorrectBuzz (
75
78
{ player : firstTeamPlayer , points : 10 , position : 1 , isLastWord : false } ,
76
79
0 ,
@@ -79,8 +82,10 @@ describe("GameStateTests", () => {
79
82
1
80
83
) ;
81
84
game . cycles [ 1 ] . setBonusPartAnswer ( 0 , firstTeamPlayer . teamName , 10 ) ;
85
+ game . cycles [ 1 ] . setBonusPartAnswer ( 1 , firstTeamPlayer . teamName , 10 ) ;
86
+ game . cycles [ 1 ] . setBonusPartAnswer ( 2 , firstTeamPlayer . teamName , 10 ) ;
82
87
83
- // 40 -0, so 15 points here and 10 points shouldn't make up for 40-10
88
+ // 60 -0, so 10 + 30 points here and 10 points shouldn't make up for 60-0
84
89
game . cycles [ 2 ] . addWrongBuzz (
85
90
{ player : secondTeamPlayer , points : - 5 , position : 1 , isLastWord : false } ,
86
91
2 ,
@@ -180,6 +185,8 @@ describe("GameStateTests", () => {
180
185
} ) ;
181
186
it ( "Uneven game, bonus protest matters (against)" , ( ) => {
182
187
const game : GameState = createDefaultGame ( ) ;
188
+
189
+ // 20-0, one protest
183
190
game . cycles [ 0 ] . addCorrectBuzz (
184
191
{ player : firstTeamPlayer , points : 10 , position : 2 , isLastWord : false } ,
185
192
0 ,
@@ -190,6 +197,7 @@ describe("GameStateTests", () => {
190
197
game . cycles [ 0 ] . setBonusPartAnswer ( 0 , firstTeamPlayer . teamName , 10 ) ;
191
198
game . cycles [ 0 ] . addBonusProtest ( 0 , 0 , "My answer" , "My reason" , secondTeamPlayer . teamName ) ;
192
199
200
+ // 20-10, one bonus protest (should tie since protest against correctness)
193
201
game . cycles [ 1 ] . addCorrectBuzz (
194
202
{ player : secondTeamPlayer , points : 10 , position : 1 , isLastWord : false } ,
195
203
0 ,
@@ -220,6 +228,79 @@ describe("GameStateTests", () => {
220
228
game . cycles [ 3 ] . addTossupProtest ( secondTeamPlayer . teamName , 2 , 1 , "My answer" , "My reason" ) ;
221
229
expect ( game . protestsMatter ) . to . be . true ;
222
230
} ) ;
231
+ it ( "Uneven game, tossup with bonus for other team would swing it" , ( ) => {
232
+ const packet : PacketState = new PacketState ( ) ;
233
+ packet . setTossups ( [
234
+ new Tossup ( "first q" , "first a" ) ,
235
+ new Tossup ( "second q" , "second a" ) ,
236
+ new Tossup ( "third q" , "third a" ) ,
237
+ new Tossup ( "fourth q" , "fourth a" ) ,
238
+ ] ) ;
239
+ packet . setBonuses ( [
240
+ new Bonus ( "first leadin" , [
241
+ { question : "first q" , answer : "first a" , value : 10 } ,
242
+ { question : "first q2" , answer : "first a2" , value : 10 } ,
243
+ { question : "first q3" , answer : "first a3" , value : 10 } ,
244
+ ] ) ,
245
+ new Bonus ( "second leadin" , [
246
+ { question : "second q" , answer : "second a" , value : 10 } ,
247
+ { question : "second q2" , answer : "second a2" , value : 10 } ,
248
+ { question : "second q3" , answer : "second a3" , value : 10 } ,
249
+ ] ) ,
250
+ new Bonus ( "third leadin" , [
251
+ { question : "third q" , answer : "third a" , value : 10 } ,
252
+ { question : "third q2" , answer : "third a2" , value : 10 } ,
253
+ { question : "third q3" , answer : "third a3" , value : 10 } ,
254
+ ] ) ,
255
+ ] ) ;
256
+
257
+ const game : GameState = new GameState ( ) ;
258
+ game . addNewPlayers ( players ) ;
259
+ game . loadPacket ( defaultPacket ) ;
260
+
261
+ // 30-0
262
+ const firstCycle : Cycle = game . cycles [ 0 ] ;
263
+ firstCycle . addCorrectBuzz (
264
+ { player : firstTeamPlayer , points : 10 , position : 2 , isLastWord : false } ,
265
+ 0 ,
266
+ game . gameFormat ,
267
+ 0 ,
268
+ 3
269
+ ) ;
270
+ firstCycle . setBonusPartAnswer ( 0 , firstTeamPlayer . teamName , 10 ) ;
271
+ firstCycle . setBonusPartAnswer ( 1 , firstTeamPlayer . teamName , 10 ) ;
272
+ expect ( game . protestsMatter ) . to . be . false ;
273
+
274
+ // 25-40, but protest neg
275
+ const secondCycle : Cycle = game . cycles [ 1 ] ;
276
+ secondCycle . addWrongBuzz (
277
+ { player : firstTeamPlayer , points : - 5 , position : 1 , isLastWord : false } ,
278
+ 1 ,
279
+ game . gameFormat
280
+ ) ;
281
+ secondCycle . addTossupProtest ( firstTeamPlayer . teamName , 2 , 1 , "My answer" , "My reason" ) ;
282
+ secondCycle . addCorrectBuzz (
283
+ { player : secondTeamPlayer , points : 10 , position : 2 , isLastWord : false } ,
284
+ 1 ,
285
+ game . gameFormat ,
286
+ 1 ,
287
+ 3
288
+ ) ;
289
+ secondCycle . setBonusPartAnswer ( 0 , secondTeamPlayer . teamName , 10 ) ;
290
+ secondCycle . setBonusPartAnswer ( 1 , secondTeamPlayer . teamName , 10 ) ;
291
+ expect ( game . protestsMatter ) . to . be . true ;
292
+
293
+ // 25-50... protestMatter should still be true, since the protest in the second question should flip it
294
+ const thirdCycle : Cycle = game . cycles [ 2 ] ;
295
+ thirdCycle . addCorrectBuzz (
296
+ { player : secondTeamPlayer , points : 10 , position : 2 , isLastWord : false } ,
297
+ 2 ,
298
+ game . gameFormat ,
299
+ 2 ,
300
+ 3
301
+ ) ;
302
+ expect ( game . protestsMatter ) . to . be . true ;
303
+ } ) ;
223
304
} ) ;
224
305
} ) ;
225
306
0 commit comments