make Set/Dict mostly work

This commit is contained in:
Folkert 2022-07-13 11:15:57 +02:00
parent 4d33e32078
commit 79f8ae4e69
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
6 changed files with 107 additions and 57 deletions

View file

@ -18,7 +18,9 @@ fn empty_len() {
assert_evals_to!(
indoc!(
r#"
Set.len Set.empty
app "set" imports [ Set ] provides [main] to "./platform"
main = Set.len Set.empty
"#
),
0,
@ -32,7 +34,9 @@ fn single_len() {
assert_evals_to!(
indoc!(
r#"
Set.len (Set.single 42)
app "set" imports [ Set ] provides [main] to "./platform"
main = Set.len (Set.single 42)
"#
),
1,
@ -46,7 +50,9 @@ fn single_to_list() {
assert_evals_to!(
indoc!(
r#"
Set.toList (Set.single 42)
app "set" imports [ Set ] provides [main] to "./platform"
main = Set.toList (Set.single 42)
"#
),
RocList::from_slice(&[42]),
@ -56,7 +62,9 @@ fn single_to_list() {
assert_evals_to!(
indoc!(
r#"
Set.toList (Set.single 1)
app "set" imports [ Set ] provides [main] to "./platform"
main = Set.toList (Set.single 1)
"#
),
RocList::from_slice(&[1]),
@ -66,7 +74,9 @@ fn single_to_list() {
assert_evals_to!(
indoc!(
r#"
Set.toList (Set.single 1.0)
app "set" imports [ Set ] provides [main] to "./platform"
main = Set.toList (Set.single 1.0)
"#
),
RocList::from_slice(&[1.0]),
@ -80,11 +90,14 @@ fn insert() {
assert_evals_to!(
indoc!(
r#"
Set.empty
|> Set.insert 0
|> Set.insert 1
|> Set.insert 2
|> Set.toList
app "set" imports [ Set ] provides [main] to "./platform"
main =
Set.empty
|> Set.insert 0
|> Set.insert 1
|> Set.insert 2
|> Set.toList
"#
),
RocList::from_slice(&[0, 1, 2]),
@ -98,12 +111,15 @@ fn remove() {
assert_evals_to!(
indoc!(
r#"
Set.empty
|> Set.insert 0
|> Set.insert 1
|> Set.remove 1
|> Set.remove 2
|> Set.toList
app "set" imports [ Set ] provides [main] to "./platform"
main =
Set.empty
|> Set.insert 0
|> Set.insert 1
|> Set.remove 1
|> Set.remove 2
|> Set.toList
"#
),
RocList::from_slice(&[0]),
@ -117,17 +133,20 @@ fn union() {
assert_evals_to!(
indoc!(
r#"
set1 : Set I64
app "set" imports [ Set ] provides [main] to "./platform"
set1 : Set.Set I64
set1 = Set.fromList [1,2]
set2 : Set I64
set2 : Set.Set I64
set2 = Set.fromList [1,3,4]
Set.union set1 set2
|> Set.toList
main =
Set.union set1 set2
|> Set.toList
"#
),
RocList::from_slice(&[4, 2, 3, 1]),
RocList::from_slice(&[1, 2, 3, 4]),
RocList<i64>
);
}
@ -138,14 +157,17 @@ fn difference() {
assert_evals_to!(
indoc!(
r#"
set1 : Set I64
app "set" imports [ Set ] provides [main] to "./platform"
set1 : Set.Set I64
set1 = Set.fromList [1,2]
set2 : Set I64
set2 : Set.Set I64
set2 = Set.fromList [1,3,4]
Set.difference set1 set2
|> Set.toList
main =
Set.difference set1 set2
|> Set.toList
"#
),
RocList::from_slice(&[2]),
@ -159,14 +181,17 @@ fn intersection() {
assert_evals_to!(
indoc!(
r#"
set1 : Set I64
app "set" imports [ Set ] provides [main] to "./platform"
set1 : Set.Set I64
set1 = Set.fromList [1,2]
set2 : Set I64
set2 : Set.Set I64
set2 = Set.fromList [1,3,4]
Set.intersection set1 set2
|> Set.toList
main =
Set.intersection set1 set2
|> Set.toList
"#
),
RocList::from_slice(&[1]),
@ -180,7 +205,9 @@ fn walk_sum() {
assert_evals_to!(
indoc!(
r#"
Set.walk (Set.fromList [1,2,3]) 0 (\x, y -> x + y)
app "set" imports [ Set ] provides [main] to "./platform"
main = Set.walk (Set.fromList [1,2,3]) 0 (\x, y -> x + y)
"#
),
6,
@ -194,7 +221,9 @@ fn contains() {
assert_evals_to!(
indoc!(
r#"
Set.contains (Set.fromList [1,3,4]) 4
app "set" imports [ Set ] provides [main] to "./platform"
main = Set.contains (Set.fromList [1,3,4]) 4
"#
),
true,
@ -204,7 +233,9 @@ fn contains() {
assert_evals_to!(
indoc!(
r#"
Set.contains (Set.fromList [1,3,4]) 2
app "set" imports [ Set ] provides [main] to "./platform"
main = Set.contains (Set.fromList [1,3,4]) 2
"#
),
false,
@ -218,24 +249,30 @@ fn from_list() {
assert_evals_to!(
indoc!(
r#"
[1,2,2,3,1,4]
|> Set.fromList
|> Set.toList
app "set" imports [ Set ] provides [main] to "./platform"
main =
[1,2,2,3,1,4]
|> Set.fromList
|> Set.toList
"#
),
RocList::from_slice(&[4, 2, 3, 1]),
RocList::from_slice(&[1, 2, 3, 4]),
RocList<i64>
);
assert_evals_to!(
indoc!(
r#"
app "set" imports [ Set ] provides [main] to "./platform"
empty : List I64
empty = []
empty
|> Set.fromList
|> Set.toList
main =
empty
|> Set.fromList
|> Set.toList
"#
),
RocList::<i64>::default(),
@ -249,9 +286,12 @@ fn from_list_void() {
assert_evals_to!(
indoc!(
r#"
[]
|> Set.fromList
|> Set.toList
app "set" imports [ Set ] provides [main] to "./platform"
main =
[]
|> Set.fromList
|> Set.toList
"#
),
RocList::<i64>::default(),
@ -265,13 +305,16 @@ fn from_list_result() {
assert_evals_to!(
indoc!(
r#"
app "set" imports [ Set ] provides [main] to "./platform"
x : Result Str {}
x = Ok "foo"
[x]
|> Set.fromList
|> Set.toList
|> List.len
main =
[x]
|> Set.fromList
|> Set.toList
|> List.len
"#
),
1,