Skip to content

Commit cb96912

Browse files
NienTzuNienTzu
authored andcommitted
Submit Lab3
1 parent daf7c20 commit cb96912

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('Parameterization', () => {
7+
it('exp', () => {
8+
const testcases = [
9+
{param: 0, expected: 1},
10+
{param: 1, expected: 2.718281828459045},
11+
{param: -1, expected: 0.36787944117144233},
12+
{param: 5, expected: 148.4131591025766},
13+
{param: 10, expected: 22026.465794806718}
14+
];
15+
const calculator = new Calculator();
16+
for (const tc of testcases) {
17+
assert.strictEqual(calculator.exp(tc.param), tc.expected);
18+
}
19+
});
20+
it('log', () => {
21+
const testcases = [
22+
{param: 1, expected: 0},
23+
{param: 10, expected: 2.302585092994046},
24+
{param: 8, expected: 2.0794415416798357},
25+
{param: 90, expected: 4.499809670330265},
26+
{param: Math.E, expected: 1}
27+
];
28+
const calculator = new Calculator();
29+
for (const tc of testcases) {
30+
assert.strictEqual(calculator.log(tc.param), tc.expected);
31+
}
32+
});
33+
})
34+
35+
var infinite_number = 1 / 0;
36+
var calculator = new Calculator();
37+
38+
describe('Errors', () => {
39+
it('exp infinite number', () => {
40+
assert.throws(function () {calculator.exp(infinite_number)});
41+
});
42+
it('exp overflow', () => {
43+
cause = 999999999;
44+
assert.throws(function() {calculator.exp(cause)});
45+
});
46+
it('log infinite number', () => {
47+
assert.throws(function() {calculator.log(infinite_number)});
48+
});
49+
it('log math domain error (1)', () => {
50+
assert.throws(function() {calculator.log(0)});
51+
})
52+
it('log math domain error (2)', () => {
53+
assert.throws(function() {calculator.log(-234)})
54+
})
55+
})

0 commit comments

Comments
 (0)