Do not allow picking cells twice

This commit is contained in:
Erik Schilling
2020-12-17 15:58:50 +01:00
parent 85f32c946e
commit d7bf259964
2 changed files with 44 additions and 7 deletions

View File

@@ -21,7 +21,7 @@ describe("GameState", () => {
test("getting cell works", () => {
const game = new Game(threeByThreeMatrix, [["AA"]], unrestrictedBuffer, unlimitedTime);
expect(game.getCell(0, 2)).toEqual("02")
expect(game.getCell(0, 2)).toEqual({ value: "02", isUsed: false })
});
describe("picking", () => {
@@ -34,11 +34,18 @@ describe("GameState", () => {
const game = new Game(threeByThreeMatrix, [["AA"]], unrestrictedBuffer, unlimitedTime);
game.pick(0, 0);
expect(game.state).toEqual({selectionMode: SelectionMode.RowPick, column: 0});
expect(game.getCell(0, 0).isUsed).toEqual(true);
expect(() => game.pick(0, 2)).toThrow();
game.pick(2, 0);
expect(game.state).toEqual({selectionMode: SelectionMode.ColumnPick, row: 2});
});
test("cannot pick cell twice", () => {
const game = new Game(threeByThreeMatrix, [["AA"]], unrestrictedBuffer, unlimitedTime);
game.pick(0, 0);
expect(() => game.pick(0, 0)).toThrow();
});
test("picking outside of range fails", () => {
const game = new Game(threeByThreeMatrix, [], unrestrictedBuffer, unlimitedTime);
expect(() => game.pick(-1, 0)).toThrow();
@@ -52,7 +59,11 @@ describe("GameState", () => {
const game = new Game(threeByThreeMatrix, [simpleSequence], unrestrictedBuffer, unlimitedTime);
expect(game.getSequences()).toEqual([{sequence: simpleSequence, numberOfFulfilled: 0}])
game.pick(0, 0);
expect(game.buffer).toEqual(["00"]);
expect(game.buffer).toEqual([{
positionInMatrixRow: 0,
positionInMatrixColumn: 0,
value: "00"
}]);
expect(game.getSequences()).toEqual([{sequence: simpleSequence, numberOfFulfilled: 1}])
});