Skip to content

Commit d44a17c

Browse files
authored
Update main_test.js
1 parent 4dd47b4 commit d44a17c

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

lab3/main_test.js

+30-18
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ const assert = require('assert');
33
const { Calculator } = require('./main');
44

55
describe('Calculator', () => {
6-
const calculator = new Calculator();
7-
8-
describe('exp function', () => {
9-
it('calculates the exponential of a number', async () => {
6+
describe('exp', () => {
7+
it('should calculate the exponential function correctly', () => {
8+
const calculator = new Calculator();
9+
assert.strictEqual(calculator.exp(0), 1);
1010
assert.strictEqual(calculator.exp(1), Math.exp(1));
11+
assert.strictEqual(calculator.exp(2), Math.exp(2));
1112
});
1213

13-
it('throws error on non-finite input', async () => {
14-
assert.throws(() => calculator.exp('a'), {
14+
it('should throw an error for unsupported operand type', () => {
15+
const calculator = new Calculator();
16+
assert.throws(() => calculator.exp(NaN), {
1517
name: 'Error',
1618
message: 'unsupported operand type'
1719
});
@@ -21,38 +23,48 @@ describe('Calculator', () => {
2123
});
2224
});
2325

24-
it('handles overflow', async () => {
26+
it('should throw an error for overflow', () => {
27+
const calculator = new Calculator();
2528
assert.throws(() => calculator.exp(1000), {
2629
name: 'Error',
2730
message: 'overflow'
2831
});
2932
});
3033
});
3134

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+
describe('log', () => {
36+
37+
it('should calculate the natural logarithm correctly', () => {
38+
const calculator = new Calculator();
39+
assert.strictEqual(calculator.log(1), 0);
40+
assert.strictEqual(calculator.log(Math.E), 1);
3541
});
3642

37-
it('throws error on non-finite input', async () => {
38-
assert.throws(() => calculator.log('a'), {
43+
it('should throw an error for unsupported operand type', () => {
44+
const calculator = new Calculator();
45+
assert.throws(() => calculator.log(NaN), {
3946
name: 'Error',
4047
message: 'unsupported operand type'
4148
});
42-
assert.throws(() => calculator.log(-1), {
49+
assert.throws(() => calculator.log(Infinity), {
4350
name: 'Error',
44-
message: 'math domain error (1)'
51+
message: 'unsupported operand type'
4552
});
4653
});
4754

48-
it('handles domain errors', async () => {
55+
it('should throw an error for math domain error (1)', () => {
56+
const calculator = new Calculator();
4957
assert.throws(() => calculator.log(0), {
5058
name: 'Error',
51-
message: 'math domain error (2)'
59+
message: 'math domain error (1)'
5260
});
53-
assert.throws(() => calculator.log(null), {
61+
});
62+
63+
it('should throw an error for math domain error (2)', () => {
64+
const calculator = new Calculator();
65+
assert.throws(() => calculator.log(-1), {
5466
name: 'Error',
55-
message: 'unsupported operand type'
67+
message: 'math domain error (2)'
5668
});
5769
});
5870
});

0 commit comments

Comments
 (0)