mirror of
https://github.com/Kugelschieber/breach.git
synced 2026-01-18 12:00:25 +00:00
Implement buffer filling and sequence fulfillment
This commit is contained in:
@@ -9,27 +9,27 @@ describe("GameState", () => {
|
||||
]
|
||||
|
||||
test("getting size works", () => {
|
||||
expect((new Game([])).size).toEqual(0)
|
||||
expect((new Game(["00"])).size).toEqual(1)
|
||||
expect((new Game([], [])).size).toEqual(0)
|
||||
expect((new Game(["00"], [])).size).toEqual(1)
|
||||
expect((new Game([
|
||||
"00", "01",
|
||||
"10", "11",
|
||||
])).size).toEqual(2)
|
||||
], [])).size).toEqual(2)
|
||||
});
|
||||
|
||||
test("getting cell works", () => {
|
||||
const game = new Game(threeByThreeMatrix);
|
||||
const game = new Game(threeByThreeMatrix, []);
|
||||
expect(game.getCell(0, 2)).toEqual("02")
|
||||
});
|
||||
|
||||
|
||||
describe("picking", () => {
|
||||
test("starts with free pick", () => {
|
||||
const game = new Game([]);
|
||||
const game = new Game([], []);
|
||||
expect(game.state).toEqual({selectionMode: SelectionMode.FreePick})
|
||||
});
|
||||
|
||||
|
||||
test("picking cells works", () => {
|
||||
const game = new Game(threeByThreeMatrix);
|
||||
const game = new Game(threeByThreeMatrix, []);
|
||||
game.pick(0, 0);
|
||||
expect(game.state).toEqual({selectionMode: SelectionMode.RowPick, column: 0});
|
||||
expect(() => game.pick(0, 2)).toThrow();
|
||||
@@ -38,11 +38,40 @@ describe("GameState", () => {
|
||||
});
|
||||
|
||||
test("picking outside of range fails", () => {
|
||||
const game = new Game(threeByThreeMatrix);
|
||||
const game = new Game(threeByThreeMatrix, []);
|
||||
expect(() => game.pick(-1, 0)).toThrow();
|
||||
expect(() => game.pick(0, -1)).toThrow();
|
||||
expect(() => game.pick(3, 0)).toThrow();
|
||||
expect(() => game.pick(0, 3)).toThrow();
|
||||
});
|
||||
|
||||
test("picking fills buffer, fulfills sequence", () => {
|
||||
const simpleSequence = ["00", "10", "20"]
|
||||
const game = new Game(threeByThreeMatrix, [simpleSequence]);
|
||||
expect(game.getSequences()).toEqual([{sequence: simpleSequence, numberOfFulfilled: 0}])
|
||||
game.pick(0, 0);
|
||||
expect(game.buffer).toEqual(["00"]);
|
||||
expect(game.getSequences()).toEqual([{sequence: simpleSequence, numberOfFulfilled: 1}])
|
||||
});
|
||||
|
||||
test("picking fulfills second sequence occurence", () => {
|
||||
const sequence = ["AA", "BB", "CC"]
|
||||
const game = new Game([
|
||||
"AA", "AA", "BB",
|
||||
"BB", "CC", "AA",
|
||||
"CC", "CC", "CC",
|
||||
], [sequence]);
|
||||
expect(game.getSequences()).toEqual([{sequence: sequence, numberOfFulfilled: 0}])
|
||||
game.pick(0, 0);
|
||||
expect(game.getSequences()).toEqual([{sequence: sequence, numberOfFulfilled: 1}])
|
||||
game.pick(2, 0);
|
||||
expect(game.getSequences()).toEqual([{sequence: sequence, numberOfFulfilled: 2}])
|
||||
game.pick(2, 1);
|
||||
expect(game.getSequences()).toEqual([{sequence: sequence, numberOfFulfilled: 1}])
|
||||
game.pick(0, 1);
|
||||
expect(game.getSequences()).toEqual([{sequence: sequence, numberOfFulfilled: 2}])
|
||||
game.pick(0, 2);
|
||||
expect(game.getSequences()).toEqual([{sequence: sequence, numberOfFulfilled: 3}])
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user