KnightTour : convert live code example to Jest test (log remaining is within a print method).

This commit is contained in:
Eric Lavault
2021-10-09 15:05:52 +02:00
parent 97724cc937
commit 7f6a53ad4a
2 changed files with 25 additions and 12 deletions

View File

@ -64,15 +64,4 @@ class OpenKnightTour {
}
}
function main () {
const board = new OpenKnightTour(5)
board.printBoard()
console.log('\n')
board.solve()
board.printBoard()
}
main()
export { OpenKnightTour }

View File

@ -0,0 +1,24 @@
import { OpenKnightTour } from '../KnightTour'
describe('OpenKnightTour', () => {
it('OpenKnightTour(5)', () => {
const KT = new OpenKnightTour(5)
expect(KT.board).toEqual([
[ 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0 ],
[ 0, 0, 0, 0, 0 ]
])
KT.solve()
expect(KT.board).toEqual([
[ 19, 4, 15, 10, 25 ],
[ 14, 9, 18, 5, 16 ],
[ 1, 20, 3, 24, 11 ],
[ 8, 13, 22, 17, 6 ],
[ 21, 2, 7, 12, 23 ]
])
})
})