@@ -3,3 +3,44 @@ const assert = require('assert');
3
3
const { Calculator } = require ( './main' ) ;
4
4
5
5
// TODO: write your tests here
6
+
7
+ describe ( 'Calculator' , ( ) => {
8
+
9
+ it ( 'should calculate exp correctly' , ( ) => {
10
+ const testcases = [
11
+ [ Infinity , 'unsupported operand type' ] ,
12
+ [ Number . MAX_VALUE , 'overflow' ] ,
13
+ [ 1 , Math . exp ( 1 ) ] ,
14
+ [ 0 , Math . exp ( 0 ) ] ,
15
+ [ - 1 , Math . exp ( - 1 ) ]
16
+ ] ;
17
+ const calculator = new Calculator ( ) ;
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
+ } ) ;
26
+
27
+ it ( 'should calculate log correctly' , ( ) => {
28
+ const testcases = [
29
+ [ Infinity , 'unsupported operand type' ] ,
30
+ [ 0 , 'unsupported operand type' ] ,
31
+ [ - 1 , 'unsupported operand type' ] ,
32
+ [ 1 , Math . log ( 1 ) ] ,
33
+ [ 100 , Math . log ( 100 ) ] ,
34
+ [ Math . E , Math . log ( Math . E ) ]
35
+ ] ;
36
+ const calculator = new Calculator ( ) ;
37
+ for ( const [ input , expected ] of testcases ) {
38
+ if ( typeof expected === 'string' ) {
39
+ assert . throws ( ( ) => calculator . log ( input ) , Error ) ;
40
+ } else {
41
+ assert . strictEqual ( calculator . log ( input ) , expected ) ;
42
+ }
43
+ }
44
+ } ) ;
45
+ } ) ;
46
+
0 commit comments