Advertisement
MariaIvanovaMihova

07. Add / Subtract

Oct 6th, 2022
740
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { expect } = require("chai");
  2.  
  3. const { createCalculator } = require("./addSubtract");
  4. const mainFunc = createCalculator();
  5.  
  6. describe("addSubtract", () => {
  7.   it("inner sum value is not acsecable outside the mainFunction", () => {
  8.     expect(mainFunc.value).to.be.undefined;
  9.   });
  10.   it("inner function getreturns", () => {
  11.     expect(mainFunc.get()).to.equal(0);
  12.   });
  13.   it("inner function add works with intigers", () => {
  14.     mainFunc.add(1);
  15.     expect(mainFunc.get()).to.equal(1);
  16.     mainFunc.add(1);
  17.     expect(mainFunc.get()).to.equal(2);
  18.   });
  19.   it("inner function subtract works with intigers", () => {
  20.     mainFunc.subtract(1);
  21.     expect(mainFunc.get()).to.equal(1);
  22.     mainFunc.subtract(1);
  23.     expect(mainFunc.get()).to.equal(0);
  24.   });
  25.   it("inner function add works with strings containing numbers", () => {
  26.     mainFunc.add("1");
  27.     expect(mainFunc.get()).to.equal(1);
  28.     mainFunc.add("1");
  29.     expect(mainFunc.get()).to.equal(2);
  30.   });
  31.   it("inner function subtract works with strings containing numbers", () => {
  32.     mainFunc.subtract("1");
  33.     expect(mainFunc.get()).to.equal(1);
  34.     mainFunc.subtract("1");
  35.     expect(mainFunc.get()).to.equal(0);
  36.   });
  37.   it("inner function add works with floating point numbers", () => {
  38.     mainFunc.add(1.1);
  39.     expect(mainFunc.get()).to.equal(1.1);
  40.   });
  41.   it("inner function subtract works with floating point numbers", () => {
  42.     mainFunc.subtract(1.1);
  43.     expect(mainFunc.get()).to.equal(0);
  44.   });
  45.   it("inner function add works with negative numbers", () => {
  46.     mainFunc.add(-1);
  47.     expect(mainFunc.get()).to.equal(-1);
  48.     mainFunc.add(-1);
  49.     expect(mainFunc.get()).to.equal(-2);
  50.   });
  51.   it("inner function subtract works with negative numbers", () => {
  52.     mainFunc.subtract(-2);
  53.     expect(mainFunc.get()).to.equal(0);
  54.   });
  55.   it("inner functions add and subtract return undefined if no argument", () => {
  56.     expect(mainFunc.add()).to.be.undefined;
  57.     expect(mainFunc.subtract()).to.be.undefined;
  58.   });
  59.  
  60.   it("inner functions add and subtrack return undefined if argument not a number", () => {
  61.     expect(mainFunc.add("a")).to.be.undefined;
  62.     expect(mainFunc.subtract("b")).to.be.undefined;
  63.   });
  64.   it("inner function get return NaN if add and subtract called with no arg or args are not in type", () => {
  65.     mainFunc.add("a");
  66.     mainFunc.subtract();
  67.     expect(mainFunc.get()).to.be.NaN;
  68.   });
  69. });
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement