Advertisement
kstoyanov

3.Char Lookup-unit

Oct 27th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe('Test if function returns char from passed parameter string at passed parameter index', () => {
  2.     describe('Test if passed parameters are invalid', () => {
  3.         it("Should return 'undefined' if first parameter is array", () => {
  4.             expect(lookupChar([1, 2, 3], 1)).to.be.undefined;
  5.         });
  6.         it("Should return 'undefined' if first parameter is object", () => {
  7.             expect(lookupChar({ test: 'test' }, 1)).to.be.undefined;
  8.         });
  9.         it("Should return 'undefined' if first parameter is number", () => {
  10.             expect(lookupChar(123, 1)).to.be.undefined;
  11.         });
  12.         it("Should return 'undefined' if second parameter is array", () => {
  13.             expect(lookupChar('bunny', [1, 2, 3])).to.be.undefined;
  14.         });
  15.         it("Should return 'undefined' if second parameter is object", () => {
  16.             expect(lookupChar('bunny', { test: 'test' })).to.be.undefined;
  17.         });
  18.         it("Should return 'undefined' if second parameter is string", () => {
  19.             expect(lookupChar('bunny', 'fox')).to.be.undefined;
  20.         });
  21.         it("Should return 'undefined' if second parameter is string", () => {
  22.             expect(lookupChar('bunny', '3')).to.be.undefined;
  23.         });
  24.         it("Should return 'undefined' if both parameters are invalid", () => {
  25.             expect(lookupChar([1, 2, 3], '3')).to.be.undefined;
  26.         });
  27.         it("Should return 'undefined' if second parameter is floating point number", () => {
  28.             expect(lookupChar('bunny', 3.3)).to.be.undefined;
  29.         });
  30.     });
  31.     describe('Test if both parameters are valid but the value of the second parameter is out of the range of the first parameter length', () => {
  32.         it("Should return 'Incorrect index' if index = 10 and string length = 5", () => {
  33.             expect(lookupChar('bunny', 10)).to.equal('Incorrect index');
  34.         });
  35.         it("Should return 'Incorrect index' if index = -10 and string length = 5", () => {
  36.             expect(lookupChar('bunny', -10)).to.equal('Incorrect index');
  37.         });
  38.         it("Should return 'Incorrect index' if index = 5 and string length = 5", () => {
  39.             expect(lookupChar('bunny', 5)).to.equal('Incorrect index');
  40.         });
  41.         it("Should return 'Incorrect index' if index = 0 and string is empty", () => {
  42.             expect(lookupChar('', 0)).to.equal('Incorrect index');
  43.         });
  44.     });
  45.     describe('Test if function returns char equal to the char at position index in the passed string', () => {
  46.         it("Should return 'b' if index = 0 and string = 'bunny'", () => {
  47.             expect(lookupChar('bunny', 0)).to.equal('b');
  48.         });
  49.         it("Should return 'y' if index = 0 and string = 'bunny'", () => {
  50.             expect(lookupChar('bunny', 4)).to.equal('y');
  51.         });
  52.         it("Should return 'n' if index = 2 and string = 'bunny'", () => {
  53.             expect(lookupChar('bunny', 2)).to.equal('n');
  54.         });
  55.     });
  56. });
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement