mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
make Set/Dict mostly work
This commit is contained in:
parent
4d33e32078
commit
79f8ae4e69
6 changed files with 107 additions and 57 deletions
|
@ -243,7 +243,7 @@ fn from_list_with_fold_simple() {
|
|||
main = Dict.values myDict
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[2, 3, 1]),
|
||||
RocList::from_slice(&[1, 2, 3]),
|
||||
RocList<i64>
|
||||
);
|
||||
}
|
||||
|
@ -273,8 +273,8 @@ fn from_list_with_fold_reallocates() {
|
|||
"#
|
||||
),
|
||||
RocList::from_slice(&[
|
||||
4, 5, 20, 0, 7, 3, 1, 21, 10, 6, 13, 9, 14, 19, 2, 15, 12, 17, 16, 18, 22, 8, 11, 24,
|
||||
23
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
|
||||
24
|
||||
]),
|
||||
RocList<i64>
|
||||
);
|
||||
|
@ -299,7 +299,7 @@ fn small_str_keys() {
|
|||
main = Dict.keys myDict
|
||||
"#
|
||||
),
|
||||
RocList::from_slice(&[RocStr::from("c"), RocStr::from("a"), RocStr::from("b"),],),
|
||||
RocList::from_slice(&["a".into(), "b".into(), "c".into(),],),
|
||||
RocList<RocStr>
|
||||
);
|
||||
}
|
||||
|
@ -324,8 +324,8 @@ fn big_str_keys() {
|
|||
),
|
||||
RocList::from_slice(&[
|
||||
RocStr::from("Leverage agile frameworks to provide a robust"),
|
||||
RocStr::from("to corporate strategy foster collaborative thinking to"),
|
||||
RocStr::from("synopsis for high level overviews. Iterative approaches"),
|
||||
RocStr::from("to corporate strategy foster collaborative thinking to"),
|
||||
]),
|
||||
RocList<RocStr>
|
||||
);
|
||||
|
@ -351,8 +351,8 @@ fn big_str_values() {
|
|||
),
|
||||
RocList::from_slice(&[
|
||||
RocStr::from("Leverage agile frameworks to provide a robust"),
|
||||
RocStr::from("to corporate strategy foster collaborative thinking to"),
|
||||
RocStr::from("synopsis for high level overviews. Iterative approaches"),
|
||||
RocStr::from("to corporate strategy foster collaborative thinking to"),
|
||||
]),
|
||||
RocList<RocStr>
|
||||
);
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue