mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 17:50:39 +08:00
KnightTour : convert live code example to Jest test (log remaining is within a print method).
This commit is contained in:
@ -64,15 +64,4 @@ class OpenKnightTour {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function main () {
|
export { OpenKnightTour }
|
||||||
const board = new OpenKnightTour(5)
|
|
||||||
|
|
||||||
board.printBoard()
|
|
||||||
console.log('\n')
|
|
||||||
|
|
||||||
board.solve()
|
|
||||||
|
|
||||||
board.printBoard()
|
|
||||||
}
|
|
||||||
|
|
||||||
main()
|
|
||||||
|
24
Backtracking/tests/KnightTour.test.js
Normal file
24
Backtracking/tests/KnightTour.test.js
Normal 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 ]
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
Reference in New Issue
Block a user