kstoyanov

4.Math Enforcer -unit-

Oct 27th, 2020
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe('Test mathEnforcer with three methods', () => {
  2.   describe('Test if mathEnforcer is of valid type and if has expected methods', () => {
  3.     it('mathEnforcer should be of type object', () => {
  4.       expect(typeof (mathEnforcer)).to.equal('object');
  5.     });
  6.     it('mathEnforcer should have property addFive', () => {
  7.       expect(mathEnforcer.hasOwnProperty('addFive')).to.be.true;
  8.     });
  9.     it('mathEnforcer should have property subtractTen', () => {
  10.       expect(mathEnforcer.hasOwnProperty('subtractTen')).to.be.true;
  11.     });
  12.     it('mathEnforcer should have property sum', () => {
  13.       expect(mathEnforcer.hasOwnProperty('sum')).to.be.true;
  14.     });
  15.   });
  16.   describe("Test method 'addFive'", () => {
  17.     it('Should be of type function', () => {
  18.       expect(typeof (mathEnforcer.addFive)).to.equal('function');
  19.     });
  20.     it('Should return undefined if parameter is array', () => {
  21.       expect(mathEnforcer.addFive([])).to.be.undefined;
  22.     });
  23.     it('Should return undefined if parameter is object', () => {
  24.       expect(mathEnforcer.addFive({ test: 'test' })).to.be.undefined;
  25.     });
  26.     it('Should return undefined if parameter is string', () => {
  27.       expect(mathEnforcer.addFive('5')).to.be.undefined;
  28.     });
  29.     it('Should return number', () => {
  30.       expect(typeof (mathEnforcer.addFive(15))).to.equal('number');
  31.     });
  32.     it('Should work with positive numbers', () => {
  33.       expect(mathEnforcer.addFive(5)).to.equal(10);
  34.     });
  35.     it('Should work with negative numbers', () => {
  36.       expect(mathEnforcer.addFive(-5)).to.equal(0);
  37.     });
  38.     it('Should work with floating point numbers', () => {
  39.       expect(mathEnforcer.addFive(-5.34)).to.be.closeTo(-0.34, 0.0001);
  40.     });
  41.   });
  42.   describe("Test method 'subtractTen'", () => {
  43.     it('Should be of type function', () => {
  44.       expect(typeof (mathEnforcer.subtractTen)).to.equal('function');
  45.     });
  46.     it('Should return undefined if parameter is array', () => {
  47.       expect(mathEnforcer.subtractTen([])).to.be.undefined;
  48.     });
  49.     it('Should return undefined if parameter is object', () => {
  50.       expect(mathEnforcer.subtractTen({ test: 'test' })).to.be.undefined;
  51.     });
  52.     it('Should return undefined if parameter is string', () => {
  53.       expect(mathEnforcer.subtractTen('5')).to.be.undefined;
  54.     });
  55.     it('Should return number', () => {
  56.       expect(typeof (mathEnforcer.subtractTen(15))).to.equal('number');
  57.     });
  58.     it('Should work with positive numbers', () => {
  59.       expect(mathEnforcer.subtractTen(5)).to.equal(-5);
  60.     });
  61.     it('Should work with negative numbers', () => {
  62.       expect(mathEnforcer.subtractTen(-5)).to.equal(-15);
  63.     });
  64.     it('Should work with floating point numbers', () => {
  65.       expect(mathEnforcer.subtractTen(5.34)).to.be.closeTo(-4.66, 0.0001);
  66.     });
  67.   });
  68.   describe("Test method 'sum'", () => {
  69.     it('Should be of type function', () => {
  70.       expect(typeof (mathEnforcer.sum)).to.equal('function');
  71.     });
  72.     it('Should return undefined if the first parameter is array', () => {
  73.       expect(mathEnforcer.sum([], 5)).to.be.undefined;
  74.     });
  75.     it('Should return undefined if the second parameter is array', () => {
  76.       expect(mathEnforcer.sum(5, [])).to.be.undefined;
  77.     });
  78.     it('Should return undefined if the first parameter is object', () => {
  79.       expect(mathEnforcer.sum({ test: 'test' }, 0)).to.be.undefined;
  80.     });
  81.     it('Should return undefined if the second parameter is object', () => {
  82.       expect(mathEnforcer.sum(0, { test: 'test' })).to.be.undefined;
  83.     });
  84.     it('Should return undefined if the first parameter is string', () => {
  85.       expect(mathEnforcer.sum('5', 5)).to.be.undefined;
  86.     });
  87.     it('Should return undefined if the second parameter is string', () => {
  88.       expect(mathEnforcer.sum(5, '5')).to.be.undefined;
  89.     });
  90.     it('Should return number', () => {
  91.       expect(typeof (mathEnforcer.sum(15, 0))).to.equal('number');
  92.     });
  93.     it('Should work with positive numbers', () => {
  94.       expect(mathEnforcer.sum(5, 6)).to.equal(11);
  95.     });
  96.     it('Should work with negative numbers', () => {
  97.       expect(mathEnforcer.sum(-5, -7)).to.equal(-12);
  98.     });
  99.     it('Should work with one positive and one negative number', () => {
  100.       expect(mathEnforcer.sum(5, -7)).to.equal(-2);
  101.     });
  102.     it('Should work with floating point numbers', () => {
  103.       expect(mathEnforcer.sum(5.34, 0.6)).to.be.closeTo(5.94, 0.01);
  104.     });
  105.   });
  106. });
  107.  
Advertisement
Add Comment
Please, Sign In to add comment