Skip to content

Commit aebbb60

Browse files
authored
Merge pull request #258 from skysoul1024/lab3
[LAB3] 313551109
2 parents 9d39867 + 8f2284f commit aebbb60

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

lab3/main_test.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
1-
const {describe, it} = require('node:test');
1+
const { describe, it } = require('node:test');
22
const assert = require('assert');
33
const { Calculator } = require('./main');
44

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

Comments
 (0)