Advertisement
Todorov_Stanimir

04. Math Enforcer Exercise: Unit Testing and Modules

Oct 19th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe("mathEnforcer", () => {
  2.  
  3.     describe("addFive", function () {
  4.         it("should return undefined if the parameter is not a number", () => {
  5.             let expected = mathEnforcer.addFive(!Number)
  6.             expect(expected).to.be.undefined
  7.         });
  8.  
  9.         it("should work correct => add 5 and return result, if the parameter is a number", () => {
  10.             let expected = mathEnforcer.addFive(6)
  11.             expect(expected).equal(11)
  12.         });
  13.  
  14.         it("should work correct => add 5 and return result, if the parameter is a less then zerro", () => {
  15.             let expected = mathEnforcer.addFive(-6)
  16.             expect(expected).equal(-1)
  17.         });
  18.  
  19.         it("should be considered correct if it is within 0.01 of the correct value => add 5 and return result, if the parameter is a floating point", () => {
  20.             let expected = mathEnforcer.addFive(6.11)
  21.             expect(expected).to.be.closeTo(11.11, 0.01)
  22.         });
  23.     })
  24.  
  25.     describe("subtractTen", function () {
  26.         it("should return undefined if the parameter of function subtractTen is not a number", () => {
  27.             let expected = mathEnforcer.subtractTen(!Number)
  28.             expect(expected).to.be.undefined
  29.         });
  30.  
  31.         it("shouldwork correct => subtract 10 and return result, if the parameter is a number", () => {
  32.             let expected = mathEnforcer.subtractTen(11)
  33.             expect(expected).equal(1)
  34.         });
  35.  
  36.         it("should work correct => subtract 10 and return result, if the parameter is a less then zerro", () => {
  37.             let expected = mathEnforcer.subtractTen(-10)
  38.             expect(expected).equal(-20)
  39.         });
  40.  
  41.         it("should be considered correct if it is within 0.01 of the correct value => subtract 10 and return result, if the parameter is a floating point", () => {
  42.             let expected = mathEnforcer.subtractTen(6.01)
  43.             expect(expected).to.be.closeTo(-3.99, 0.01)
  44.         });
  45.     })
  46.  
  47.     describe("sum", function () {
  48.         it("sum(par1, par2) return undefined, if par1 is a not a number", () => {
  49.             let expected = mathEnforcer.sum('11', 11)
  50.             expect(expected).to.be.undefined
  51.         });
  52.  
  53.         it("sum(par1, par2) return undefined, if par2 is a not a number", () => {
  54.             let expected = mathEnforcer.sum(11, '11')
  55.             expect(expected).to.be.undefined
  56.         });
  57.  
  58.         it("sum(par1, par2) return correct result, if par1 and par2 are numbers", () => {
  59.             let expected = mathEnforcer.sum(10, 11)
  60.             expect(expected).equal(21)
  61.         });
  62.  
  63.         it("sum(par1, par2) return correct result, if par1 or par2 are less then zero", () => {
  64.             let expected = mathEnforcer.sum(-10, 11)
  65.             expect(expected).equal(1)
  66.         });
  67.  
  68.         it("sum(par1, par2) return correct result, if par1 or par2 are floating numbers", () => {
  69.             let expected = mathEnforcer.sum(11.1, -9.98)
  70.             expect(expected).to.be.closeTo(1.12, 0.01)
  71.         });
  72.  
  73.         it("checking all methods", () => {
  74.             let expected = mathEnforcer.addFive(11.11)
  75.             expected = mathEnforcer.subtractTen(expected)
  76.             expected = mathEnforcer.sum(expected, 5.13)
  77.             expect(expected).to.be.closeTo(11.24, 0.01)
  78.         });
  79.     })
  80. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement