FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript/Maths/test/AverageMean.test.js at master · TheAlgorithms/JavaScript · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
TheAlgorithms
/
JavaScript
Public
Uh oh!
There was an error while loading.
Please reload this page
.
Notifications
You must be signed in to change notification settings
Fork
5.8k
Star
34.2k
Code
Issues
21
Pull requests
192
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScript
/
Maths
/
test
/
AverageMean.test.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
67 lines (53 loc) · 1.89 KB
Breadcrumbs
JavaScript
/
Maths
/
test
/
AverageMean.test.js
Copy path
File metadata and controls
67 lines (53 loc) · 1.89 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import
{
mean
}
from
'../AverageMean'
describe
(
'Tests for average mean'
,
(
)
=>
{
it
(
'should be a function'
,
(
)
=>
{
expect
(
typeof
mean
)
.
toEqual
(
'function'
)
}
)
it
(
'should throw error for invalid input'
,
(
)
=>
{
expect
(
(
)
=>
mean
(
123
)
)
.
toThrow
(
)
}
)
it
(
'should return the mean of an array of numbers'
,
(
)
=>
{
const
meanFunction
=
mean
(
[
1
,
2
,
4
,
5
]
)
expect
(
meanFunction
)
.
toBe
(
3
)
}
)
it
(
'should return the mean of an array of numbers'
,
(
)
=>
{
const
meanFunction
=
mean
(
[
10
,
40
,
100
,
20
]
)
expect
(
meanFunction
)
.
toBe
(
42.5
)
}
)
it
(
'should return the number itself for a single-element array'
,
(
)
=>
{
const
result
=
mean
(
[
5
]
)
expect
(
result
)
.
toBe
(
5
)
}
)
it
(
'should throw error for empty array'
,
(
)
=>
{
expect
(
(
)
=>
mean
(
[
]
)
)
.
toThrow
(
)
}
)
it
(
'should throw error for an array containing null'
,
(
)
=>
{
expect
(
(
)
=>
mean
(
[
1
,
2
,
null
]
)
)
.
toThrow
(
)
}
)
it
(
'should throw error for an array containing booleans'
,
(
)
=>
{
expect
(
(
)
=>
mean
(
[
1
,
2
,
true
]
)
)
.
toThrow
(
)
}
)
it
(
'should throw error for an array containing strings'
,
(
)
=>
{
expect
(
(
)
=>
mean
(
[
1
,
2
,
'asd'
]
)
)
.
toThrow
(
)
}
)
it
(
'should return the mean of an array with negative numbers'
,
(
)
=>
{
const
result
=
mean
(
[
-
1
,
-
2
,
-
3
,
-
4
]
)
expect
(
result
)
.
toBe
(
-
2.5
)
}
)
it
(
'should return the mean of an array with floating-point numbers'
,
(
)
=>
{
const
result
=
mean
(
[
1.5
,
2.5
,
3.5
]
)
expect
(
result
)
.
toBe
(
2.5
)
}
)
it
(
'should return 0 for an array with zeros'
,
(
)
=>
{
const
result
=
mean
(
[
0
,
0
,
0
]
)
expect
(
result
)
.
toBe
(
0
)
}
)
it
(
'should handle very large numbers correctly'
,
(
)
=>
{
const
result
=
mean
(
[
1000000000
,
2000000000
,
3000000000
]
)
expect
(
result
)
.
toBe
(
2000000000
)
}
)
it
(
'should return correct mean for an array with integers and floating-point numbers'
,
(
)
=>
{
const
result
=
mean
(
[
1
,
2.5
,
3
]
)
expect
(
result
)
.
toBeCloseTo
(
2.1667
,
4
)
}
)
}
)
Back
|
FazBrowse Home
|
New Git URL