@@ -18,4 +18,50 @@ describe('Tests for average mean', () => {
1818 const meanFunction = mean ( [ 10 , 40 , 100 , 20 ] )
1919 expect ( meanFunction ) . toBe ( 42.5 )
2020 } )
21+
22+ it ( 'should return the number itself for a single-element array' , ( ) => {
23+ const result = mean ( [ 5 ] )
24+ expect ( result ) . toBe ( 5 )
25+ } )
26+
27+ it ( 'should throw error for empty array' , ( ) => {
28+ expect ( ( ) => mean ( [ ] ) ) . toThrow ( )
29+ } )
30+
31+ it ( 'should throw error for an array containing null' , ( ) => {
32+ expect ( ( ) => mean ( [ 1 , 2 , null ] ) ) . toThrow ( )
33+ } )
34+
35+ it ( 'should throw error for an array containing booleans' , ( ) => {
36+ expect ( ( ) => mean ( [ 1 , 2 , true ] ) ) . toThrow ( )
37+ } )
38+
39+ it ( 'should throw error for an array containing strings' , ( ) => {
40+ expect ( ( ) => mean ( [ 1 , 2 , 'asd' ] ) ) . toThrow ( )
41+ } )
42+
43+ it ( 'should return the mean of an array with negative numbers' , ( ) => {
44+ const result = mean ( [ - 1 , - 2 , - 3 , - 4 ] )
45+ expect ( result ) . toBe ( - 2.5 )
46+ } )
47+
48+ it ( 'should return the mean of an array with floating-point numbers' , ( ) => {
49+ const result = mean ( [ 1.5 , 2.5 , 3.5 ] )
50+ expect ( result ) . toBe ( 2.5 )
51+ } )
52+
53+ it ( 'should return 0 for an array with zeros' , ( ) => {
54+ const result = mean ( [ 0 , 0 , 0 ] )
55+ expect ( result ) . toBe ( 0 )
56+ } )
57+
58+ it ( 'should handle very large numbers correctly' , ( ) => {
59+ const result = mean ( [ 1000000000 , 2000000000 , 3000000000 ] )
60+ expect ( result ) . toBe ( 2000000000 )
61+ } )
62+
63+ it ( 'should return correct mean for an array with integers and floating-point numbers' , ( ) => {
64+ const result = mean ( [ 1 , 2.5 , 3 ] )
65+ expect ( result ) . toBeCloseTo ( 2.1667 , 4 )
66+ } )
2167} )
0 commit comments