diff --git a/src/model/__tests__/__snapshots__/puzzle-generator.test.ts.snap b/src/model/__tests__/__snapshots__/puzzle-generator.test.ts.snap index c3bdc73..dbfcdd3 100644 --- a/src/model/__tests__/__snapshots__/puzzle-generator.test.ts.snap +++ b/src/model/__tests__/__snapshots__/puzzle-generator.test.ts.snap @@ -5,301 +5,301 @@ Array [ Array [ Object { "column": 0, - "letter": "H", + "letter": "W", "row": 0, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 1, - "letter": "F", + "letter": "G", "row": 0, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 2, - "letter": "N", + "letter": "B", "row": 0, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 3, - "letter": "O", + "letter": "B", "row": 0, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 4, - "letter": "R", + "letter": "X", "row": 0, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 5, - "letter": "A", + "letter": "V", "row": 0, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 6, - "letter": "S", + "letter": "K", "row": 0, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 7, - "letter": "D", + "letter": "L", "row": 0, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, ], Array [ Object { "column": 0, - "letter": "P", + "letter": "G", "row": 1, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 1, - "letter": "D", + "letter": "H", "row": 1, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 2, - "letter": "M", + "letter": "H", "row": 1, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 3, - "letter": "U", + "letter": "G", "row": 1, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 4, - "letter": "P", + "letter": "D", "row": 1, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 5, - "letter": "X", + "letter": "K", "row": 1, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 6, - "letter": "X", + "letter": "L", "row": 1, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 7, - "letter": "C", + "letter": "S", "row": 1, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, ], Array [ Object { "column": 0, - "letter": "E", + "letter": "T", "row": 2, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 1, - "letter": "F", + "letter": "J", "row": 2, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 2, - "letter": "F", + "letter": "X", "row": 2, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 3, - "letter": "V", + "letter": "U", "row": 2, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 4, - "letter": "P", + "letter": "F", "row": 2, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 5, - "letter": "E", + "letter": "P", "row": 2, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 6, - "letter": "X", + "letter": "G", "row": 2, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 7, - "letter": "T", + "letter": "H", "row": 2, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, ], Array [ Object { "column": 0, - "letter": "K", + "letter": "L", "row": 3, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 1, - "letter": "D", + "letter": "W", "row": 3, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 2, - "letter": "S", + "letter": "T", "row": 3, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 3, - "letter": "F", + "letter": "E", "row": 3, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 4, - "letter": "C", + "letter": "X", "row": 3, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 5, - "letter": "J", + "letter": "P", "row": 3, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 6, - "letter": "Q", + "letter": "G", "row": 3, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 7, - "letter": "J", + "letter": "H", "row": 3, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, ], Array [ Object { "column": 0, - "letter": "Q", + "letter": "M", "row": 4, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 1, - "letter": "B", + "letter": "F", "row": 4, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 2, - "letter": "S", + "letter": "C", "row": 4, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 3, - "letter": "P", + "letter": "F", "row": 4, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 4, "letter": "W", "row": 4, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 5, - "letter": "G", + "letter": "X", "row": 4, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 6, - "letter": "K", + "letter": "D", "row": 4, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 7, - "letter": "M", + "letter": "D", "row": 4, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, ], Array [ Object { "column": 0, - "letter": "C", + "letter": "H", "row": 5, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 1, - "letter": "B", + "letter": "S", "row": 5, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 2, - "letter": "Y", + "letter": "X", "row": 5, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 3, - "letter": "L", + "letter": "G", "row": 5, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 4, - "letter": "M", + "letter": "K", "row": 5, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 5, - "letter": "E", + "letter": "U", "row": 5, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 6, - "letter": "X", + "letter": "N", "row": 5, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 7, - "letter": "C", + "letter": "T", "row": 5, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, ], Array [ @@ -307,49 +307,49 @@ Array [ "column": 0, "letter": "Z", "row": 6, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 1, - "letter": "F", + "letter": "X", "row": 6, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 2, - "letter": "P", + "letter": "I", "row": 6, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 3, - "letter": "Z", + "letter": "E", "row": 6, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 4, - "letter": "M", + "letter": "L", "row": 6, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 5, - "letter": "I", + "letter": "Q", "row": 6, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 6, - "letter": "G", + "letter": "O", "row": 6, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 7, - "letter": "Q", + "letter": "R", "row": 6, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, ], Array [ @@ -357,49 +357,49 @@ Array [ "column": 0, "letter": "E", "row": 7, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 1, - "letter": "C", + "letter": "Y", "row": 7, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 2, - "letter": "B", + "letter": "I", "row": 7, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 3, - "letter": "H", + "letter": "G", "row": 7, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 4, - "letter": "J", + "letter": "G", "row": 7, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 5, - "letter": "Q", + "letter": "X", "row": 7, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 6, - "letter": "K", + "letter": "W", "row": 7, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, Object { "column": 7, - "letter": "X", + "letter": "A", "row": 7, - "updatedAt": "2017-07-14T02:40:00.000Z", + "updatedAt": 2017-07-14T02:40:00.000Z, }, ], ] diff --git a/src/model/__tests__/game-utils.test.ts b/src/model/__tests__/game-utils.test.ts new file mode 100644 index 0000000..4c8098f --- /dev/null +++ b/src/model/__tests__/game-utils.test.ts @@ -0,0 +1,23 @@ +import { mockMathRandom } from 'utils/mockMathRandom' +import PuzzleGenerator from '../puzzle-generator' + +const noise = 'ABCDEFGHIJKLMNOPQRSTVWUXYZ'.split('') +const solution = 'NORA'.toUpperCase().split('') + +beforeAll(() => { + mockMathRandom() +}) + +// isCorrectAnswer + +// didWin + +// didLoose + +describe('Puzzle', () => { + it('Should generate a 6 x 6 grid', () => { + const puzzle = new PuzzleGenerator(6, solution, noise) + expect(puzzle.grid.length).toEqual(6) + expect(puzzle.grid[0].length).toEqual(6) + }) +}) diff --git a/src/model/__tests__/puzzle-generator.test.ts b/src/model/__tests__/puzzle-generator.test.ts index 211eaf4..1960f74 100644 --- a/src/model/__tests__/puzzle-generator.test.ts +++ b/src/model/__tests__/puzzle-generator.test.ts @@ -1,8 +1,13 @@ +import { mockMathRandom } from 'utils/mockMathRandom' import PuzzleGenerator from '../puzzle-generator' const noise = 'ABCDEFGHIJKLMNOPQRSTVWUXYZ'.split('') const solution = 'NORA'.toUpperCase().split('') +beforeEach(() => { + mockMathRandom() +}) + describe('Puzzle', () => { it('Should generate a 6 x 6 grid', () => { const puzzle = new PuzzleGenerator(6, solution, noise) @@ -27,6 +32,12 @@ describe('Puzzle', () => { }) }) +describe('removeSolutionLettersFrom()', () => { + const puzzle = new PuzzleGenerator(6, solution, noise) + puzzle.removeSolutionLettersFrom('NORABCD'.split('')) + expect(puzzle.noise).toEqual(['B', 'C', 'D']) +}) + describe('calculateStepsToEdge()', () => { it('Should calculate steps to edge start at origin', () => { const puzzle = new PuzzleGenerator(6, solution, noise) @@ -67,8 +78,27 @@ describe('updateIndices()', () => { }) describe('applyTransformations()', () => { - it('Should ...', () => { - // const puzzle = new PuzzleGenerator(6, solution, noise) - // + it('Should do nothing on first tranformation', () => { + const puzzle = new PuzzleGenerator(4, solution, noise) + puzzle.applyRandomTransformation() + const str = puzzle.toString() + expect(str.startsWith('BLGA')).toBeTruthy() + }) + + it('Should rotate counterclockwise on second tranformation', () => { + const puzzle = new PuzzleGenerator(4, solution, noise) + puzzle.applyRandomTransformation() + puzzle.applyRandomTransformation() + const str = puzzle.toString() + expect(str.startsWith('ARKD')).toBeTruthy() + }) + + it('Should mirror horizontally on third tranformation', () => { + const puzzle = new PuzzleGenerator(4, solution, noise) + puzzle.applyRandomTransformation() + puzzle.applyRandomTransformation() + puzzle.applyRandomTransformation() + const str = puzzle.toString() + expect(str.endsWith('ARKD\n')).toBeTruthy() }) }) diff --git a/src/model/puzzle-generator.ts b/src/model/puzzle-generator.ts index 358b427..bab20a4 100644 --- a/src/model/puzzle-generator.ts +++ b/src/model/puzzle-generator.ts @@ -7,7 +7,7 @@ import { class PuzzleGenerator { public grid: GridType - private noise: string[] + public noise: string[] constructor( readonly size: number, @@ -112,10 +112,10 @@ class PuzzleGenerator { public toString() { let s: string = '' this.grid.forEach(row => { - s += '\n' row.forEach(item => { - s += ' ' + item.letter + s += item.letter }) + s += '\n' }) return s } diff --git a/src/setupTests.ts b/src/setupTests.ts index 02a6589..4399959 100644 --- a/src/setupTests.ts +++ b/src/setupTests.ts @@ -2,4 +2,3 @@ import { mockDate } from './utils/mockDate' import { mockMathRandom } from './utils/mockMathRandom' mockDate() -mockMathRandom()