Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(737)

Side by Side Diff: test/union_set_test.dart

Issue 1873373002: Add GroupSet and SetGroup classes. (Closed) Base URL: git@github.com:dart-lang/collection@master
Patch Set: Code review changes Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/union_set_controller_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 import "package:test/test.dart";
6
7 import "package:collection/collection.dart";
8
9 void main() {
10 group("with an empty outer set", () {
11 var set;
12 setUp(() {
13 set = new UnionSet<int>(new Set());
14 });
15
16 test("length returns 0", () {
17 expect(set.length, equals(0));
18 });
19
20 test("contains() returns false", () {
21 expect(set.contains(0), isFalse);
22 expect(set.contains(null), isFalse);
23 expect(set.contains("foo"), isFalse);
24 });
25
26 test("lookup() returns null", () {
27 expect(set.lookup(0), isNull);
28 expect(set.lookup(null), isNull);
29 expect(set.lookup("foo"), isNull);
30 });
31
32 test("toSet() returns an empty set", () {
33 expect(set.toSet(), isEmpty);
34 expect(set.toSet(), isNot(same(set)));
35 });
36
37 test("map() doesn't run on any elements", () {
38 expect(set.map(expectAsync((_) {}, count: 0)), isEmpty);
39 });
40 });
41
42 group("with multiple disjoint sets", () {
43 var set;
44 setUp(() {
45 set = new UnionSet<int>.from([
46 new Set.from([1, 2]),
47 new Set.from([3, 4]),
48 new Set.from([5]),
49 new Set()
50 ], disjoint: true);
51 });
52
53 test("length returns the total length", () {
54 expect(set.length, equals(5));
55 });
56
57 test("contains() returns whether any set contains the element", () {
58 expect(set.contains(1), isTrue);
59 expect(set.contains(4), isTrue);
60 expect(set.contains(5), isTrue);
61 expect(set.contains(6), isFalse);
62 });
63
64 test("lookup() returns elements that are in any set", () {
65 expect(set.lookup(1), equals(1));
66 expect(set.lookup(4), equals(4));
67 expect(set.lookup(5), equals(5));
68 expect(set.lookup(6), isNull);
69 });
70
71 test("toSet() returns the union of all the sets", () {
72 expect(set.toSet(), unorderedEquals([1, 2, 3, 4, 5]));
73 expect(set.toSet(), isNot(same(set)));
74 });
75
76 test("map() maps the elements", () {
77 expect(set.map((i) => i * 2), unorderedEquals([2, 4, 6, 8, 10]));
78 });
79 });
80
81 group("with multiple overlapping sets", () {
82 var set;
83 setUp(() {
84 set = new UnionSet<int>.from([
85 new Set.from([1, 2, 3]),
86 new Set.from([3, 4]),
87 new Set.from([5, 1]),
88 new Set()
89 ]);
90 });
91
92 test("length returns the total length", () {
93 expect(set.length, equals(5));
94 });
95
96 test("contains() returns whether any set contains the element", () {
97 expect(set.contains(1), isTrue);
98 expect(set.contains(4), isTrue);
99 expect(set.contains(5), isTrue);
100 expect(set.contains(6), isFalse);
101 });
102
103 test("lookup() returns elements that are in any set", () {
104 expect(set.lookup(1), equals(1));
105 expect(set.lookup(4), equals(4));
106 expect(set.lookup(5), equals(5));
107 expect(set.lookup(6), isNull);
108 });
109
110 test("lookup() returns the first element in an ordered context", () {
111 var duration1 = new Duration(seconds: 0);
112 var duration2 = new Duration(seconds: 0);
113 expect(duration1, equals(duration2));
114 expect(duration1, isNot(same(duration2)));
115
116 var set = new UnionSet.from([
117 new Set.from([duration1]),
118 new Set.from([duration2])
119 ]);
120
121 expect(set.lookup(new Duration(seconds: 0)), same(duration1));
122 });
123
124 test("toSet() returns the union of all the sets", () {
125 expect(set.toSet(), unorderedEquals([1, 2, 3, 4, 5]));
126 expect(set.toSet(), isNot(same(set)));
127 });
128
129 test("map() maps the elements", () {
130 expect(set.map((i) => i * 2), unorderedEquals([2, 4, 6, 8, 10]));
131 });
132 });
133
134 group("after an inner set was modified", () {
135 var set;
136 setUp(() {
137 var innerSet = new Set.from([3, 7]);
138 set = new UnionSet<int>.from([
139 new Set.from([1, 2]),
140 new Set.from([5]),
141 innerSet
142 ]);
143
144 innerSet.add(4);
145 innerSet.remove(7);
146 });
147
148 test("length returns the total length", () {
149 expect(set.length, equals(5));
150 });
151
152 test("contains() returns true for a new element", () {
153 expect(set.contains(4), isTrue);
154 });
155
156 test("contains() returns false for a removed element", () {
157 expect(set.contains(7), isFalse);
158 });
159
160 test("lookup() returns a new element", () {
161 expect(set.lookup(4), equals(4));
162 });
163
164 test("lookup() doesn't returns a removed element", () {
165 expect(set.lookup(7), isNull);
166 });
167
168 test("toSet() returns the union of all the sets", () {
169 expect(set.toSet(), unorderedEquals([1, 2, 3, 4, 5]));
170 expect(set.toSet(), isNot(same(set)));
171 });
172
173 test("map() maps the elements", () {
174 expect(set.map((i) => i * 2), unorderedEquals([2, 4, 6, 8, 10]));
175 });
176 });
177
178 group("after the outer set was modified", () {
179 var set;
180 setUp(() {
181 var innerSet = new Set.from([6]);
182 var outerSet = new Set.from([
183 new Set.from([1, 2]),
184 new Set.from([5]),
185 innerSet
186 ]);
187
188 set = new UnionSet<int>(outerSet);
189 outerSet.remove(innerSet);
190 outerSet.add(new Set.from([3, 4]));
191 });
192
193 test("length returns the total length", () {
194 expect(set.length, equals(5));
195 });
196
197 test("contains() returns true for a new element", () {
198 expect(set.contains(4), isTrue);
199 });
200
201 test("contains() returns false for a removed element", () {
202 expect(set.contains(6), isFalse);
203 });
204
205 test("lookup() returns a new element", () {
206 expect(set.lookup(4), equals(4));
207 });
208
209 test("lookup() doesn't returns a removed element", () {
210 expect(set.lookup(6), isNull);
211 });
212
213 test("toSet() returns the union of all the sets", () {
214 expect(set.toSet(), unorderedEquals([1, 2, 3, 4, 5]));
215 expect(set.toSet(), isNot(same(set)));
216 });
217
218 test("map() maps the elements", () {
219 expect(set.map((i) => i * 2), unorderedEquals([2, 4, 6, 8, 10]));
220 });
221 });
222 }
OLDNEW
« no previous file with comments | « test/union_set_controller_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698