-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test new helpers to set a flag in the game
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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], | ||
]); | ||
}); | ||
}); | ||
}); |