Skip to content

Commit 84cea91

Browse files
committed
Improve test robustness
Tests will now fail if they create an impossible situation.
1 parent 5f9847b commit 84cea91

18 files changed

+186
-155
lines changed

test/conventionless/endgame.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe('simple endgames with 1 card left', () => {
8787
['r4', 'r4', 'xx', 'xx'],
8888
['b2', 'y1', 'g1', 'b5'],
8989
['g1', 'b1', 'b1', 'r1'],
90-
['b2', 'p1', 'p1', 'r5'],
90+
['r1', 'p1', 'p1', 'r5'],
9191
], {
9292
play_stacks: [3, 5, 5, 4, 5],
9393
init: (game) => {
@@ -114,9 +114,9 @@ describe('simple endgames with 1 card left', () => {
114114
it('plays to start endgame when other has dupes', () => {
115115
const game = setup(HGroup, [
116116
['p3', 'xx', 'xx', 'xx'],
117-
['b1', 'p4', 'g1', 'p4'],
118-
['g1', 'b1', 'b1', 'r1'],
119-
['r1', 'p1', 'p1', 'p5'],
117+
['b1', 'p4', 'b1', 'p4'],
118+
['r1', 'y1', 'g1', 'p1'],
119+
['r1', 'y1', 'g1', 'p5'],
120120
], {
121121
play_stacks: [5, 5, 5, 5, 2],
122122
discarded: ['p3'],

test/h-group/h-endgames.js

+8-34
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { strict as assert } from 'node:assert';
22
import { describe, it } from 'node:test';
33
import * as ExAsserts from '../../test/extra-asserts.js';
44

5-
import { COLOUR, PLAYER, expandShortCard, setup } from '../test-utils.js';
5+
import { COLOUR, PLAYER, expandShortCard, preClue, setup } from '../test-utils.js';
66
import HGroup from '../../src/conventions/h-group.js';
77

88
import { ACTION, CLUE } from '../../src/constants.js';
@@ -20,45 +20,19 @@ describe('simple endgames with 1 card left', () => {
2020
const game = setup(HGroup, [
2121
['r5', 'xx', 'xx', 'xx'],
2222
['y5', 'r1', 'g1', 'b1'],
23-
['r4', 'b1', 'b1', 'g1'],
23+
['r4', 'r1', 'g1', 'b1'],
2424
['r4', 'p1', 'p1', 'b5'],
2525
], {
2626
play_stacks: [3, 4, 5, 4, 5],
2727
clue_tokens: 2,
2828
init: (game) => {
29-
const { common, state } = game;
30-
31-
const update1 = (draft) => {
32-
draft.clued = true;
33-
draft.clues.push({ giver: PLAYER.DONALD, type: CLUE.RANK, value: 5, turn: -1 });
34-
draft.clues.push({ giver: PLAYER.DONALD, type: CLUE.COLOUR, value: COLOUR.RED, turn: -1 });
35-
};
36-
37-
const a_slot1 = state.hands[PLAYER.ALICE][0];
38-
state.deck = state.deck.with(a_slot1, produce(state.deck[a_slot1], update1));
39-
40-
let { inferred, possible } = common.thoughts[a_slot1];
41-
common.updateThoughts(state.hands[PLAYER.ALICE][0], (draft) => {
42-
draft.inferred = inferred.intersect(expandShortCard('r5'));
43-
draft.possible = possible.intersect(expandShortCard('r5'));
44-
update1(draft);
45-
});
46-
47-
const update2 = (draft) => {
48-
draft.clued = true;
49-
draft.clues.push({ giver: PLAYER.ALICE, type: CLUE.RANK, value: 5, turn: -1 });
50-
draft.clues.push({ giver: PLAYER.ALICE, type: CLUE.COLOUR, value: COLOUR.BLUE, turn: -1 });
51-
};
52-
53-
const d_slot4 = state.hands[PLAYER.DONALD][3];
54-
state.deck = state.deck.with(d_slot4, produce(state.deck[d_slot4], update2));
29+
preClue(game, game.state.hands[PLAYER.ALICE][0], [
30+
{ giver: PLAYER.DONALD, type: CLUE.RANK, value: 5 },
31+
{ giver: PLAYER.DONALD, type: CLUE.COLOUR, value: COLOUR.RED }]);
5532

56-
({ inferred, possible } = common.thoughts[d_slot4]);
57-
common.updateThoughts(state.hands[PLAYER.DONALD][3], (draft) => {
58-
draft.inferred = inferred.intersect(expandShortCard('b5'));
59-
draft.possible = possible.intersect(expandShortCard('b5'));
60-
update2(draft);
61-
});
33+
preClue(game, game.state.hands[PLAYER.DONALD][3], [
34+
{ giver: PLAYER.ALICE, type: CLUE.RANK, value: 5 },
35+
{ giver: PLAYER.ALICE, type: CLUE.COLOUR, value: COLOUR.BLUE }]);
6236

6337
game.state.cardsLeft = 1;
6438
}

test/h-group/level-1/good-touch-principle.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ describe('good touch principle', () => {
5454
it('eliminates from indirect focus', () => {
5555
const game = setup(HGroup, [
5656
['xx', 'xx', 'xx', 'xx', 'xx'],
57-
['b2', 'b4', 'b2', 'p2', 'r1'],
58-
['y3', 'r4', 'y2', 'p1', 'g3']
57+
['r1', 'b4', 'g1', 'b1', 'p1'],
58+
['r1', 'y1', 'g1', 'b1', 'p1']
5959
], {
6060
level: { min: 1 },
6161
play_stacks: [5, 2, 5, 3, 5],

test/h-group/level-1/play-clues.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ describe('counting playables', () => {
287287
it('considers ambiguous play clues to still be plays', () => {
288288
const game = setup(HGroup, [
289289
['xx', 'xx', 'xx', 'xx', 'xx'],
290-
['y1', 'p4', 'g4', 'g4', 'r4'],
290+
['y1', 'g2', 'p4', 'g4', 'r4'],
291291
['y5', 'r2', 'y3', 'p1', 'y1']
292292
], {
293293
level: { min: 1 },

test/h-group/level-1/special-moves.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe('other cases', () => {
6161
const game = setup(HGroup, [
6262
['xx', 'xx', 'xx', 'xx'],
6363
['p1', 'p4', 'r3', 'y5'],
64-
['y5', 'r4', 'r4', 'r2'],
64+
['r5', 'r4', 'r4', 'r2'],
6565
['r1', 'b2', 'g3', 'b1']
6666
], {
6767
level: { min: 1 },
@@ -80,7 +80,7 @@ describe('other cases', () => {
8080
const game = setup(HGroup, [
8181
['xx', 'xx', 'xx', 'xx', 'xx'],
8282
['r2', 'p4', 'r3', 'y5', 'r1'],
83-
['y5', 'g4', 'r3', 'b4', 'g5']
83+
['p5', 'g4', 'r3', 'b4', 'g5']
8484
], {
8585
level: { min: 1 },
8686
play_stacks: [1, 0, 2, 2, 0],

test/h-group/level-10.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ describe('baton discards', () => {
167167
const game = setup(HGroup, [
168168
['xx', 'xx', 'xx', 'xx'],
169169
['b4', 'g4', 'y2', 'b2'],
170-
['r1', 'y4', 'r4', 'y3'],
170+
['r1', 'y4', 'p4', 'y3'],
171171
['y1', 'r4', 'b4', 'b1']
172172
], {
173173
level: { min: 10 },
@@ -189,7 +189,7 @@ describe('baton discards', () => {
189189
const game = setup(HGroup, [
190190
['xx', 'xx', 'xx', 'xx'],
191191
['b3', 'g4', 'y2', 'b2'],
192-
['r1', 'y4', 'r4', 'y3'],
192+
['r1', 'y4', 'p4', 'y3'],
193193
['y1', 'r4', 'b4', 'b1']
194194
], {
195195
level: { min: 10 },
@@ -327,7 +327,7 @@ describe('composition finesse', () => {
327327
it('resolves a complex certain discard correctly', () => {
328328
const game = setup(HGroup, [
329329
['xx', 'xx', 'xx', 'xx'],
330-
['r4', 'b4', 'y4', 'g4'],
330+
['r1', 'b4', 'y4', 'g4'],
331331
['g2', 'r4', 'y3', 'b5'],
332332
['g1', 'g3', 'r2', 'b1']
333333
], {
@@ -366,7 +366,7 @@ describe('composition finesse', () => {
366366
it('resolves a fake certain discard correctly', () => {
367367
const game = setup(HGroup, [
368368
['xx', 'xx', 'xx', 'xx'],
369-
['g2', 'r4', 'y3', 'b5'],
369+
['g2', 'r4', 'y3', 'g5'],
370370
['g1', 'g3', 'r2', 'b1'],
371371
['b2', 'y5', 'b5', 'b4']
372372
], {

0 commit comments

Comments
 (0)