|
| 1 | +import { minesweeper } from '../Minesweeper' |
| 2 | + |
| 3 | +describe('Testing minesweeper function', () => { |
| 4 | + it('should return the expected 3x3 array', () => { |
| 5 | + const input = [ |
| 6 | + [true, false, false], |
| 7 | + [false, true, false], |
| 8 | + [false, false, false] |
| 9 | + ] |
| 10 | + const expectedOutput = [ |
| 11 | + [1, 2, 1], |
| 12 | + [2, 1, 1], |
| 13 | + [1, 1, 1] |
| 14 | + ] |
| 15 | + expect(minesweeper(input)).toStrictEqual(expectedOutput) |
| 16 | + }) |
| 17 | + |
| 18 | + it('should return the expected 3x4 array', () => { |
| 19 | + const input = [ |
| 20 | + [true, false, false, true], |
| 21 | + [false, false, true, false], |
| 22 | + [true, true, false, true] |
| 23 | + ] |
| 24 | + const expectedOutput = [ |
| 25 | + [0, 2, 2, 1], |
| 26 | + [3, 4, 3, 3], |
| 27 | + [1, 2, 3, 1] |
| 28 | + ] |
| 29 | + expect(minesweeper(input)).toStrictEqual(expectedOutput) |
| 30 | + }) |
| 31 | + |
| 32 | + it('should return the expected 5x2 array', () => { |
| 33 | + const input = [ |
| 34 | + [true, false], |
| 35 | + [true, false], |
| 36 | + [false, true], |
| 37 | + [false, false], |
| 38 | + [false, false] |
| 39 | + ] |
| 40 | + const expectedOutput = [ |
| 41 | + [1, 2], |
| 42 | + [2, 3], |
| 43 | + [2, 1], |
| 44 | + [1, 1], |
| 45 | + [0, 0] |
| 46 | + ] |
| 47 | + expect(minesweeper(input)).toStrictEqual(expectedOutput) |
| 48 | + }) |
| 49 | + |
| 50 | + it('should return the correct result when there are no mines', () => { |
| 51 | + const input = [ |
| 52 | + [false, false, false], |
| 53 | + [false, false, false] |
| 54 | + ] |
| 55 | + const expectedOutput = [ |
| 56 | + [0, 0, 0], |
| 57 | + [0, 0, 0] |
| 58 | + ] |
| 59 | + expect(minesweeper(input)).toStrictEqual(expectedOutput) |
| 60 | + }) |
| 61 | + |
| 62 | + it('should return the correct result when there are mines in every cell', () => { |
| 63 | + const input = [ |
| 64 | + [true, true, true], |
| 65 | + [true, true, true], |
| 66 | + [true, true, true] |
| 67 | + ] |
| 68 | + const expectedOutput = [ |
| 69 | + [3, 5, 3], |
| 70 | + [5, 8, 5], |
| 71 | + [3, 5, 3] |
| 72 | + ] |
| 73 | + expect(minesweeper(input)).toStrictEqual(expectedOutput) |
| 74 | + }) |
| 75 | +}) |
0 commit comments