Advertisement
PaweU

testy

Dec 11th, 2020 (edited)
526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const assert = require('chai').assert;
  2. const generator = require('../guest-src/generator');
  3.  
  4. describe('Generator', function(){
  5.     beforeEach(function() {
  6.         testGrid = [
  7.             [6,4,1,9,8,2,3,5,7],
  8.             [8,7,2,3,6,5,4,9,1],
  9.             [3,5,9,4,1,7,2,8,6],
  10.             [2,3,7,8,9,1,6,4,5],
  11.             [1,8,6,5,2,4,7,3,9],
  12.             [5,9,4,7,3,6,8,1,2],
  13.             [4,1,8,2,7,9,5,6,3],
  14.             [7,6,5,1,4,3,9,2,8],
  15.             [9,2,3,6,5,8,1,7,4]
  16.         ];
  17.  
  18.         testGridToSolve = [
  19.             [6,4,1,9,8,2,3,5,7],
  20.             [8,7,2,3,6,5,4,9,1],
  21.             [3,5,9,4,1,7,2,8,6],
  22.             [2,3,7,8,9,1,6,4,5],
  23.             [1,8,6,5,2,4,7,3,9],
  24.             [5,9,4,7,3,6,8,1,2],
  25.             [4,1,8,2,7,9,5,6,3],
  26.             [7,6,5,1,4,3,9,2,8],
  27.             [9,2,3,6,5,8,0,0,0]
  28.         ];
  29.       });
  30.  
  31.     describe('check', function(){
  32.         it('check function should return true for solved grid', function() {
  33.             assert.equal(generator.check(testGrid), true);
  34.         });
  35.        
  36.         it('check function return false for unsolved grid', function() {
  37.             assert.equal(generator.check(testGridToSolve), false);
  38.         });
  39.  
  40.     });
  41.  
  42.     describe('fill', function(){
  43.  
  44.         it('fill function should solve the test grid with 3 empty squares', function() {
  45.             assert.deepEqual(generator.fill(testGridToSolve), testGrid);
  46.         });
  47.        
  48.         it('fill function should not leave any empty square (represented by 0)', function() {
  49.             assert.notDeepInclude(generator.fill(testGridToSolve), 0);
  50.         });
  51.     });
  52.  
  53.     describe('shuffle', function(){
  54.  
  55.         it('shuffle has the same length as the initial list and keeps its every element', function() {
  56.             list = [1,2,3,4,5,6,7,8];
  57.             shuffled = generator.shuffle(list);
  58.  
  59.             list.forEach(elem => assert.include(shuffled, elem));
  60.             assert.equal(list.length, shuffled.length);
  61.         });
  62.     });
  63. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement