@@ -81,46 +81,46 @@ describe('Calculate the sum of array of numbers', () => {
8181 } ) ;
8282} ) ;
8383
84- // describe('Bonus: Calculate the sum', () => {
85- // it('should create a function named sum', () => {
86- // expect(typeof sum).toBe('function');
87- // });
84+ describe ( 'Bonus: Calculate the sum' , ( ) => {
85+ it ( 'should create a function named sum' , ( ) => {
86+ expect ( typeof sum ) . toBe ( 'function' ) ;
87+ } ) ;
8888
89- // it('should return zero if receives an empty array when called', () => {
90- // expect(sum([])).toBe(0);
91- // });
89+ it ( 'should return zero if receives an empty array when called' , ( ) => {
90+ expect ( sum ( [ ] ) ) . toBe ( 0 ) ;
91+ } ) ;
9292
93- // it('should return the sum with one number array', () => {
94- // expect(sum([4])).toBe(4);
95- // });
93+ it ( 'should return the sum with one number array' , ( ) => {
94+ expect ( sum ( [ 4 ] ) ) . toBe ( 4 ) ;
95+ } ) ;
9696
97- // it('should return zero if all elements are zero', () => {
98- // expect(sum([0, 0, 0, 0, 0])).toBe(0);
99- // });
97+ it ( 'should return zero if all elements are zero' , ( ) => {
98+ expect ( sum ( [ 0 , 0 , 0 , 0 , 0 ] ) ) . toBe ( 0 ) ;
99+ } ) ;
100100
101- // it('should return the sum when passed array of numbers', () => {
102- // expect(sum([10, 5, 4, 32, 8])).toBe(59);
103- // });
101+ it ( 'should return the sum when passed array of numbers' , ( ) => {
102+ expect ( sum ( [ 10 , 5 , 4 , 32 , 8 ] ) ) . toBe ( 59 ) ;
103+ } ) ;
104104
105- // it('should return the sum when passed array of strings', () => {
106- // expect(sum(['ana', 'marco', 'nicolas', 'tania', 'ptwd'])).toBe(24);
107- // });
105+ it ( 'should return the sum when passed array of strings' , ( ) => {
106+ expect ( sum ( [ 'ana' , 'marco' , 'nicolas' , 'tania' , 'ptwd' ] ) ) . toBe ( 24 ) ;
107+ } ) ;
108108
109- // it('should return the sum when passed array of mixed strings and numbers - ', () => {
110- // expect(sum([6, 12, 'miami', 1, 'barca', '200', 'lisboa', 8, 10])).toBe(56);
111- // });
112- // it('should return the sum when passed array of mixed strings, numbers and booleans - ', () => {
113- // // false is counted as 0
114- // expect(sum([6, 12, 'miami', 1, 'barca', '200', 'lisboa', 8, false])).toBe(46);
115- // // true is counted as 1
116- // expect(sum([6, 12, 'miami', 1, 'barca', '200', 'lisboa', 8, true])).toBe(47);
117- // });
118- // it('should throw an error when unsupported data type (object or array) present in the array', () => {
119- // expect(() => sum([6, 12, 'miami', 1, 'barca', '200', 'lisboa', 8, [], {}])).toThrow(
120- // new Error("Unsupported data type sir or ma'am")
121- // );
122- // });
123- // });
109+ it ( 'should return the sum when passed array of mixed strings and numbers - ' , ( ) => {
110+ expect ( sum ( [ 6 , 12 , 'miami' , 1 , 'barca' , '200' , 'lisboa' , 8 , 10 ] ) ) . toBe ( 56 ) ;
111+ } ) ;
112+ it ( 'should return the sum when passed array of mixed strings, numbers and booleans - ' , ( ) => {
113+ // false is counted as 0
114+ expect ( sum ( [ 6 , 12 , 'miami' , 1 , 'barca' , '200' , 'lisboa' , 8 , false ] ) ) . toBe ( 46 ) ;
115+ // true is counted as 1
116+ expect ( sum ( [ 6 , 12 , 'miami' , 1 , 'barca' , '200' , 'lisboa' , 8 , true ] ) ) . toBe ( 47 ) ;
117+ } ) ;
118+ it ( 'should throw an error when unsupported data type (object or array) present in the array' , ( ) => {
119+ expect ( ( ) => sum ( [ 6 , 12 , 'miami' , 1 , 'barca' , '200' , 'lisboa' , 8 , [ ] , { } ] ) ) . toThrow (
120+ new Error ( "Unsupported data type sir or ma'am" )
121+ ) ;
122+ } ) ;
123+ } ) ;
124124
125125describe ( 'Calculate the average of an array of numbers' , ( ) => {
126126 it ( 'should create a function named averageNumbers' , ( ) => {
0 commit comments