|
1 |
| -const { describe, it, beforeEach } = require('node:test'); |
| 1 | +const {describe, it} = require('node:test'); |
2 | 2 | const assert = require('assert');
|
3 | 3 | const { Calculator } = require('./main');
|
4 | 4 |
|
5 |
| -describe('Calculator', () => { |
6 |
| - let calculator; |
7 |
| - beforeEach(() => { |
8 |
| - calculator = new Calculator(); |
9 |
| - }); |
10 |
| - |
11 |
| - describe('exp method', () => { |
12 |
| - it('unsupported operand type', () => { |
13 |
| - const testcases = [ |
14 |
| - { param: [Infinity], expected: 'unsupported operand type' }, |
15 |
| - { param: [-Infinity], expected: 'unsupported operand type' }, |
16 |
| - { param: [NaN], expected: 'unsupported operand type' }, |
17 |
| - ]; |
18 |
| - |
19 |
| - for (const tc of testcases) { |
20 |
| - assert.throws(() => calculator.exp(...tc.param), new RegExp(tc.expected)); |
21 |
| - } |
22 |
| - }); |
23 |
| - |
24 |
| - it('overflow', () => { |
25 |
| - const testcases = [ |
26 |
| - { param: [710], expected: 'overflow' }, |
27 |
| - ]; |
28 |
| - |
29 |
| - for (const tc of testcases) { |
30 |
| - assert.throws(() => calculator.exp(...tc.param), new RegExp(tc.expected)); |
31 |
| - } |
32 |
| - }); |
33 |
| - |
34 |
| - it('normal', () => { |
35 |
| - const testcases = [ |
36 |
| - { param: [0], expected: Math.exp(0) }, |
37 |
| - { param: [1], expected: Math.exp(1) }, |
38 |
| - { param: [2], expected: Math.exp(2) }, |
39 |
| - { param: [-1], expected: Math.exp(-1) }, |
40 |
| - { param: [-2], expected: Math.exp(-2) }, |
41 |
| - ]; |
42 |
| - |
43 |
| - for (const tc of testcases) { |
44 |
| - const result = calculator.exp(...tc.param); |
45 |
| - assert.strictEqual(result, tc.expected); |
46 |
| - } |
47 |
| - }); |
48 |
| - }); |
49 |
| - |
50 |
| - describe('log method', () => { |
51 |
| - it('unsupported operand type', () => { |
52 |
| - const testcases = [ |
53 |
| - { param: [Infinity], expected: 'unsupported operand type' }, |
54 |
| - { param: [-Infinity], expected: 'unsupported operand type' }, |
55 |
| - { param: [NaN], expected: 'unsupported operand type' }, |
56 |
| - ]; |
57 |
| - |
58 |
| - for (const tc of testcases) { |
59 |
| - assert.throws(() => calculator.log(...tc.param), new RegExp(tc.expected)); |
60 |
| - } |
61 |
| - }); |
62 |
| - |
63 |
| - it('math domain error (1)', () => { |
64 |
| - const testcases = [ |
65 |
| - { param: [0], expected: 'math domain error \\(1\\)' }, |
66 |
| - ]; |
67 |
| - |
68 |
| - for (const tc of testcases) { |
69 |
| - assert.throws(() => calculator.log(...tc.param), new RegExp(tc.expected)); |
70 |
| - } |
71 |
| - }); |
72 |
| - |
73 |
| - it('math domain error (2)', () => { |
74 |
| - const testcases = [ |
75 |
| - { param: [-1], expected: 'math domain error \\(2\\)' }, |
76 |
| - { param: [-2], expected: 'math domain error \\(2\\)' }, |
77 |
| - ]; |
78 |
| - |
79 |
| - for (const tc of testcases) { |
80 |
| - assert.throws(() => calculator.log(...tc.param), new RegExp(tc.expected)); |
81 |
| - } |
82 |
| - }); |
83 |
| - |
84 |
| - it('normal', () => { |
85 |
| - const testcases = [ |
86 |
| - { param: [1], expected: Math.log(1) }, |
87 |
| - { param: [2], expected: Math.log(2) }, |
88 |
| - ]; |
89 |
| - |
90 |
| - for (const tc of testcases) { |
91 |
| - const result = calculator.log(...tc.param); |
92 |
| - assert.strictEqual(result, tc.expected); |
93 |
| - } |
94 |
| - }); |
95 |
| - }); |
96 |
| -}); |
| 5 | +// TODO: write your tests here |
0 commit comments