Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change empty_error type to array. Add tests #9019

Merged
merged 3 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ type Array

[0, 1, 2].to_array . reduce (+)
reduce : (Any -> Any -> Any) -> Any -> Any
reduce self function ~if_empty=(Error.throw (Empty_Error.Error Vector)) = Vector.reduce self function if_empty
reduce self function ~if_empty=(Error.throw (Empty_Error.Error Array)) = Vector.reduce self function if_empty

## GROUP Logical
ICON preparation
Expand Down
7 changes: 7 additions & 0 deletions test/Base_Tests/src/Data/Array_Spec.enso
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from Standard.Base import all
import Standard.Base.Errors.Empty_Error.Empty_Error
import Standard.Base.Errors.Common.Index_Out_Of_Bounds
import Standard.Base.Errors.Illegal_State.Illegal_State

Expand Down Expand Up @@ -42,6 +43,12 @@ add_specs suite_builder =
arr . should_equal [3, 1, 2]
new_arr . should_equal [1, 2, 3]

group_builder.specify "should be able to be reduced" <|
make_enso_array [1, 2, 3, 4, 5] . reduce (+) . should_equal 15
make_enso_array [1, 3, 5] . reduce (+) . should_equal 9
make_enso_array [] . reduce (+) . should_fail_with (Empty_Error.Error Array)
make_enso_array [] . reduce (+) 0 . should_equal 0

suite_builder.group "Compare functionality with Vector" group_builder->
group_builder.specify "compare methods" <|
vector_methods = Meta.meta Vector . methods . sort
Expand Down
5 changes: 3 additions & 2 deletions test/Base_Tests/src/Data/Vector_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ type_spec suite_builder name alter = suite_builder.group name group_builder->

group_builder.specify "should allow to reduce elements if it is non-empty" <|
alter [1,2,3] . reduce (+) . should_equal 6
alter [] . reduce (+) . should_fail_with (Empty_Error.Error Vector)
alter [] . reduce (+) 0 . should_equal 0
empty_vec = alter []
empty_vec . reduce (+) . should_fail_with (Empty_Error.Error (Meta.type_of empty_vec))
empty_vec . reduce (+) 0 . should_equal 0

group_builder.specify "should check any" <|
vec = alter [1, 2, 3, 4, 5]
Expand Down
Loading