Skip to content

Commit

Permalink
Add tests of TreeSet removal operations (#420)
Browse files Browse the repository at this point in the history
* Add tests of TreeSet removal operations

* fmt

I promise I've become better at testing since adding this feature :)
  • Loading branch information
srawlins authored and cbracken committed Mar 24, 2018
1 parent 4e73f3e commit fb26a43
Showing 1 changed file with 71 additions and 1 deletion.
72 changes: 71 additions & 1 deletion test/collection/treeset_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,78 @@ main() {
});
});

group("removal", () {
TreeSet<num> tree;

test("remove from empty tree", () {
tree = new TreeSet();
tree.remove(10);
expect(tree, isEmpty);
});

test("remove from tree", () {
tree = new TreeSet()..addAll([10, 20, 15, 21, 30, 20]);
tree.remove(42);
expect(tree.toList(), equals([10, 15, 20, 21, 30]));

tree.remove(10);
expect(tree.toList(), equals([15, 20, 21, 30]));

tree.remove(30);
expect(tree.toList(), equals([15, 20, 21]));

tree.remove(20);
expect(tree.toList(), equals([15, 21]));
});

test("removeAll from tree", () {
tree = new TreeSet()..addAll([10, 20, 15, 21, 30, 20]);
tree.removeAll([42]);
expect(tree.toList(), equals([10, 15, 20, 21, 30]));

tree.removeAll([10, 30]);
expect(tree.toList(), equals([15, 20, 21]));

tree.removeAll([21, 20, 15]);
expect(tree, isEmpty);
});

test("removeWhere from tree", () {
tree = new TreeSet()..addAll([10, 20, 15, 21, 30, 20]);
tree.removeWhere((e) => e % 10 == 2);
expect(tree.toList(), equals([10, 15, 20, 21, 30]));

tree.removeWhere((e) => e % 10 == 0);
expect(tree.toList(), equals([15, 21]));

tree.removeWhere((e) => e % 10 > 0);
expect(tree, isEmpty);
});

test("retainAll from tree", () {
tree = new TreeSet()..addAll([10, 20, 15, 21, 30, 20]);
tree.retainAll([10, 30]);
expect(tree.toList(), equals([10, 30]));

tree.retainAll([42]);
expect(tree, isEmpty);
});

test("retainWhere from tree", () {
tree = new TreeSet()..addAll([10, 20, 15, 21, 30, 20]);
tree.retainWhere((e) => e % 1 == 0);
expect(tree.toList(), equals([10, 15, 20, 21, 30]));

tree.retainWhere((e) => e % 10 == 0);
expect(tree.toList(), equals([10, 20, 30]));

tree.retainWhere((e) => e % 10 > 0);
expect(tree, isEmpty);
});
});

group("set math", () {
/// NOTE: set math with sorted sets should have a performance benifit,
/// NOTE: set math with sorted sets should have a performance benefit;
/// we do not check the performance, only that the resulting math
/// is equivilant to non-sorted sets.
Expand Down

0 comments on commit fb26a43

Please sign in to comment.