Skip to content

Commit

Permalink
1-5 stats
Browse files Browse the repository at this point in the history
  • Loading branch information
jdunkerley committed May 11, 2022
1 parent 3bf4fb4 commit 5f45e3d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/Tests/src/Data/Statistics_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type No_Ord number
# Tests

spec =
simple_set = [1, 2, 3, 4, 5]
number_set = [0.4, -18.56, -16.99, -16.43, -45.84, 13.44, -6.85, 9.68, -8.55, 10.87, 10.38, 33.85, -41.02, 1.87, -26.52, -13.87, -39.06, 25.92, -16.01, 42.01]
missing_set = number_set.map_with_index i->v->(if i % 5 == 4 then Nothing else v)
with_nans_set = number_set.map_with_index i->v->(if i % 5 == 4 then (if i % 10 == 9 then Number.nan else Nothing) else v)
Expand All @@ -29,66 +30,78 @@ spec =

Test.group "Statistics" <|
Test.specify "should be able to count valid values" <|
simple_set.compute . should_equal 5
number_set.compute . should_equal 20
missing_set.compute . should_equal 16
with_nans_set.compute . should_equal 16
text_set.compute . should_equal 3

Test.specify "should be able to get minimum of maximum values" <|
simple_set.compute Minimum . should_equal 1
number_set.compute Minimum . should_equal -45.84 epsilon=double_error
missing_set.compute Minimum . should_equal -41.02 epsilon=double_error
with_nans_set.compute Minimum . should_equal -41.02 epsilon=double_error
text_set.compute Minimum . should_equal "A"
simple_set.compute Maximum . should_equal 5
number_set.compute Maximum . should_equal 42.01 epsilon=double_error
missing_set.compute Maximum . should_equal 33.85 epsilon=double_error
with_nans_set.compute Maximum . should_equal 33.85 epsilon=double_error
text_set.compute Maximum . should_equal "D"

Test.specify "should be able to get sum of values" <|
simple_set.compute Sum . should_equal 15 epsilon=double_error
number_set.compute Sum . should_equal -101.28 epsilon=double_error
missing_set.compute Sum . should_equal -81.8 epsilon=double_error
with_nans_set.compute Sum . should_equal -81.8 epsilon=double_error

Test.specify "should be able to get mean of values" <|
simple_set.compute Mean . should_equal 3 epsilon=double_error
number_set.compute Mean . should_equal -5.064 epsilon=double_error
missing_set.compute Mean . should_equal -5.1125 epsilon=double_error
with_nans_set.compute Mean . should_equal -5.1125 epsilon=double_error

Test.specify "should be able to get sample variance of values" <|
simple_set.compute Variance . should_equal 2.5 epsilon=double_error
number_set.compute Variance . should_equal 582.0137832 epsilon=double_error
missing_set.compute Variance . should_equal 431.0218867 epsilon=double_error
with_nans_set.compute Variance . should_equal 431.0218867 epsilon=double_error
[1].compute Variance . is_nan . should_equal True

Test.specify "should be able to get population variance of values" <|
simple_set.compute (Variance True) . should_equal 2 epsilon=double_error
number_set.compute (Variance True) . should_equal 552.913094 epsilon=double_error
missing_set.compute (Variance True) . should_equal 404.0830188 epsilon=double_error
with_nans_set.compute (Variance True) . should_equal 404.0830188 epsilon=double_error

Test.specify "should be able to get population standard deviation of values" <|
simple_set.compute Standard_Deviation . should_equal 1.58113883 epsilon=double_error
number_set.compute Standard_Deviation . should_equal 24.12496183 epsilon=double_error
missing_set.compute Standard_Deviation . should_equal 20.76106661 epsilon=double_error
with_nans_set.compute Standard_Deviation . should_equal 20.76106661 epsilon=double_error
[1].compute Standard_Deviation . is_nan . should_equal True

Test.specify "should be able to get sample standard deviation of values" <|
simple_set.compute (Standard_Deviation True) . should_equal 1.414213562 epsilon=double_error
number_set.compute (Standard_Deviation True) . should_equal 23.51410415 epsilon=double_error
missing_set.compute (Standard_Deviation True) . should_equal 20.1018163 epsilon=double_error
with_nans_set.compute (Standard_Deviation True) . should_equal 20.1018163 epsilon=double_error

Test.specify "should be able to get sample skewness of values" <|
simple_set.compute Skew . should_equal 0 epsilon=double_error
number_set.compute Skew . should_equal 0.165086552 epsilon=double_error
missing_set.compute Skew . should_equal 0.084238123 epsilon=double_error
with_nans_set.compute Skew . should_equal 0.084238123 epsilon=double_error
[1, 2].compute Skew . is_nan . should_equal True

Test.specify "should be able to get population skewness of values" <|
simple_set.compute (Skew True) . should_equal 0 epsilon=double_error
number_set.compute (Skew True) . should_equal 0.152437706 epsilon=double_error
missing_set.compute (Skew True) . should_equal 0.076125664 epsilon=double_error
with_nans_set.compute (Skew True) . should_equal 0.076125664 epsilon=double_error
[1, 2].compute (Skew True) . is_nan . should_equal True

Test.specify "should be able to get sample kurtosis of values" <|
simple_set.compute Kurtosis . should_equal -1.2 epsilon=double_error
number_set.compute Kurtosis . should_equal -0.449422438 epsilon=double_error
missing_set.compute Kurtosis . should_equal -0.201991074 epsilon=double_error
with_nans_set.compute Kurtosis . should_equal -0.201991074 epsilon=double_error
Expand Down

0 comments on commit 5f45e3d

Please sign in to comment.