Change empty_error type to array. Add tests (#9019)

* Change error type tp array. Add tests

* Fix tests

* Put this back as it was
This commit is contained in:
AdRiley 2024-02-12 09:15:10 +00:00 committed by GitHub
parent ca9125f8e9
commit 48a61d7b78
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 3 deletions

View File

@ -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

View File

@ -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
@ -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

View File

@ -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]