From 8ee5add81fb20fd593880fc4cd96843b1a2028b5 Mon Sep 17 00:00:00 2001 From: Kornel Filep Date: Tue, 11 Aug 2020 20:41:15 +0200 Subject: [PATCH] added module-2 solution --- module-2/test/calc.spec.js | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/module-2/test/calc.spec.js b/module-2/test/calc.spec.js index c6fc7c7..d9de954 100644 --- a/module-2/test/calc.spec.js +++ b/module-2/test/calc.spec.js @@ -16,6 +16,37 @@ describe.only('calc', () => { * .minus(3) * .times(6).v // 24 */ - // TODO: write test cases to test calculator - + describe('v', () => { + it('should return positive value when positive number', () => expect(calc(3).v).equal(3)) + it('should return negative value when negative number', () => expect(calc(-3).v).equal(-3)) + }) + describe('add', () => { + it('should return 8 when adding 3 and 5', () => expect(calc(3).add(5).v).equal(8)) + it('should return -2 when adding 3 and -5', () => expect(calc(3).add(-5).v).equal(-2)) + it('should return -8 when adding -3 and -5', () => expect(calc(-3).add(-5).v).equal(-8)) + }) + describe('minus', () => { + it('should return 1 when subtracting 3 and 2', () => expect(calc(3).minus(2).v).equal(1)) + it('should return 5 when subtracting 3 and -2', () => expect(calc(3).minus(-2).v).equal(5)) + it('should return -1 when subtracting -3 and -2', () => expect(calc(-3).minus(-2).v).equal(-1)) + }) + describe('sqrt', () => { + it('should preform sqrt', () => expect(calc(4).sqrt().v).equal(2)) + it('should throw error for negative squared root', () => expect(() => calc(-3).sqrt()).throw('Square root of negative value cannot be determined!')) + }) + describe('times', () => { + it('should return 30 when multiplying 3 and 10', () => expect(calc(3).times(10).v).equal(30)) + it('should return -30 when multiplying 3 and -10', () => expect(calc(3).times(-10).v).equal(-30)) + it('should return 30 when multiplying -3 and -10', () => expect(calc(-3).times(-10).v).equal(30)) + }) + describe('divide', () => { + it('should return 5 when dividing 10 and 2', () => expect(calc(10).divide(2).v).equal(5)) + it('should return -5 when dividing 10 and -2', () => expect(calc(10).divide(-2).v).equal(-5)) + it('should return 5 when dividing -10 and -2', () => expect(calc(-10).divide(-2).v).equal(5)) + it('should throw error when dividing by zero', () => expect(() => calc(5).divide(0)).throw('Division by 0 is not possible!')) + }) + describe('modulo', () => { + it('should return the remainder', () => expect(calc(10).modulo(5).v).equal(0)) + }) + it('should perform chained operations', () => expect(calc(3).add(4).minus(3).times(6).v).equal(24)) }); \ No newline at end of file