-
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.
- Loading branch information
Showing
3 changed files
with
99 additions
and
7 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
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 |
---|---|---|
@@ -1,30 +1,92 @@ | ||
import { CellState, emptyFieldGenerator } from "./field"; | ||
import { CellState, fieldGenerator, generateFieldWithDefaultState } from "./field"; | ||
|
||
const { empty, bomb, hidden } = CellState; | ||
|
||
describe("Field Generator", () => { | ||
describe("emptyFieldGenerator tests", () => { | ||
it("should go with 2x2", function () { | ||
expect(emptyFieldGenerator(2)).toStrictEqual([ | ||
expect(generateFieldWithDefaultState(2)).toStrictEqual([ | ||
[empty, empty], | ||
[empty, empty], | ||
]); | ||
}); | ||
|
||
it("should go with 3x3", function () { | ||
expect(emptyFieldGenerator(3)).toStrictEqual([ | ||
expect(generateFieldWithDefaultState(3)).toStrictEqual([ | ||
[empty, empty, empty], | ||
[empty, empty, empty], | ||
[empty, empty, empty], | ||
]); | ||
}); | ||
|
||
it("should go with 2x2", function () { | ||
expect(emptyFieldGenerator(3, hidden)).toStrictEqual([ | ||
expect(generateFieldWithDefaultState(3, hidden)).toStrictEqual([ | ||
[hidden, hidden, hidden], | ||
[hidden, hidden, hidden], | ||
[hidden, hidden, hidden], | ||
]); | ||
}); | ||
}); | ||
|
||
describe("Simple Case", () => { | ||
it("should throw wrong density", function () { | ||
const errorText = "Probability must be between 0 and 1"; | ||
expect(() => fieldGenerator(1, -1)).toThrow(errorText); | ||
expect(() => fieldGenerator(1, 2)).toThrow(errorText); | ||
}); | ||
|
||
it("should have a smallest possible field without mine(bomb)", function () { | ||
expect(fieldGenerator(1, 0)).toStrictEqual([[empty]]); | ||
}); | ||
|
||
it("should have a BIG field without mine", () => { | ||
expect(fieldGenerator(10, 0)).toStrictEqual([ | ||
[empty, empty, empty, empty, empty, empty, empty, empty, empty, empty], | ||
[empty, empty, empty, empty, empty, empty, empty, empty, empty, empty], | ||
[empty, empty, empty, empty, empty, empty, empty, empty, empty, empty], | ||
[empty, empty, empty, empty, empty, empty, empty, empty, empty, empty], | ||
[empty, empty, empty, empty, empty, empty, empty, empty, empty, empty], | ||
[empty, empty, empty, empty, empty, empty, empty, empty, empty, empty], | ||
[empty, empty, empty, empty, empty, empty, empty, empty, empty, empty], | ||
[empty, empty, empty, empty, empty, empty, empty, empty, empty, empty], | ||
[empty, empty, empty, empty, empty, empty, empty, empty, empty, empty], | ||
[empty, empty, empty, empty, empty, empty, empty, empty, empty, empty], | ||
]); | ||
}); | ||
|
||
it("should have a smallest possible field with mine(bomb)", function () { | ||
expect(fieldGenerator(1, 1)).toStrictEqual([[bomb]]); | ||
}); | ||
|
||
it("should have 2x2 field with mines(bomb)", function () { | ||
expect(fieldGenerator(2, 1)).toStrictEqual([ | ||
[bomb, bomb], | ||
[bomb, bomb], | ||
]); | ||
}); | ||
|
||
it("should have 2x2 field with 50% probability mines(bomb)", function () { | ||
expect(fieldGenerator(2, 0.5)).toStrictEqual([ | ||
[bomb, bomb], | ||
[empty, empty], | ||
]); | ||
}); | ||
|
||
it("should have 4x4 field with 50% of probability mines(bomb)", function () { | ||
expect(fieldGenerator(4, 0.5)).toStrictEqual([ | ||
[bomb, bomb, bomb, bomb], | ||
[bomb, bomb, bomb, bomb], | ||
[empty, empty, empty, empty], | ||
[empty, empty, empty, empty], | ||
]); | ||
}); | ||
|
||
it("should have 3x3 field with 50% of probability mines(bomb)", function () { | ||
const field = fieldGenerator(3, 0.5); | ||
const flatField = field.flat(); | ||
|
||
console.table(field); | ||
console.table(flatField); | ||
}); | ||
}); | ||
}); |
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