Advertisement
Btwonu

isSymmetric

Oct 28th, 2020
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // • Take an array as argument
  2. // • Return false for any input that isn’t of the correct type
  3. // • Return true if the input array is symmetric
  4. // • Otherwise, return false
  5.  
  6. const assert = require('chai').assert;
  7. const isSymmetric = require('../../lab/isSymmetric');
  8.  
  9. describe('Testing if an array is symmetrical', () => {
  10.   it('Should work with even count elements', () => {
  11.     let inp0 = [1, 2, 3, 3, 2, 1];
  12.  
  13.     let res0 = isSymmetric(inp0);
  14.  
  15.     assert.isTrue(res0, 'result is not true');
  16.   });
  17.  
  18.   it('Should work with odd count elements', () => {
  19.     let inp0 = [1, 2, 3, 2, 1];
  20.  
  21.     let res0 = isSymmetric(inp0);
  22.  
  23.     assert.isTrue(res0, 'result is not true');
  24.   });
  25.  
  26.   it('Should work with an array which contain different data types', () => {
  27.     let inp0 = [1, '2', 3, 3, '2', 1];
  28.     let inp1 = [1, 'string', 'center', 'string', 1];
  29.  
  30.     let arr = [];
  31.     let obj = {};
  32.     let inp2 = ['arr', 0, arr, obj, () => {}, obj, arr, 0, 'arr'];
  33.  
  34.     let res0 = isSymmetric(inp0);
  35.     let res1 = isSymmetric(inp1);
  36.     let res2 = isSymmetric(inp2);
  37.  
  38.     assert.isTrue(res0, "doesn't work with strings");
  39.     assert.isTrue(res1, "doesn't work with strings");
  40.     assert.isTrue(res2, "doesn't work with mixed data types");
  41.   });
  42.  
  43.   it('Should return false if array is not symmetrical', () => {
  44.     let inp0 = [1, 2, 3, 4, 5];
  45.     let inp1 = [6, 5, 4, 3, 2, 1];
  46.  
  47.     let res0 = isSymmetric(inp0);
  48.     let res1 = isSymmetric(inp1);
  49.  
  50.     assert.isFalse(res0, 'passing a normal array');
  51.     assert.isFalse(res1, 'passing a reversed normal array');
  52.   });
  53.  
  54.   it('Should return false if input type is not an array', () => {
  55.     let inp0 = [1, 2, 3, 2, 1];
  56.     let inp1 = undefined;
  57.     let inp2 = 0;
  58.     let inp3 = 10n;
  59.     let inp4 = false;
  60.     let inp5 = 'string';
  61.     let inp6 = Symbol();
  62.     let inp7 = { object: 'object' };
  63.     let inp8 = function () {};
  64.  
  65.     let res0 = isSymmetric(inp0);
  66.     let res1 = isSymmetric(inp1);
  67.     let res2 = isSymmetric(inp2);
  68.     let res3 = isSymmetric(inp3);
  69.     let res4 = isSymmetric(inp4);
  70.     let res5 = isSymmetric(inp5);
  71.     let res6 = isSymmetric(inp6);
  72.     let res7 = isSymmetric(inp7);
  73.     let res8 = isSymmetric(inp8);
  74.  
  75.     assert.isNotFalse(res0);
  76.     assert.isFalse(res1, 'passing undefined as an argument');
  77.     assert.isFalse(res2, 'passing number as an argument');
  78.     assert.isFalse(res3, 'passing big int as an argument');
  79.     assert.isFalse(res4, 'passing boolean as an argument');
  80.     assert.isFalse(res5, 'passing string as an argument');
  81.     assert.isFalse(res6, 'passing symbol as an argument');
  82.     assert.isFalse(res7, 'passing object as an argument');
  83.     assert.isFalse(res8, 'passing function as an argument');
  84.   });
  85. });
  86.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement