@@ -3,15 +3,17 @@ const assert = require('assert');
3
3
const { Calculator } = require ( './main' ) ;
4
4
5
5
describe ( 'Calculator' , ( ) => {
6
- const calculator = new Calculator ( ) ;
7
-
8
- describe ( 'exp function' , ( ) => {
9
- it ( 'calculates the exponential of a number' , async ( ) => {
6
+ describe ( 'exp' , ( ) => {
7
+ it ( 'should calculate the exponential function correctly' , ( ) => {
8
+ const calculator = new Calculator ( ) ;
9
+ assert . strictEqual ( calculator . exp ( 0 ) , 1 ) ;
10
10
assert . strictEqual ( calculator . exp ( 1 ) , Math . exp ( 1 ) ) ;
11
+ assert . strictEqual ( calculator . exp ( 2 ) , Math . exp ( 2 ) ) ;
11
12
} ) ;
12
13
13
- it ( 'throws error on non-finite input' , async ( ) => {
14
- assert . throws ( ( ) => calculator . exp ( 'a' ) , {
14
+ it ( 'should throw an error for unsupported operand type' , ( ) => {
15
+ const calculator = new Calculator ( ) ;
16
+ assert . throws ( ( ) => calculator . exp ( NaN ) , {
15
17
name : 'Error' ,
16
18
message : 'unsupported operand type'
17
19
} ) ;
@@ -21,38 +23,48 @@ describe('Calculator', () => {
21
23
} ) ;
22
24
} ) ;
23
25
24
- it ( 'handles overflow' , async ( ) => {
26
+ it ( 'should throw an error for overflow' , ( ) => {
27
+ const calculator = new Calculator ( ) ;
25
28
assert . throws ( ( ) => calculator . exp ( 1000 ) , {
26
29
name : 'Error' ,
27
30
message : 'overflow'
28
31
} ) ;
29
32
} ) ;
30
33
} ) ;
31
34
32
- describe ( 'log function' , ( ) => {
33
- it ( 'calculates the logarithm of a number' , async ( ) => {
34
- assert . strictEqual ( calculator . log ( Math . E ) , Math . log ( Math . E ) ) ;
35
+ describe ( 'log' , ( ) => {
36
+
37
+ it ( 'should calculate the natural logarithm correctly' , ( ) => {
38
+ const calculator = new Calculator ( ) ;
39
+ assert . strictEqual ( calculator . log ( 1 ) , 0 ) ;
40
+ assert . strictEqual ( calculator . log ( Math . E ) , 1 ) ;
35
41
} ) ;
36
42
37
- it ( 'throws error on non-finite input' , async ( ) => {
38
- assert . throws ( ( ) => calculator . log ( 'a' ) , {
43
+ it ( 'should throw an error for unsupported operand type' , ( ) => {
44
+ const calculator = new Calculator ( ) ;
45
+ assert . throws ( ( ) => calculator . log ( NaN ) , {
39
46
name : 'Error' ,
40
47
message : 'unsupported operand type'
41
48
} ) ;
42
- assert . throws ( ( ) => calculator . log ( - 1 ) , {
49
+ assert . throws ( ( ) => calculator . log ( Infinity ) , {
43
50
name : 'Error' ,
44
- message : 'math domain error (1) '
51
+ message : 'unsupported operand type '
45
52
} ) ;
46
53
} ) ;
47
54
48
- it ( 'handles domain errors' , async ( ) => {
55
+ it ( 'should throw an error for math domain error (1)' , ( ) => {
56
+ const calculator = new Calculator ( ) ;
49
57
assert . throws ( ( ) => calculator . log ( 0 ) , {
50
58
name : 'Error' ,
51
- message : 'math domain error (2 )'
59
+ message : 'math domain error (1 )'
52
60
} ) ;
53
- assert . throws ( ( ) => calculator . log ( null ) , {
61
+ } ) ;
62
+
63
+ it ( 'should throw an error for math domain error (2)' , ( ) => {
64
+ const calculator = new Calculator ( ) ;
65
+ assert . throws ( ( ) => calculator . log ( - 1 ) , {
54
66
name : 'Error' ,
55
- message : 'unsupported operand type '
67
+ message : 'math domain error (2) '
56
68
} ) ;
57
69
} ) ;
58
70
} ) ;
0 commit comments