Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- describe('Test if function returns char from passed parameter string at passed parameter index', () => {
- describe('Test if passed parameters are invalid', () => {
- it("Should return 'undefined' if first parameter is array", () => {
- expect(lookupChar([1, 2, 3], 1)).to.be.undefined;
- });
- it("Should return 'undefined' if first parameter is object", () => {
- expect(lookupChar({ test: 'test' }, 1)).to.be.undefined;
- });
- it("Should return 'undefined' if first parameter is number", () => {
- expect(lookupChar(123, 1)).to.be.undefined;
- });
- it("Should return 'undefined' if second parameter is array", () => {
- expect(lookupChar('bunny', [1, 2, 3])).to.be.undefined;
- });
- it("Should return 'undefined' if second parameter is object", () => {
- expect(lookupChar('bunny', { test: 'test' })).to.be.undefined;
- });
- it("Should return 'undefined' if second parameter is string", () => {
- expect(lookupChar('bunny', 'fox')).to.be.undefined;
- });
- it("Should return 'undefined' if second parameter is string", () => {
- expect(lookupChar('bunny', '3')).to.be.undefined;
- });
- it("Should return 'undefined' if both parameters are invalid", () => {
- expect(lookupChar([1, 2, 3], '3')).to.be.undefined;
- });
- it("Should return 'undefined' if second parameter is floating point number", () => {
- expect(lookupChar('bunny', 3.3)).to.be.undefined;
- });
- });
- describe('Test if both parameters are valid but the value of the second parameter is out of the range of the first parameter length', () => {
- it("Should return 'Incorrect index' if index = 10 and string length = 5", () => {
- expect(lookupChar('bunny', 10)).to.equal('Incorrect index');
- });
- it("Should return 'Incorrect index' if index = -10 and string length = 5", () => {
- expect(lookupChar('bunny', -10)).to.equal('Incorrect index');
- });
- it("Should return 'Incorrect index' if index = 5 and string length = 5", () => {
- expect(lookupChar('bunny', 5)).to.equal('Incorrect index');
- });
- it("Should return 'Incorrect index' if index = 0 and string is empty", () => {
- expect(lookupChar('', 0)).to.equal('Incorrect index');
- });
- });
- describe('Test if function returns char equal to the char at position index in the passed string', () => {
- it("Should return 'b' if index = 0 and string = 'bunny'", () => {
- expect(lookupChar('bunny', 0)).to.equal('b');
- });
- it("Should return 'y' if index = 0 and string = 'bunny'", () => {
- expect(lookupChar('bunny', 4)).to.equal('y');
- });
- it("Should return 'n' if index = 2 and string = 'bunny'", () => {
- expect(lookupChar('bunny', 2)).to.equal('n');
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement