Skip to content

Commit 665b523

Browse files
authored
Update main_test.js
1 parent fcf7db7 commit 665b523

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

lab3/main_test.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,46 @@ 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+
describe('exp', () => {
7+
it('should return the exponential value of a number', () => {
8+
const calculator = new Calculator();
9+
assert.strictEqual(calculator.exp(0), 1);
10+
assert.strictEqual(calculator.exp(1), Math.exp(1));
11+
assert.strictEqual(calculator.exp(2), Math.exp(2));
12+
});
13+
14+
it('should throw error for unsupported operand type', () => {
15+
const calculator = new Calculator();
16+
assert.throws(() => calculator.exp('abc'), Error);
17+
assert.throws(() => calculator.exp(null), Error);
18+
});
19+
20+
it('should throw error for overflow', () => {
21+
const calculator = new Calculator();
22+
assert.throws(() => calculator.exp(1000), Error);
23+
});
24+
});
25+
26+
describe('log', () => {
27+
it('should return the natural logarithm of a number', () => {
28+
const calculator = new Calculator();
29+
assert.strictEqual(calculator.log(1), 0);
30+
assert.strictEqual(calculator.log(Math.exp(1)), 1);
31+
assert.strictEqual(calculator.log(10), Math.log(10));
32+
});
33+
34+
it('should throw error for unsupported operand type', () => {
35+
const calculator = new Calculator();
36+
assert.throws(() => calculator.log('abc'), Error);
37+
assert.throws(() => calculator.log(null), Error);
38+
assert.throws(() => calculator.log(-1), Error);
39+
});
40+
41+
it('should throw error for math domain errors', () => {
42+
const calculator = new Calculator();
43+
assert.throws(() => calculator.log(0), Error);
44+
assert.throws(() => calculator.log(-100), Error);
45+
});
46+
});
47+
});

0 commit comments

Comments
 (0)