Skip to content

Commit caff565

Browse files
committed
lab3
1 parent 3a2d694 commit caff565

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

lab3/main_test.js

+42-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,46 @@
11
const {describe, it} = require('node:test');
22
const assert = require('assert');
33
const { Calculator } = require('./main');
4-
4+
const test = require('node:test');
55
// TODO: write your tests here
6+
// const { test, describe } = require('node:test');
7+
// const assert = require('assert');
8+
// const { Calculator } = require('./main');
9+
10+
describe('Calculator', () => {
11+
const calculator = new Calculator();
12+
13+
test('return Math.exp(x) ', () => {
14+
assert.ok(Math.abs(calculator.exp(1) - Math.exp(1)) < 1e-10);
15+
assert.ok(Math.abs(calculator.exp(0) - 1) < 1e-10);
16+
});
17+
18+
test('exp() throw "unsupported operand type" for non-finite x', () => {
19+
assert.throws(() => calculator.exp(Infinity), /unsupported operand type/);
20+
assert.throws(() => calculator.exp(-Infinity), /unsupported operand type/);
21+
assert.throws(() => calculator.exp(NaN), /unsupported operand type/);
22+
});
23+
24+
test('exp() throw "overflow" for large x resulting Infinity', () => {
25+
assert.throws(() => calculator.exp(10000), /overflow/);
26+
});
27+
28+
test('log() return Math.log(x) ', () => {
29+
assert.ok(Math.abs(calculator.log(1) - 0) < 1e-10);
30+
assert.ok(Math.abs(calculator.log(Math.E) - 1) < 1e-10);
31+
});
32+
33+
test('log() throw "unsupported operand type" for non-finite x', () => {
34+
assert.throws(() => calculator.log(Infinity), /unsupported operand type/);
35+
assert.throws(() => calculator.log(-Infinity), /unsupported operand type/);
36+
assert.throws(() => calculator.log(NaN), /unsupported operand type/);
37+
});
38+
39+
test('log() throw "math domain error (1)" when x = 0', () => {
40+
assert.throws(() => calculator.log(0), /math domain error \(1\)/);
41+
});
42+
43+
test('log() throw "math domain error (2)" when x < 0', () => {
44+
assert.throws(() => calculator.log(-1), /math domain error \(2\)/);
45+
});
46+
});

0 commit comments

Comments
 (0)