Advertisement
vvsvvs

Untitled

Oct 4th, 2022
903
0
123 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe('Test lookupChar function', () => {
  2.     it('return undefined', () => {
  3.         let str = 'hello';
  4.         let index = 2;
  5.  
  6.         let expect = undefined;
  7.  
  8.         assert.equal(lookupChar(2, index), expect);
  9.         assert.equal(lookupChar(undefined, index), expect);
  10.         assert.equal(lookupChar(true, index), expect);
  11.         assert.equal(lookupChar([], index), expect);
  12.         assert.equal(lookupChar({ 2: 2 }, index), expect);
  13.         assert.equal(lookupChar(() => 2 + 2, index), expect);
  14.  
  15.         assert.equal(lookupChar(str, undefined), expect);
  16.         assert.equal(lookupChar(str, 4.5), expect);
  17.         assert.equal(lookupChar(str, '2'), expect);
  18.         assert.equal(lookupChar(str, false), expect);
  19.         assert.equal(lookupChar(str, []), expect);
  20.         assert.equal(lookupChar(str, { 'undefined': 4 }), expect);
  21.         assert.equal(lookupChar(str, () => 2 + 2), expect);
  22.     });
  23.  
  24.     it('return message "Incorrect index"', () => {
  25.         let str = '';
  26.         let index = str.length;
  27.  
  28.         let expect = "Incorrect index";
  29.  
  30.         assert.equal(lookupChar(str, index), expect);        
  31.     });
  32.  
  33.     it('incorrect index', () => {
  34.         let str = 'hello';
  35.         let index = str.length;
  36.         let expected = "Incorrect index";
  37.  
  38.         assert.equal(lookupChar(str, index), expected);
  39.  
  40.         index = -1;
  41.  
  42.         assert.equal(lookupChar(str, index), expected);
  43.     });
  44.  
  45.     it('return correct', () => {
  46.  
  47.         let range = Math.random() * 1000;
  48.  
  49.         for (let i = 0; i < range; i++) {
  50.             let wordlength = Math.random() * 100;
  51.             let str = '';
  52.  
  53.             for (let j = 0; j < wordlength; j++) {
  54.                 str += String.fromCharCode(Math.random() * (127 - 32) + 32);
  55.             }
  56.  
  57.             let index = Math.floor(Math.random() * str.length);
  58.             let expectedResult = str.charAt(index);
  59.  
  60.             assert.equal(lookupChar(str, index), expectedResult);
  61.         }
  62.     });
  63. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement