Skip to content

Commit

Permalink
PR comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdunkerley committed May 11, 2022
1 parent 5f65c85 commit 3bf4fb4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ compute_bulk data statistics=[Count, Sum] =
Error.throw (Illegal_Argument_Error ("Can only compute " + v.to_text + " on numerical data sets."))
handle_unsupported = Panic.catch Unsupported_Argument_Types handler=report_invalid

empty_map s = if (s == Count) || (s == Sum) then 0 else Error.throw Empty_Error
empty_map s = if (s == Count) || (s == Sum) then 0 else
if (s == Minimum) || (s == Maximum) then Error.throw Empty_Error else
Number.nan

if data.length == 0 then statistics.map empty_map else
count_min_max_values = if count_min_max then CountMinMax.new (CountMinMax.toObjectStream data.to_array) Comparator.new else Nothing
Expand Down
16 changes: 9 additions & 7 deletions test/Tests/src/Data/Statistics_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,19 @@ spec =
values = number_set.compute_bulk stats
values.map_with_index i->v->((expected.at i - v).abs < double_error) . any v->(v == True) . should_equal True

Test.specify "should be able to count valid values on empty Vector" <|
Test.specify "should be able to count and sum on empty Vector" <|
[].compute . should_equal 0
[].compute Sum . should_equal 0

Test.specify "should fail with Empty_Error on other statistics for empty Vector" <|
Test.specify "should fail with Empty_Error for Minimuma and Maximum on empty Vector" <|
[].compute Minimum . should_fail_with Vector.Empty_Error
[].compute Maximum . should_fail_with Vector.Empty_Error
[].compute Sum . should_fail_with Vector.Empty_Error
[].compute Mean . should_fail_with Vector.Empty_Error
[].compute Variance . should_fail_with Vector.Empty_Error
[].compute Skew . should_fail_with Vector.Empty_Error
[].compute Kurtosis . should_fail_with Vector.Empty_Error

Test.specify "should be NaN for other statistics sum on empty Vector" <|
[].compute Mean . is_nan . should_equal True
[].compute Variance . is_nan . should_equal True
[].compute Skew . is_nan . should_equal True
[].compute Kurtosis . is_nan . should_equal True

Test.specify "should fail with Illegal_Argument_Error on number based statistics for text Vector" <|
text_set.compute Sum . should_fail_with Illegal_Argument_Error
Expand Down

0 comments on commit 3bf4fb4

Please sign in to comment.