@@ -3,156 +3,3 @@ const assert = require('assert');
33const { Calculator } = require ( './main' ) ;
44
55// TODO: write your tests here
6-
7- describe ( "test Calculator" , ( ) => {
8- const calculator = new Calculator ;
9- // console.log(calculator.exp(1000000000));
10- describe ( "exp(x) testing" , ( ) => {
11- it ( "error testcases" , ( ) => {
12- const testcases = [
13- { param : [ Infinity ] , expected : {
14- name : 'Error' ,
15- message : 'unsupported operand type'
16- } } ,
17- { param : [ - Infinity ] , expected : {
18- name : 'Error' ,
19- message : 'unsupported operand type'
20- } } ,
21- { param : [ 'abc' ] , expected : {
22- name : 'Error' ,
23- message : 'unsupported operand type'
24- } } ,
25- { param : [ 1234567890 ] , expected : {
26- name : 'Error' ,
27- message : 'overflow'
28- } }
29- ] ;
30- for ( tc of testcases ) {
31- assert . throws ( ( ) => {
32- calculator . exp . apply ( this , tc . param ) } ,
33- tc . expected
34- ) ;
35- }
36- } ) ;
37-
38- /* it("isFinite Error", () => {
39- assert.throws(() => {
40- calculator.exp(Infinity);
41- }, {
42- name: 'Error',
43- message: 'unsupported operand type'
44- });
45- assert.throws(() => {
46- calculator.exp('abc');
47- }, {
48- name: 'Error',
49- message: 'unsupported operand type'
50- });
51- });
52- it("overflow Error", () => {
53- assert.throws(() => {
54- calculator.exp(1000000000);
55- }, {
56- name: 'Error',
57- message: 'overflow'
58- });
59- });
60- */
61- it ( "normal behavior" , ( ) => {
62- const testcases = [
63- { param : [ 1 ] , expected : Math . exp ( 1 ) } ,
64- { param : [ 16 ] , expected : Math . exp ( 16 ) } ,
65- { param : [ - 3 ] , expected : Math . exp ( - 3 ) } ,
66- { param : [ 0.794 ] , expected : Math . exp ( 0.794 ) }
67- ] ;
68- for ( const tc of testcases ) {
69- assert . strictEqual ( calculator . exp . apply ( this , tc . param ) , tc . expected ) ;
70- }
71- } ) ;
72- } ) ;
73- describe ( "log(x) testing" , ( ) => {
74- it ( "error testcases" , ( ) => {
75- const testcases = [
76- { param : [ Infinity ] , expected : {
77- name : 'Error' ,
78- message : 'unsupported operand type'
79- } } ,
80- { param : [ - Infinity ] , expected : {
81- name : 'Error' ,
82- message : 'unsupported operand type'
83- } } ,
84- { param : [ 'abc' ] , expected : {
85- name : 'Error' ,
86- message : 'unsupported operand type'
87- } } ,
88- { param : [ 0 ] , expected : {
89- name : 'Error' ,
90- message : 'math domain error (1)'
91- } } ,
92- { param : [ - 1 ] , expected : {
93- name : 'Error' ,
94- message : 'math domain error (2)'
95- } } ,
96- { param : [ - 1000000 ] , expected : {
97- name : 'Error' ,
98- message : 'math domain error (2)'
99- } }
100- ] ;
101- for ( tc of testcases ) {
102- assert . throws ( ( ) => {
103- calculator . log . apply ( this , tc . param ) } ,
104- tc . expected
105- ) ;
106- }
107- } ) ;
108-
109- /* it("isFinite Error", () =>{
110- assert.throws(() => {
111- calculator.log(Infinity);
112- }, {
113- name: 'Error',
114- message: 'unsupported operand type'
115- });
116- assert.throws(() => {
117- calculator.log('abc');
118- }, {
119- name: 'Error',
120- message: 'unsupported operand type'
121- });
122- });
123- it("domain error (1)", () => {
124- assert.throws(() => {
125- calculator.log(0);
126- }, {
127- name: 'Error',
128- message: 'math domain error (1)'
129- });
130- });
131- it("domain error (2)", () => {
132- assert.throws(() => {
133- calculator.log(-1);
134- }, {
135- name: 'Error',
136- message: 'math domain error (2)'
137- });
138- assert.throws(() => {
139- calculator.log(-1000000);
140- }, {
141- name: 'Error',
142- message: 'math domain error (2)'
143- });
144- });
145- */
146- it ( "normal behavior" , ( ) => {
147- const testcases = [
148- { param : [ 1 ] , expected : Math . log ( 1 ) } ,
149- { param : [ 16 ] , expected : Math . log ( 16 ) } ,
150- { param : [ 3456789 ] , expected : Math . log ( 3456789 ) } ,
151- { param : [ 0.794 ] , expected : Math . log ( 0.794 ) }
152- ] ;
153- for ( const tc of testcases ) {
154- assert . strictEqual ( calculator . log . apply ( this , tc . param ) , tc . expected ) ;
155- }
156- } ) ;
157- } ) ;
158- } ) ;
0 commit comments