Skip to content

Commit

Permalink
Test new helpers to set a flag in the game
Browse files Browse the repository at this point in the history
  • Loading branch information
zourdyzou committed Aug 9, 2022
1 parent 2ebe4b8 commit 500d68d
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions src/helpers/set-flag.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { CellState, Field } from "@helpers/field";
import { setFlag } from "@helpers/set-flag";

const { empty: e, hidden: h, bomb: b, mark: m, weakMark: w } = CellState;

describe("Set flag action", () => {
describe("Set flag to the cell check", () => {
it("Set flag to the non hidden cell should be ignored", () => {
const gameField: Field = [
[1, 1, e],
[b, 1, e],
[1, 1, e],
];
const playerField: Field = [
[1, h, h],
[h, h, h],
[h, h, h],
];

const newPlayerField = setFlag([0, 0], playerField, gameField);

expect(newPlayerField).toStrictEqual([
[1, h, h],
[h, h, h],
[h, h, h],
]);
});
it("Set Flag action, simple 3*3 case", () => {
const gameField: Field = [
[1, 1, e],
[b, 1, e],
[1, 1, e],
];

const playerField: Field = [
[h, h, h],
[h, h, h],
[h, h, h],
];

const playerFieldAfterFirstClick = setFlag([0, 0], playerField, gameField);

expect(playerFieldAfterFirstClick).toStrictEqual([
[m, h, h],
[h, h, h],
[h, h, h],
]);

const playerFieldAfterSecondClick = setFlag([0, 0], playerField, gameField);

expect(playerFieldAfterSecondClick).toStrictEqual([
[w, h, h],
[h, h, h],
[h, h, h],
]);

const playerFieldAfterThirdClick = setFlag([0, 0], playerField, gameField);

expect(playerFieldAfterThirdClick).toStrictEqual([
[h, h, h],
[h, h, h],
[h, h, h],
]);
});
});
});

0 comments on commit 500d68d

Please sign in to comment.