Skip to content

Commit edcb4b1

Browse files
committed
feat: lab3 ok
1 parent fab83cd commit edcb4b1

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

lab3/main_test.js

+47-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,50 @@ 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 calc = new Calculator();
7+
8+
// ---- exp(x) tests ----
9+
it('exp(0) should return 1', () => {
10+
assert.strictEqual(calc.exp(0), 1);
11+
});
12+
13+
it('exp(1) should return ~2.718', () => {
14+
assert.ok(Math.abs(calc.exp(1) - Math.E) < 1e-10);
15+
});
16+
17+
it('exp(Infinity) should throw unsupported operand type', () => {
18+
assert.throws(() => calc.exp(Infinity), {
19+
message: 'unsupported operand type'
20+
});
21+
});
22+
23+
it('exp(1000) should throw overflow', () => {
24+
assert.throws(() => calc.exp(1000), {
25+
message: 'overflow'
26+
});
27+
});
28+
29+
// ---- log(x) tests ----
30+
it('log(1) should return 0', () => {
31+
assert.strictEqual(calc.log(1), 0);
32+
});
33+
34+
it('log(0) should throw math domain error (1)', () => {
35+
assert.throws(() => calc.log(0), {
36+
message: 'math domain error (1)'
37+
});
38+
});
39+
40+
it('log(-5) should throw math domain error (2)', () => {
41+
assert.throws(() => calc.log(-5), {
42+
message: 'math domain error (2)'
43+
});
44+
});
45+
46+
it('log(NaN) should throw unsupported operand type', () => {
47+
assert.throws(() => calc.log(NaN), {
48+
message: 'unsupported operand type'
49+
});
50+
});
51+
});

0 commit comments

Comments
 (0)