@@ -11,15 +11,15 @@ const sum = require("./sum.js");
1111// Acceptance Criteria:
1212
1313describe ( "sum()" , ( ) => {
14- it ( "returns 0 for empty array" , ( ) => expect ( sum ( [ ] ) ) . toBe ( 0 ) ) ;
14+ it ( "returns 0 for empty array" , ( ) => expect ( sum ( [ ] ) ) . toBeCloseTo ( 0 ) ) ;
1515
1616 [
1717 { input : [ 4 ] , expected : 4 } ,
1818 { input : [ 367 ] , expected : 367 } ,
1919 { input : [ 7958463 ] , expected : 7958463 } ,
2020 ] . forEach ( ( { input, expected } ) => {
2121 it ( `returns the sum for arrays with one number` , ( ) =>
22- expect ( sum ( input ) ) . toBe ( expected ) ) ;
22+ expect ( sum ( input ) ) . toBeCloseTo ( expected ) ) ;
2323 } ) ;
2424
2525 [
@@ -28,7 +28,7 @@ describe("sum()", () => {
2828 { input : [ - 7958463 , - 100 , - 202 , - 6453 ] , expected : - 7965218 } ,
2929 ] . forEach ( ( { input, expected } ) =>
3030 it ( "returns the correct sum for array with only negative values" , ( ) =>
31- expect ( sum ( input ) ) . toBe ( expected ) )
31+ expect ( sum ( input ) ) . toBeCloseTo ( expected ) )
3232 ) ;
3333
3434 [
@@ -37,7 +37,7 @@ describe("sum()", () => {
3737 { input : [ - 7958463 , - 100 , - 202 , - 6453 , 153 , 45621 ] , expected : - 7919444 } ,
3838 ] . forEach ( ( { input, expected } ) =>
3939 it ( "returns the correct sum for array containing negative numbers" , ( ) =>
40- expect ( sum ( input ) ) . toBe ( expected ) )
40+ expect ( sum ( input ) ) . toBeCloseTo ( expected ) )
4141 ) ;
4242
4343 [
@@ -49,17 +49,19 @@ describe("sum()", () => {
4949 } ,
5050 ] . forEach ( ( { input, expected } ) =>
5151 it ( "returns the correct sum for array containing decimal/float numbers" , ( ) =>
52- expect ( sum ( input ) ) . toBe ( expected ) )
52+ expect ( sum ( input ) ) . toBeCloseTo ( expected ) )
5353 ) ;
5454
5555 [
56- { input : [ - 9 , 9 , 0.1 , ( ) => { } ] , expected : 0.1 } ,
56+ { input : [ - 9 , 9 , 0.1 , ( ) => { } , undefined ] , expected : 0.1 } ,
5757 {
58- input : [ - 367 , - 5 , "-234" , 70 , 2 , { fruit : "apple" } , - 4.567 ] ,
58+ input : [ - 367 , - 5 , "-234" , 70 , 2 , null , { fruit : "apple" } , - 4.567 ] ,
5959 expected : - 304.567 ,
6060 } ,
61+ { input : [ Infinity , - Infinity , 1 , , NaN , 10 , - 9 ] , expected : 2 } ,
6162 {
6263 input : [
64+ NaN ,
6365 - 7958463 ,
6466 - 100 ,
6567 "Iran" ,
@@ -77,15 +79,15 @@ describe("sum()", () => {
7779 expected : - 7910469.024 ,
7880 } ,
7981 ] . forEach ( ( { input, expected } ) =>
80- it ( "returns the correct sum for array containing decimal/float numbers " , ( ) =>
81- expect ( sum ( input ) ) . toBe ( expected ) )
82+ it ( "returns the correct sum for array containing finite and infinite values " , ( ) =>
83+ expect ( sum ( input ) ) . toBeCloseTo ( expected ) )
8284 ) ;
8385
8486 [
8587 [ "not an array" , null , undefined , { } , [ ] ] ,
8688 [ ( "apple" , null , undefined ) ] ,
8789 ] . forEach ( ( item ) =>
8890 it ( "returns 0 for arrays with only non-number values" , ( ) =>
89- expect ( sum ( item ) ) . toBe ( 0 ) )
91+ expect ( sum ( item ) ) . toBeCloseTo ( 0 ) )
9092 ) ;
9193} ) ;
0 commit comments