expand Set test cases

This commit is contained in:
Brendan Hansknecht 2022-11-21 19:19:54 -08:00
parent cad7d8b4e9
commit 4befccc6b4
No known key found for this signature in database
GPG key ID: 0EA784685083E75B
2 changed files with 34 additions and 28 deletions

View file

@ -801,33 +801,12 @@ expect
&& (get dict "g" == Ok 6)
&& (get dict "h" == Ok 7)
# These are equivalent to the Set tests that are panicking for some reason.
expect
actual =
empty
|> insert "foo" {}
|> insert "bar" {}
|> insert "foo" {}
|> insert "baz" {}
expected =
empty
|> insert "foo" {}
|> insert "bar" {}
|> insert "baz" {}
toList expected == toList actual
expect
actual =
empty
|> insert "foo" {}
|> insert "bar" {}
|> insert "foo" {}
|> insert "baz" {}
|> len
actual == 3
Dict.empty
|> Dict.insert "Some" "Value"
|> Dict.remove "Some"
|> Dict.len
|> Bool.isEq 0
# We have decided not to expose the standard roc hashing algorithm.
# This is to avoid external dependence and the need for versioning.

View file

@ -105,7 +105,7 @@ fromList : List k -> Set k | k has Hash & Eq
fromList = \list ->
initial = @Set (Dict.withCapacity (List.len list))
List.walk list initial \set, key -> Set.insert set key
List.walk list initial insert
union : Set k, Set k -> Set k | k has Hash & Eq
union = \@Set dict1, @Set dict2 ->
@ -175,4 +175,31 @@ expect
|> insert 3
|> insert 4
union first second == expected
union first second == expected
expect
base =
single "Remove Me"
|> insert "Keep Me"
|> insert "And Me"
expected =
single "Keep Me"
|> insert "And Me"
remove base "Remove Me" == expected
expect
x =
single 0
|> insert 1
|> insert 2
|> insert 3
|> insert 4
|> insert 5
|> insert 6
|> insert 7
|> insert 8
|> insert 9
x == fromList (toList x)