@@ -4,12 +4,27 @@ const { Calculator } = require('./main');
4
4
5
5
// TODO: write your tests here
6
6
describe ( 'Calculator' , ( ) => {
7
+
7
8
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
+ ] ;
8
17
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));
13
28
} ) ;
14
29
15
30
it ( 'should calculate log correctly' , ( ) => {
0 commit comments