Skip to content

Commit

Permalink
Sync flatten-array exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
keiravillekode committed Dec 23, 2023
1 parent bcc6f8f commit a3d3bec
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
15 changes: 15 additions & 0 deletions exercises/practice/flatten-array/.meta/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[8c71dabd-da60-422d-a290-4a571471fb14]
description = "empty"

[d268b919-963c-442d-9f07-82b93f1b518c]
description = "no nesting"

[3f15bede-c856-479e-bb71-1684b20c6a30]
description = "flattens a nested array"

[c84440cc-bb3a-48a6-862c-94cf23f2815d]
description = "flattens array with just integers present"

Expand All @@ -21,6 +27,15 @@ description = "5 level nesting"
[d572bdba-c127-43ed-bdcd-6222ac83d9f7]
description = "6 level nesting"

[0705a8e5-dc86-4cec-8909-150c5e54fa9c]
description = "null values are omitted from the final result"

[c6cf26de-8ccd-4410-84bd-b9efd88fd2bc]
description = "consecutive null values at the front of the list are omitted from the final result"

[382c5242-587e-4577-b8ce-a5fb51e385a1]
description = "consecutive null values in the middle of the list are omitted from the final result"

[ef1d4790-1b1e-4939-a179-51ace0829dbd]
description = "6 level nest list with null values"

Expand Down
37 changes: 36 additions & 1 deletion exercises/practice/flatten-array/test.sml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(* version 1.1.0 *)
(* version 1.2.0 *)

use "testlib.sml";
use "flatten-array.sml";
Expand All @@ -8,13 +8,27 @@ fun x |> f = f x

val testsuite =
describe "flatten-array" [
test "empty"
(fn _ => let
val nested = List []
in
flatten nested |> Expect.equalTo []
end),

test "no nesting"
(fn _ => let
val nested = List [Elem 0, Elem 1, Elem 2]
in
flatten nested |> Expect.equalTo [0, 1, 2]
end),

test "flattens a nested array"
(fn _ => let
val nested = List [List [List []]]
in
flatten nested |> Expect.equalTo []
end),

test "flattens array with just integers present"
(fn _ => let
val nested = List [Elem 1,
Expand Down Expand Up @@ -51,6 +65,27 @@ val testsuite =
flatten nested |> Expect.equalTo [1, 2, 3, 4, 5, 6, 7, 8]
end),

test "Empty values are omitted from the final result"
(fn _ => let
val nested = List [Elem 1, Elem 2, Empty]
in
flatten nested |> Expect.equalTo [1, 2]
end),

test "consecutive Empty values at the front of the list are omitted from the final result"
(fn _ => let
val nested = List [Empty, Empty, Elem 3]
in
flatten nested |> Expect.equalTo [3]
end),

test "consecutive Empty values in the middle of the list are omitted from the final result"
(fn _ => let
val nested = List [Elem 1, Empty, Empty, Elem 4]
in
flatten nested |> Expect.equalTo [1, 4]
end),

test "6 level nest list with Empty values"
(fn _ => let
val nested = List [Elem 0,
Expand Down

0 comments on commit a3d3bec

Please sign in to comment.