Skip to content

Commit 29ddeb4

Browse files
committed
lab3 complete
1 parent c5d1744 commit 29ddeb4

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

lab3/main_test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,53 @@ const assert = require('assert');
33
const { Calculator } = require('./main');
44

55
// TODO: write your tests here
6+
describe('test exp',() => {
7+
const cal = new Calculator
8+
it('test error-exp', () => {
9+
const testcase = [
10+
{param : "string", expected : "unsupported operand type"},
11+
{param : NaN, expected : "unsupported operand type"} ,
12+
{param : 1000, expected : "overflow"},
13+
]
14+
15+
for (const tc of testcase){
16+
assert.throws(() => {cal.exp(tc.param)}, {message : tc.expected});
17+
}
18+
});
19+
it('test normal-exp',() => {
20+
const testcase = [
21+
{param : 3, expected : Math.exp(3)},
22+
{param : 100, expected : Math.exp(100)},
23+
{param : 125, expected : Math.exp(125)}
24+
]
25+
26+
for (const tc of testcase){
27+
assert.strictEqual(cal.exp(tc.param), tc.expected)
28+
}
29+
})
30+
});
31+
describe('test log',() => {
32+
const cal = new Calculator
33+
it('test error-log', () => {
34+
const testcase = [
35+
{param : "string", expected : "unsupported operand type"},
36+
{param : 0, expected : "math domain error (1)"},
37+
{param : -1, expected : "math domain error (2)"},
38+
]
39+
40+
for (const tc of testcase){
41+
assert.throws(() => {cal.log(tc.param)}, {message : tc.expected});
42+
}
43+
});
44+
it('test normal-log',() => {
45+
const testcase = [
46+
{param : 12, expected : Math.log(12)},
47+
{param : 36, expected : Math.log(36)},
48+
{param : 64, expected : Math.log(64)}
49+
]
50+
51+
for (const tc of testcase){
52+
assert.strictEqual(cal.log(tc.param), tc.expected)
53+
}
54+
})
55+
});

0 commit comments

Comments
 (0)