Skip to content

Commit 1aa3788

Browse files
authored
Merge pull request #2 from scott87730/lab3
[Lab3] 512558012
2 parents df13dc6 + 7940491 commit 1aa3788

File tree

1 file changed

+49
-3
lines changed

1 file changed

+49
-3
lines changed

lab3/main_test.js

+49-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,51 @@
1-
const { describe, it } = require('node:test');
2-
const assert = require('assert');
31
const { Calculator } = require('./main');
2+
const Jasmine = require('jasmine');
3+
const jasmine = new Jasmine();
4+
5+
describe('Calculator', () => {
6+
let calculator;
7+
8+
beforeEach(() => {
9+
calculator = new Calculator();
10+
});
11+
12+
describe('exp function', () => {
13+
it('should correctly calculate the exponential of valid numbers', () => {
14+
expect(calculator.exp(1)).toBeCloseTo(Math.exp(1));
15+
expect(calculator.exp(0)).toBeCloseTo(1);
16+
expect(calculator.exp(-1)).toBeCloseTo(Math.exp(-1));
17+
});
18+
19+
it('should throw an error for non-finite inputs', () => {
20+
expect(() => calculator.exp(Infinity)).toThrowError('unsupported operand type');
21+
expect(() => calculator.exp(-Infinity)).toThrowError('unsupported operand type');
22+
expect(() => calculator.exp(NaN)).toThrowError('unsupported operand type');
23+
});
24+
25+
it('should throw an overflow error for large inputs', () => {
26+
expect(() => calculator.exp(1000)).toThrowError('overflow');
27+
});
28+
});
29+
30+
describe('log function', () => {
31+
it('should correctly calculate the logarithm of valid numbers', () => {
32+
expect(calculator.log(1)).toBeCloseTo(Math.log(1));
33+
expect(calculator.log(Math.E)).toBeCloseTo(1);
34+
expect(calculator.log(10)).toBeCloseTo(Math.log(10));
35+
});
36+
37+
it('should throw an error for non-finite inputs', () => {
38+
expect(() => calculator.log(Infinity)).toThrowError('unsupported operand type');
39+
expect(() => calculator.log(-Infinity)).toThrowError('unsupported operand type');
40+
expect(() => calculator.log(NaN)).toThrowError('unsupported operand type');
41+
});
42+
43+
it('should throw a math domain error for invalid domain inputs', () => {
44+
expect(() => calculator.log(-1)).toThrowError('math domain error (2)');
45+
expect(() => calculator.log(0)).toThrowError('math domain error (1)');
46+
});
47+
});
48+
});
49+
50+
jasmine.execute();
451

5-
// TODO: write your tests here

0 commit comments

Comments
 (0)