Skip to content

Commit

Permalink
Change empty_error type to array. Add tests (#9019)
Browse files Browse the repository at this point in the history
* Change error type tp array. Add tests

* Fix tests

* Put this back as it was
  • Loading branch information
AdRiley authored Feb 12, 2024
1 parent ca9125f commit 48a61d7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
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

0 comments on commit 48a61d7

Please sign in to comment.