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 1 commit
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
13 changes: 8 additions & 5 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,18 +43,20 @@ 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
array_methods = Meta.meta Array . methods . sort
vector_methods . should_equal array_methods

suite_builder.group "ArrayOverBuffer" group_builder->
location_pending = case Platform.os of
Platform.OS.Windows -> "This test is disabled on Windows."
_ -> Nothing

group_builder.specify "should behave like an Array" pending=location_pending <|
group_builder.specify "should behave like an Array" <|
array_over_buffer = (File.new (enso_project.data / "sample.txt") . read_last_bytes 10).to_array

case array_over_buffer of
Expand Down
Loading