Skip to content

Commit e5c17a4

Browse files
committed
parameterized test
1 parent 55be598 commit e5c17a4

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

lab3/main_test.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,27 @@ const { Calculator } = require('./main');
44

55
// TODO: write your tests here
66
describe('Calculator', () => {
7+
78
it('should calculate exp correctly', () => {
9+
const testcases = [
10+
[Infinity, 'unsupported operand type'],
11+
[Number.MAX_VALUE, 'overflow'],
12+
[1, Math.exp(1)],
13+
// [2, Math.log(2)],
14+
// [0, 'unsupported operand type'],
15+
// [-1, 'unsupported operand type']
16+
];
817
const calculator = new Calculator();
9-
const infiniteValue = Infinity;
10-
assert.throws(() => calculator.exp(infiniteValue), Error);
11-
assert.throws(() => calculator.exp(Number.MAX_VALUE), Error);
12-
assert.strictEqual(calculator.exp(1), Math.exp(1));
18+
for (const [input, expected] of testcases) {
19+
if (typeof expected === 'string') {
20+
assert.throws(() => calculator.exp(input), Error);
21+
} else {
22+
assert.strictEqual(calculator.exp(input), expected);
23+
}
24+
}
25+
// assert.throws(() => calculator.exp(infiniteValue), Error);
26+
// assert.throws(() => calculator.exp(Number.MAX_VALUE), Error);
27+
// assert.strictEqual(calculator.exp(1), Math.exp(1));
1328
});
1429

1530
it('should calculate log correctly', () => {

0 commit comments

Comments
 (0)