1
+ import { standardDeviation } from "../StandardDeviation.js" ;
2
+
3
+ test ( "Calculate STD of 3,5,6,10,23,12,19" , ( ) => {
4
+ expect ( standardDeviation ( [ 3 , 5 , 6 , 10 , 23 , 12 , 19 ] ) ) . toBeCloseTo ( 6.9164105353773 ) ;
5
+ } )
6
+
7
+ test ( "Calculate STD of -2,-5,1,12,23,-81,-23" , ( ) => {
8
+ expect ( standardDeviation ( [ - 2 , - 5 , 1 , 12 , 23 , - 81 , - 23 ] ) ) . toBeCloseTo ( 31.598889156399 ) ;
9
+ } )
10
+
11
+ test ( "Calculate STD of 0,0,0" , ( ) => {
12
+ expect ( standardDeviation ( [ 0 , 0 , 0 ] ) ) . toBeCloseTo ( 0 ) ;
13
+ } )
14
+
15
+ test ( "Calculate STD of -7,7" , ( ) => {
16
+ expect ( standardDeviation ( [ - 7 , 7 ] ) ) . toBeCloseTo ( 7 ) ;
17
+ } )
18
+
19
+ test ( "Throw error - array has less than two items" , ( ) => {
20
+ expect ( ( ) => standardDeviation ( [ ] ) ) . toThrow ( ) ;
21
+ expect ( ( ) => standardDeviation ( [ 7 ] ) ) . toThrow ( ) ;
22
+ } )
23
+
24
+ test ( "Throw type error - not an array" , ( ) => {
25
+ expect ( ( ) => standardDeviation ( 2 ) ) . toThrow ( ) ;
26
+ expect ( ( ) => standardDeviation ( "not an array" ) ) . toThrow ( ) ;
27
+ } )
28
+
29
+ test ( "Throw type error - not a number inside array" , ( ) => {
30
+ expect ( ( ) => standardDeviation ( [ 5 , "not a number" , 2 ] ) ) . toThrow ( ) ;
31
+ expect ( ( ) => standardDeviation ( [ 1 , [ 2 ] , 3 ] ) ) . toThrow ( ) ;
32
+ } )
0 commit comments