|
1 |
| -const { describe, it } = require('node:test'); |
2 |
| -const assert = require('assert'); |
3 | 1 | const { Calculator } = require('./main');
|
| 2 | +const Jasmine = require('jasmine'); |
| 3 | +const jasmine = new Jasmine(); |
| 4 | + |
| 5 | +describe('Calculator', () => { |
| 6 | + let calculator; |
| 7 | + |
| 8 | + beforeEach(() => { |
| 9 | + calculator = new Calculator(); |
| 10 | + }); |
| 11 | + |
| 12 | + describe('exp function', () => { |
| 13 | + it('should correctly calculate the exponential of valid numbers', () => { |
| 14 | + expect(calculator.exp(1)).toBeCloseTo(Math.exp(1)); |
| 15 | + expect(calculator.exp(0)).toBeCloseTo(1); |
| 16 | + expect(calculator.exp(-1)).toBeCloseTo(Math.exp(-1)); |
| 17 | + }); |
| 18 | + |
| 19 | + it('should throw an error for non-finite inputs', () => { |
| 20 | + expect(() => calculator.exp(Infinity)).toThrowError('unsupported operand type'); |
| 21 | + expect(() => calculator.exp(-Infinity)).toThrowError('unsupported operand type'); |
| 22 | + expect(() => calculator.exp(NaN)).toThrowError('unsupported operand type'); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should throw an overflow error for large inputs', () => { |
| 26 | + expect(() => calculator.exp(1000)).toThrowError('overflow'); |
| 27 | + }); |
| 28 | + }); |
| 29 | + |
| 30 | + describe('log function', () => { |
| 31 | + it('should correctly calculate the logarithm of valid numbers', () => { |
| 32 | + expect(calculator.log(1)).toBeCloseTo(Math.log(1)); |
| 33 | + expect(calculator.log(Math.E)).toBeCloseTo(1); |
| 34 | + expect(calculator.log(10)).toBeCloseTo(Math.log(10)); |
| 35 | + }); |
| 36 | + |
| 37 | + it('should throw an error for non-finite inputs', () => { |
| 38 | + expect(() => calculator.log(Infinity)).toThrowError('unsupported operand type'); |
| 39 | + expect(() => calculator.log(-Infinity)).toThrowError('unsupported operand type'); |
| 40 | + expect(() => calculator.log(NaN)).toThrowError('unsupported operand type'); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should throw a math domain error for invalid domain inputs', () => { |
| 44 | + expect(() => calculator.log(-1)).toThrowError('math domain error (2)'); |
| 45 | + expect(() => calculator.log(0)).toThrowError('math domain error (1)'); |
| 46 | + }); |
| 47 | + }); |
| 48 | +}); |
| 49 | + |
| 50 | +jasmine.execute(); |
4 | 51 |
|
5 |
| -// TODO: write your tests here |
|
0 commit comments