Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- describe('Test mathEnforcer with three methods', () => {
- describe('Test if mathEnforcer is of valid type and if has expected methods', () => {
- it('mathEnforcer should be of type object', () => {
- expect(typeof (mathEnforcer)).to.equal('object');
- });
- it('mathEnforcer should have property addFive', () => {
- expect(mathEnforcer.hasOwnProperty('addFive')).to.be.true;
- });
- it('mathEnforcer should have property subtractTen', () => {
- expect(mathEnforcer.hasOwnProperty('subtractTen')).to.be.true;
- });
- it('mathEnforcer should have property sum', () => {
- expect(mathEnforcer.hasOwnProperty('sum')).to.be.true;
- });
- });
- describe("Test method 'addFive'", () => {
- it('Should be of type function', () => {
- expect(typeof (mathEnforcer.addFive)).to.equal('function');
- });
- it('Should return undefined if parameter is array', () => {
- expect(mathEnforcer.addFive([])).to.be.undefined;
- });
- it('Should return undefined if parameter is object', () => {
- expect(mathEnforcer.addFive({ test: 'test' })).to.be.undefined;
- });
- it('Should return undefined if parameter is string', () => {
- expect(mathEnforcer.addFive('5')).to.be.undefined;
- });
- it('Should return number', () => {
- expect(typeof (mathEnforcer.addFive(15))).to.equal('number');
- });
- it('Should work with positive numbers', () => {
- expect(mathEnforcer.addFive(5)).to.equal(10);
- });
- it('Should work with negative numbers', () => {
- expect(mathEnforcer.addFive(-5)).to.equal(0);
- });
- it('Should work with floating point numbers', () => {
- expect(mathEnforcer.addFive(-5.34)).to.be.closeTo(-0.34, 0.0001);
- });
- });
- describe("Test method 'subtractTen'", () => {
- it('Should be of type function', () => {
- expect(typeof (mathEnforcer.subtractTen)).to.equal('function');
- });
- it('Should return undefined if parameter is array', () => {
- expect(mathEnforcer.subtractTen([])).to.be.undefined;
- });
- it('Should return undefined if parameter is object', () => {
- expect(mathEnforcer.subtractTen({ test: 'test' })).to.be.undefined;
- });
- it('Should return undefined if parameter is string', () => {
- expect(mathEnforcer.subtractTen('5')).to.be.undefined;
- });
- it('Should return number', () => {
- expect(typeof (mathEnforcer.subtractTen(15))).to.equal('number');
- });
- it('Should work with positive numbers', () => {
- expect(mathEnforcer.subtractTen(5)).to.equal(-5);
- });
- it('Should work with negative numbers', () => {
- expect(mathEnforcer.subtractTen(-5)).to.equal(-15);
- });
- it('Should work with floating point numbers', () => {
- expect(mathEnforcer.subtractTen(5.34)).to.be.closeTo(-4.66, 0.0001);
- });
- });
- describe("Test method 'sum'", () => {
- it('Should be of type function', () => {
- expect(typeof (mathEnforcer.sum)).to.equal('function');
- });
- it('Should return undefined if the first parameter is array', () => {
- expect(mathEnforcer.sum([], 5)).to.be.undefined;
- });
- it('Should return undefined if the second parameter is array', () => {
- expect(mathEnforcer.sum(5, [])).to.be.undefined;
- });
- it('Should return undefined if the first parameter is object', () => {
- expect(mathEnforcer.sum({ test: 'test' }, 0)).to.be.undefined;
- });
- it('Should return undefined if the second parameter is object', () => {
- expect(mathEnforcer.sum(0, { test: 'test' })).to.be.undefined;
- });
- it('Should return undefined if the first parameter is string', () => {
- expect(mathEnforcer.sum('5', 5)).to.be.undefined;
- });
- it('Should return undefined if the second parameter is string', () => {
- expect(mathEnforcer.sum(5, '5')).to.be.undefined;
- });
- it('Should return number', () => {
- expect(typeof (mathEnforcer.sum(15, 0))).to.equal('number');
- });
- it('Should work with positive numbers', () => {
- expect(mathEnforcer.sum(5, 6)).to.equal(11);
- });
- it('Should work with negative numbers', () => {
- expect(mathEnforcer.sum(-5, -7)).to.equal(-12);
- });
- it('Should work with one positive and one negative number', () => {
- expect(mathEnforcer.sum(5, -7)).to.equal(-2);
- });
- it('Should work with floating point numbers', () => {
- expect(mathEnforcer.sum(5.34, 0.6)).to.be.closeTo(5.94, 0.01);
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment