|
1 | | -const {describe, it} = require('node:test'); |
| 1 | +const { describe, it } = require('node:test'); |
2 | 2 | const assert = require('assert'); |
3 | 3 | const { Calculator } = require('./main'); |
4 | 4 |
|
5 | | -// TODO: write your tests here |
| 5 | +describe('Calculator', () => { |
| 6 | + const calculator = new Calculator(); |
| 7 | + |
| 8 | + describe('exp()', () => { |
| 9 | + it('should return correct exponentiation results', () => { |
| 10 | + assert.strictEqual(calculator.exp(0), 1); |
| 11 | + assert.strictEqual(calculator.exp(1), Math.exp(1)); |
| 12 | + assert.strictEqual(calculator.exp(-1), Math.exp(-1)); |
| 13 | + assert.strictEqual(calculator.exp(5), Math.exp(5)); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should throw an error for non-finite numbers', () => { |
| 17 | + assert.throws(() => calculator.exp(Infinity), /unsupported operand type/); |
| 18 | + assert.throws(() => calculator.exp(-Infinity), /unsupported operand type/); |
| 19 | + assert.throws(() => calculator.exp(NaN), /unsupported operand type/); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should throw an overflow error for large numbers', () => { |
| 23 | + assert.throws(() => calculator.exp(1000), /overflow/); |
| 24 | + }); |
| 25 | + }); |
| 26 | +}); |
0 commit comments