Skip to content

Commit 27a4b8c

Browse files
authored
Update main_test.js
1 parent b88ef9e commit 27a4b8c

File tree

1 file changed

+56
-1
lines changed

1 file changed

+56
-1
lines changed

lab3/main_test.js

+56-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,59 @@ 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 function', () => {
9+
it('calculates the exponential of a number', async () => {
10+
assert.strictEqual(calculator.exp(1), Math.exp(1));
11+
});
12+
13+
it('throws error on non-finite input', async () => {
14+
assert.throws(() => calculator.exp('a'), {
15+
name: 'Error',
16+
message: 'unsupported operand type'
17+
});
18+
assert.throws(() => calculator.exp(Infinity), {
19+
name: 'Error',
20+
message: 'unsupported operand type'
21+
});
22+
});
23+
24+
it('handles overflow', async () => {
25+
assert.throws(() => calculator.exp(1000), {
26+
name: 'Error',
27+
message: 'overflow'
28+
});
29+
});
30+
});
31+
32+
describe('log function', () => {
33+
it('calculates the logarithm of a number', async () => {
34+
assert.strictEqual(calculator.log(Math.E), Math.log(Math.E));
35+
});
36+
37+
it('throws error on non-finite input', async () => {
38+
assert.throws(() => calculator.log('a'), {
39+
name: 'Error',
40+
message: 'unsupported operand type'
41+
});
42+
assert.throws(() => calculator.log(-1), {
43+
name: 'Error',
44+
message: 'math domain error (1)'
45+
});
46+
});
47+
48+
it('handles domain errors', async () => {
49+
assert.throws(() => calculator.log(0), {
50+
name: 'Error',
51+
message: 'math domain error (1)'
52+
});
53+
assert.throws(() => calculator.log(null), {
54+
name: 'Error',
55+
message: 'unsupported operand type'
56+
});
57+
});
58+
});
59+
});
60+

0 commit comments

Comments
 (0)