@@ -10,9 +10,8 @@ describe('Calculator', () => {
10
10
[ Infinity , 'unsupported operand type' ] ,
11
11
[ Number . MAX_VALUE , 'overflow' ] ,
12
12
[ 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 ) ]
16
15
] ;
17
16
const calculator = new Calculator ( ) ;
18
17
for ( const [ input , expected ] of testcases ) {
@@ -22,17 +21,24 @@ describe('Calculator', () => {
22
21
assert . strictEqual ( calculator . exp ( input ) , expected ) ;
23
22
}
24
23
}
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));
28
24
} ) ;
29
25
30
26
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
+ ] ;
31
35
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
+ }
37
43
} ) ;
38
44
} ) ;
0 commit comments