Advertisement
vaakata

04_Add_Subtract_Test_31.10.16

Oct 31st, 2016
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. let createCalculator = require('../04_Add_Subtract_31.10.16').crateCalculator;
  2. let expect = require('chai').expect;
  3.  
  4. let calculator;
  5. beforeEach(function(){
  6.     calculator = createCalculator();;
  7. });
  8.  
  9. describe("Tests for calculator", function() {
  10.  
  11.     //Check for main functions existence
  12.     it("should have get() function", function () {
  13.         let hasProp = calculator.hasOwnProperty('get');
  14.         expect(hasProp).to.be.true;
  15.     });
  16.  
  17.     it("should have subtract() function", function(){
  18.         let hasProp = calculator.hasOwnProperty('subtract');
  19.         expect(hasProp).to.be.true;
  20.     });
  21.  
  22.     it("should have add() function", function(){
  23.         let hasProp = calculator.hasOwnProperty('add');
  24.         expect(hasProp).to.be.true;
  25.     });
  26.  
  27.     it("should return 0 for get", function(){
  28.         let value = calculator.get();
  29.         expect(value).to.be.equal(0);
  30.     })
  31.  
  32.     it('should return 5 on {add "5";}', () => {
  33.         calculator.add("5");
  34.         let value = calculator.get();
  35.         expect(value).to.equal(5);
  36.     });
  37.  
  38.     it("should return -5 after (add(-5))", function(){
  39.         calculator.add(-5);
  40.         let value = calculator.get();
  41.         expect(value).to.be.equal(-5);
  42.     })
  43.  
  44.     it("should return 2 after (add(10); subtract('7'); add('-2'); subtract(-1)", function(){
  45.         calculator.add(10);
  46.         calculator.subtract('7');
  47.         calculator.add(-2);
  48.         calculator.subtract('-1');
  49.         let value = calculator.get();
  50.         expect(value).to.be.equal(2);
  51.     })
  52.  
  53.     it("should return 4.2 after(add(5.3); subtract(1.1))", function(){
  54.         calculator.add(5.3);
  55.         calculator.subtract(1.1);
  56.         let value = calculator.get();
  57.         expect(value).to.be.equal(4.199999999999999);
  58.     })
  59.  
  60.     it("should return NaN after (add('hello))", function(){
  61.         calculator.add("hello");
  62.         let value = calculator.get();
  63.         expect(value).to.be.NaN;
  64.     })
  65.  
  66.     it("should return NaN after (subtract('hello')", function(){
  67.         calculator.subtract('hello');
  68.         let value = calculator.get();
  69.         expect(value).to.be.NaN
  70.     })
  71.  
  72.     it("should return NaN after add empty input", function(){
  73.         calculator.add()
  74.         let value = calculator.get();
  75.         expect(value).to.be.NaN
  76.     })
  77.  
  78.     it("should return NaN after subtract of empty input", function(){
  79.         calculator.subtract()
  80.         let value = calculator.get();
  81.         expect(value).to.be.NaN
  82.     })
  83. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement