Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const assert = require('chai').assert;
- const generator = require('../guest-src/generator');
- describe('Generator', function(){
- beforeEach(function() {
- testGrid = [
- [6,4,1,9,8,2,3,5,7],
- [8,7,2,3,6,5,4,9,1],
- [3,5,9,4,1,7,2,8,6],
- [2,3,7,8,9,1,6,4,5],
- [1,8,6,5,2,4,7,3,9],
- [5,9,4,7,3,6,8,1,2],
- [4,1,8,2,7,9,5,6,3],
- [7,6,5,1,4,3,9,2,8],
- [9,2,3,6,5,8,1,7,4]
- ];
- testGridToSolve = [
- [6,4,1,9,8,2,3,5,7],
- [8,7,2,3,6,5,4,9,1],
- [3,5,9,4,1,7,2,8,6],
- [2,3,7,8,9,1,6,4,5],
- [1,8,6,5,2,4,7,3,9],
- [5,9,4,7,3,6,8,1,2],
- [4,1,8,2,7,9,5,6,3],
- [7,6,5,1,4,3,9,2,8],
- [9,2,3,6,5,8,0,0,0]
- ];
- });
- describe('check', function(){
- it('check function should return true for solved grid', function() {
- assert.equal(generator.check(testGrid), true);
- });
- it('check function return false for unsolved grid', function() {
- assert.equal(generator.check(testGridToSolve), false);
- });
- });
- describe('fill', function(){
- it('fill function should solve the test grid with 3 empty squares', function() {
- assert.deepEqual(generator.fill(testGridToSolve), testGrid);
- });
- it('fill function should not leave any empty square (represented by 0)', function() {
- assert.notDeepInclude(generator.fill(testGridToSolve), 0);
- });
- });
- describe('shuffle', function(){
- it('shuffle has the same length as the initial list and keeps its every element', function() {
- list = [1,2,3,4,5,6,7,8];
- shuffled = generator.shuffle(list);
- list.forEach(elem => assert.include(shuffled, elem));
- assert.equal(list.length, shuffled.length);
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement