Skip to content

Commit

Permalink
tests: Some test cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dinfuehr committed Feb 16, 2025
1 parent 361d3a7 commit de0c8f8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
8 changes: 4 additions & 4 deletions tests/stdlib/iterator-collect-map.dora
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::collections::HashMap;

fn main() {
let initial = Vec[(Int, String)]::new((1, "one"), (3, "three"));
let x = initial.iter().collect[HashMap[Int, String]]();
assert(x.size() == 2);
assert(x.get(1) == Some[String]("one"));
assert(x.get(3) == Some[String]("three"));
let map = initial.iter().collect[HashMap[Int, String]]();
assert(map.size() == 2);
assert(map.get(1) == Some[String]("one"));
assert(map.get(3) == Some[String]("three"));
}
19 changes: 10 additions & 9 deletions tests/stdlib/iterator-collect.dora
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ use std::collections::HashSet;

fn main() {
let initial = Vec[Int]::new(1, 2, 3, 4, 5);
let x = initial.iter().collect[Vec[Int]]();
assert(initial !== x);
assert(initial == x);
let copy = initial.iter().collect[Vec[Int]]();
assert(initial !== copy);
assert(initial == copy);

let initial = Array[Int]::new(1, 2, 3, 4, 5);
let x = initial.iter().collect[Array[Int]]();
assert(initial !== x);
assert(initial == x);
let copy = initial.iter().collect[Array[Int]]();
assert(initial !== copy);
assert(initial == copy);

let initial = Vec[Int]::new(1, 5, 3, 1, 5);
let x = initial.iter().collect[HashSet[Int]]().iter().collect[Vec[Int]]();
x.sort();
assert(x == Vec[Int]::new(1, 3, 5));
let set = initial.iter().collect[HashSet[Int]]();
let set_as_vec = set.iter().collect[Vec[Int]]();
set_as_vec.sort();
assert(set_as_vec == Vec[Int]::new(1, 3, 5));
}
2 changes: 0 additions & 2 deletions tests/stdlib/iterator-fold.dora
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::collections::HashMap;

fn main() {
let x = Vec[Int]::new(1, 2, 3, 4, 5).iter().fold[Int](0, |result: Int, x: Int|: Int { result + x });
assert(x == 15);
Expand Down
2 changes: 0 additions & 2 deletions tests/stdlib/iterator-reduce.dora
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::collections::HashMap;

fn main() {
let x = Vec[Int]::new(1, 2, 3, 4, 5).iter().reduce(|result: Int, x: Int|: Int { result + x });
assert(x == Some[Int](15));
Expand Down

0 comments on commit de0c8f8

Please sign in to comment.