Skip to content

Commit 218ebde

Browse files
committed
complete parameterize
1 parent e5c17a4 commit 218ebde

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

lab3/main_test.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ describe('Calculator', () => {
1010
[Infinity, 'unsupported operand type'],
1111
[Number.MAX_VALUE, 'overflow'],
1212
[1, Math.exp(1)],
13-
// [2, Math.log(2)],
14-
// [0, 'unsupported operand type'],
15-
// [-1, 'unsupported operand type']
13+
[0, Math.exp(0)],
14+
[-1, Math.exp(-1)]
1615
];
1716
const calculator = new Calculator();
1817
for (const [input, expected] of testcases) {
@@ -22,17 +21,24 @@ describe('Calculator', () => {
2221
assert.strictEqual(calculator.exp(input), expected);
2322
}
2423
}
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));
2824
});
2925

3026
it('should calculate log correctly', () => {
27+
const testcases = [
28+
[Infinity, 'unsupported operand type'],
29+
[0, 'unsupported operand type'],
30+
[-1, 'unsupported operand type'],
31+
[1, Math.log(1)],
32+
[100, Math.log(100)],
33+
[Math.E, Math.log(Math.E)]
34+
];
3135
const calculator = new Calculator();
32-
const infiniteValue = Infinity;
33-
assert.throws(() => calculator.log(infiniteValue), Error);
34-
assert.strictEqual(calculator.log(2), Math.log(2));
35-
assert.throws(() => calculator.log(0), Error);
36-
assert.throws(() => calculator.log(-1), Error);
36+
for (const [input, expected] of testcases) {
37+
if (typeof expected === 'string') {
38+
assert.throws(() => calculator.log(input), Error);
39+
} else {
40+
assert.strictEqual(calculator.log(input), expected);
41+
}
42+
}
3743
});
3844
});

0 commit comments

Comments
 (0)