Skip to content

Commit a305991

Browse files
authored
Merge pull request #219 from Aniina-ping/lab3
[LAB3] 313551010
2 parents 4b493d5 + 5aea65a commit a305991

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

lab3/main_test.js

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,69 @@ 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+
const calculator = new Calculator();
8+
9+
it('should throw "unsupported operand type" for non-finite numbers', () => {
10+
const invalidInputs = [NaN, Infinity, -Infinity, 'string', null, undefined];
11+
invalidInputs.forEach(input => {
12+
assert.throws(() => calculator.exp(input), Error('unsupported operand type'));
13+
});
14+
});
15+
16+
it('should throw "overflow" for large numbers', () => {
17+
const largeInputs = [1000, 10000, 100000];
18+
largeInputs.forEach(input => {
19+
assert.throws(() => calculator.exp(input), Error('overflow'));
20+
});
21+
});
22+
23+
it('should return correct exp value for valid inputs', () => {
24+
const testCases = [
25+
{ input: 0, expected: 1 },
26+
{ input: 1, expected: Math.exp(1) },
27+
{ input: -1, expected: Math.exp(-1) },
28+
];
29+
testCases.forEach(({ input, expected }) => {
30+
assert.strictEqual(calculator.exp(input), expected);
31+
});
32+
});
33+
});
34+
35+
describe('log', () => {
36+
const calculator = new Calculator();
37+
38+
it('should throw "unsupported operand type" for non-finite numbers', () => {
39+
const invalidInputs = [NaN, Infinity, -Infinity, 'string', null, undefined];
40+
invalidInputs.forEach(input => {
41+
assert.throws(() => calculator.log(input), Error('unsupported operand type'));
42+
});
43+
});
44+
45+
it('should throw "math domain error (1)" for zero', () => {
46+
const invalidInputs = [0];
47+
invalidInputs.forEach(input => {
48+
assert.throws(() => calculator.log(input), Error('math domain error (1)'));
49+
});
50+
});
51+
52+
it('should throw "math domain error (2)" for finite negative numbers', () => {
53+
const invalidInputs = [-1, -5, -100];
54+
invalidInputs.forEach(input => {
55+
assert.throws(() => calculator.log(input), Error('math domain error (2)'));
56+
});
57+
});
58+
59+
it('should return correct log value for valid inputs', () => {
60+
const testCases = [
61+
{ input: 1, expected: 0 },
62+
{ input: Math.E, expected: 1 },
63+
{ input: 10, expected: Math.log(10) },
64+
];
65+
testCases.forEach(({ input, expected }) => {
66+
assert.strictEqual(calculator.log(input), expected);
67+
});
68+
});
69+
});
70+
});

0 commit comments

Comments
 (0)