@@ -25,50 +25,43 @@ namespace {
25
25
TEST (SetOperationsTest, SetUnion) {
26
26
std::set<int > Set1 = {1 , 2 , 3 , 4 };
27
27
std::set<int > Set2 = {5 , 6 , 7 , 8 };
28
- // Set1 should be the union of input sets Set1 and Set2.
29
- std::set<int > ExpectedSet1 = {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 };
30
- // Set2 should not be touched.
31
- std::set<int > ExpectedSet2 = Set2;
32
28
33
29
set_union (Set1, Set2);
34
- EXPECT_EQ (ExpectedSet1, Set1);
35
- EXPECT_EQ (ExpectedSet2, Set2);
30
+ // Set1 should be the union of input sets Set1 and Set2.
31
+ EXPECT_THAT (Set1, UnorderedElementsAre (1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ));
32
+ // Set2 should not be touched.
33
+ EXPECT_THAT (Set2, UnorderedElementsAre (5 , 6 , 7 , 8 ));
36
34
37
35
Set1.clear ();
38
36
Set2 = {1 , 2 };
37
+
38
+ set_union (Set1, Set2);
39
39
// Set1 should be the union of input sets Set1 and Set2, which in this case
40
40
// will be Set2.
41
- ExpectedSet1 = Set2 ;
41
+ EXPECT_THAT (Set1, UnorderedElementsAre ( 1 , 2 )) ;
42
42
// Set2 should not be touched.
43
- ExpectedSet2 = Set2;
44
-
45
- set_union (Set1, Set2);
46
- EXPECT_EQ (ExpectedSet1, Set1);
47
- EXPECT_EQ (ExpectedSet2, Set2);
43
+ EXPECT_THAT (Set2, UnorderedElementsAre (1 , 2 ));
48
44
}
49
45
50
46
TEST (SetOperationsTest, SetIntersect) {
51
47
std::set<int > Set1 = {1 , 2 , 3 , 4 };
52
48
std::set<int > Set2 = {3 , 4 , 5 , 6 };
53
- // Set1 should be the intersection of sets Set1 and Set2.
54
- std::set<int > ExpectedSet1 = {3 , 4 };
55
- // Set2 should not be touched.
56
- std::set<int > ExpectedSet2 = Set2;
57
49
58
50
set_intersect (Set1, Set2);
59
- EXPECT_EQ (ExpectedSet1, Set1);
60
- EXPECT_EQ (ExpectedSet2, Set2);
51
+ // Set1 should be the intersection of sets Set1 and Set2.
52
+ EXPECT_THAT (Set1, UnorderedElementsAre (3 , 4 ));
53
+ // Set2 should not be touched.
54
+ EXPECT_THAT (Set2, UnorderedElementsAre (3 , 4 , 5 , 6 ));
61
55
62
56
Set1 = {1 , 2 , 3 , 4 };
63
57
Set2 = {5 , 6 };
64
- // Set2 should not be touched.
65
- ExpectedSet2 = Set2;
66
58
67
59
set_intersect (Set1, Set2);
68
60
// Set1 should be the intersection of sets Set1 and Set2, which
69
61
// is empty as they are non-overlapping.
70
62
EXPECT_THAT (Set1, IsEmpty ());
71
- EXPECT_EQ (ExpectedSet2, Set2);
63
+ // Set2 should not be touched.
64
+ EXPECT_THAT (Set2, UnorderedElementsAre (5 , 6 ));
72
65
73
66
// Check that set_intersect works on SetVector via remove_if.
74
67
SmallSetVector<int , 4 > SV;
@@ -85,121 +78,101 @@ TEST(SetOperationsTest, SetIntersection) {
85
78
std::set<int > Set1 = {1 , 2 , 3 , 4 };
86
79
std::set<int > Set2 = {3 , 4 , 5 , 6 };
87
80
std::set<int > Result;
88
- // Result should be the intersection of sets Set1 and Set2.
89
- std::set<int > ExpectedResult = {3 , 4 };
90
- // Set1 and Set2 should not be touched.
91
- std::set<int > ExpectedSet1 = Set1;
92
- std::set<int > ExpectedSet2 = Set2;
93
81
94
82
Result = set_intersection (Set1, Set2);
95
- EXPECT_EQ (ExpectedResult, Result);
96
- EXPECT_EQ (ExpectedSet1, Set1);
97
- EXPECT_EQ (ExpectedSet2, Set2);
83
+ // Result should be the intersection of sets Set1 and Set2.
84
+ EXPECT_THAT (Result, UnorderedElementsAre (3 , 4 ));
85
+ // Set1 and Set2 should not be touched.
86
+ EXPECT_THAT (Set1, UnorderedElementsAre (1 , 2 , 3 , 4 ));
87
+ EXPECT_THAT (Set2, UnorderedElementsAre (3 , 4 , 5 , 6 ));
98
88
99
89
Set1 = {1 , 2 , 3 , 4 };
100
90
Set2 = {5 , 6 };
101
- // Set1 and Set2 should not be touched.
102
- ExpectedSet1 = Set1;
103
- ExpectedSet2 = Set2;
104
91
105
92
Result = set_intersection (Set1, Set2);
106
93
// Result should be the intersection of sets Set1 and Set2, which
107
94
// is empty as they are non-overlapping.
108
95
EXPECT_THAT (Result, IsEmpty ());
109
- EXPECT_EQ (ExpectedSet1, Set1);
110
- EXPECT_EQ (ExpectedSet2, Set2);
96
+ // Set1 and Set2 should not be touched.
97
+ EXPECT_THAT (Set1, UnorderedElementsAre (1 , 2 , 3 , 4 ));
98
+ EXPECT_THAT (Set2, UnorderedElementsAre (5 , 6 ));
111
99
112
100
Set1 = {5 , 6 };
113
101
Set2 = {1 , 2 , 3 , 4 };
114
- // Set1 and Set2 should not be touched.
115
- ExpectedSet1 = Set1;
116
- ExpectedSet2 = Set2;
117
102
118
103
Result = set_intersection (Set1, Set2);
119
104
// Result should be the intersection of sets Set1 and Set2, which
120
105
// is empty as they are non-overlapping. Test this again with the input sets
121
106
// reversed, since the code takes a different path depending on which input
122
107
// set is smaller.
123
108
EXPECT_THAT (Result, IsEmpty ());
124
- EXPECT_EQ (ExpectedSet1, Set1);
125
- EXPECT_EQ (ExpectedSet2, Set2);
109
+ // Set1 and Set2 should not be touched.
110
+ EXPECT_THAT (Set1, UnorderedElementsAre (5 , 6 ));
111
+ EXPECT_THAT (Set2, UnorderedElementsAre (1 , 2 , 3 , 4 ));
126
112
}
127
113
128
114
TEST (SetOperationsTest, SetDifference) {
129
115
std::set<int > Set1 = {1 , 2 , 3 , 4 };
130
116
std::set<int > Set2 = {3 , 4 , 5 , 6 };
131
117
std::set<int > Result;
132
- // Result should be Set1 - Set2, leaving only {1, 2}.
133
- std::set<int > ExpectedResult = {1 , 2 };
134
- // Set1 and Set2 should not be touched.
135
- std::set<int > ExpectedSet1 = Set1;
136
- std::set<int > ExpectedSet2 = Set2;
137
118
138
119
Result = set_difference (Set1, Set2);
139
- EXPECT_EQ (ExpectedResult, Result);
140
- EXPECT_EQ (ExpectedSet1, Set1);
141
- EXPECT_EQ (ExpectedSet2, Set2);
120
+ // Result should be Set1 - Set2, leaving only {1, 2}.
121
+ EXPECT_THAT (Result, UnorderedElementsAre (1 , 2 ));
122
+ // Set1 and Set2 should not be touched.
123
+ EXPECT_THAT (Set1, UnorderedElementsAre (1 , 2 , 3 , 4 ));
124
+ EXPECT_THAT (Set2, UnorderedElementsAre (3 , 4 , 5 , 6 ));
142
125
143
126
Set1 = {1 , 2 , 3 , 4 };
144
127
Set2 = {1 , 2 , 3 , 4 };
145
- // Set1 and Set2 should not be touched.
146
- ExpectedSet1 = Set1;
147
- ExpectedSet2 = Set2;
148
128
149
129
Result = set_difference (Set1, Set2);
150
130
// Result should be Set1 - Set2, which should be empty.
151
131
EXPECT_THAT (Result, IsEmpty ());
152
- EXPECT_EQ (ExpectedSet1, Set1);
153
- EXPECT_EQ (ExpectedSet2, Set2);
132
+ // Set1 and Set2 should not be touched.
133
+ EXPECT_THAT (Set1, UnorderedElementsAre (1 , 2 , 3 , 4 ));
134
+ EXPECT_THAT (Set2, UnorderedElementsAre (1 , 2 , 3 , 4 ));
154
135
155
136
Set1 = {1 , 2 , 3 , 4 };
156
137
Set2 = {5 , 6 };
138
+
139
+ Result = set_difference (Set1, Set2);
157
140
// Result should be Set1 - Set2, which should be Set1 as they are
158
141
// non-overlapping.
159
- ExpectedResult = Set1 ;
142
+ EXPECT_THAT (Result, UnorderedElementsAre ( 1 , 2 , 3 , 4 )) ;
160
143
// Set1 and Set2 should not be touched.
161
- ExpectedSet1 = Set1;
162
- ExpectedSet2 = Set2;
163
-
164
- Result = set_difference (Set1, Set2);
165
- EXPECT_EQ (ExpectedResult, Result);
166
- EXPECT_EQ (ExpectedSet1, Set1);
167
- EXPECT_EQ (ExpectedSet2, Set2);
144
+ EXPECT_THAT (Set1, UnorderedElementsAre (1 , 2 , 3 , 4 ));
145
+ EXPECT_THAT (Set2, UnorderedElementsAre (5 , 6 ));
168
146
}
169
147
170
148
TEST (SetOperationsTest, SetSubtract) {
171
149
std::set<int > Set1 = {1 , 2 , 3 , 4 };
172
150
std::set<int > Set2 = {3 , 4 , 5 , 6 };
173
- // Set1 should get Set1 - Set2, leaving only {1, 2}.
174
- std::set<int > ExpectedSet1 = {1 , 2 };
175
- // Set2 should not be touched.
176
- std::set<int > ExpectedSet2 = Set2;
177
151
178
152
set_subtract (Set1, Set2);
179
- EXPECT_EQ (ExpectedSet1, Set1);
180
- EXPECT_EQ (ExpectedSet2, Set2);
153
+ // Set1 should get Set1 - Set2, leaving only {1, 2}.
154
+ EXPECT_THAT (Set1, UnorderedElementsAre (1 , 2 ));
155
+ // Set2 should not be touched.
156
+ EXPECT_THAT (Set2, UnorderedElementsAre (3 , 4 , 5 , 6 ));
181
157
182
158
Set1 = {1 , 2 , 3 , 4 };
183
159
Set2 = {1 , 2 , 3 , 4 };
184
- // Set2 should not be touched.
185
- ExpectedSet2 = Set2;
186
160
187
161
set_subtract (Set1, Set2);
188
162
// Set1 should get Set1 - Set2, which should be empty.
189
163
EXPECT_THAT (Set1, IsEmpty ());
190
- EXPECT_EQ (ExpectedSet2, Set2);
164
+ // Set2 should not be touched.
165
+ EXPECT_THAT (Set2, UnorderedElementsAre (1 , 2 , 3 , 4 ));
191
166
192
167
Set1 = {1 , 2 , 3 , 4 };
193
168
Set2 = {5 , 6 };
169
+
170
+ set_subtract (Set1, Set2);
194
171
// Set1 should get Set1 - Set2, which should be Set1 as they are
195
172
// non-overlapping.
196
- ExpectedSet1 = Set1 ;
173
+ EXPECT_THAT (Set1, UnorderedElementsAre ( 1 , 2 , 3 , 4 )) ;
197
174
// Set2 should not be touched.
198
- ExpectedSet2 = Set2;
199
-
200
- set_subtract (Set1, Set2);
201
- EXPECT_EQ (ExpectedSet1, Set1);
202
- EXPECT_EQ (ExpectedSet2, Set2);
175
+ EXPECT_THAT (Set2, UnorderedElementsAre (5 , 6 ));
203
176
}
204
177
205
178
TEST (SetOperationsTest, SetSubtractSmallPtrSet) {
@@ -239,56 +212,47 @@ TEST(SetOperationsTest, SetSubtractRemovedRemaining) {
239
212
240
213
std::set<int > Set1 = {1 , 2 , 3 , 4 };
241
214
std::set<int > Set2 = {3 , 4 , 5 , 6 };
215
+
216
+ set_subtract (Set1, Set2, Removed, Remaining);
242
217
// Set1 should get Set1 - Set2, leaving only {1, 2}.
243
- std::set< int > ExpectedSet1 = { 1 , 2 } ;
218
+ EXPECT_THAT (Set1, UnorderedElementsAre ( 1 , 2 )) ;
244
219
// Set2 should not be touched.
245
- std::set< int > ExpectedSet2 = Set2 ;
220
+ EXPECT_THAT (Set2, UnorderedElementsAre ( 3 , 4 , 5 , 6 )) ;
246
221
// We should get back that {3, 4} from Set2 were removed from Set1, and {5, 6}
247
222
// were not removed from Set1.
248
- std::set<int > ExpectedRemoved = {3 , 4 };
249
- std::set<int > ExpectedRemaining = {5 , 6 };
250
-
251
- set_subtract (Set1, Set2, Removed, Remaining);
252
- EXPECT_EQ (ExpectedSet1, Set1);
253
- EXPECT_EQ (ExpectedSet2, Set2);
254
- EXPECT_EQ (ExpectedRemoved, Removed);
255
- EXPECT_EQ (ExpectedRemaining, Remaining);
223
+ EXPECT_THAT (Removed, UnorderedElementsAre (3 , 4 ));
224
+ EXPECT_THAT (Remaining, UnorderedElementsAre (5 , 6 ));
256
225
257
226
Set1 = {1 , 2 , 3 , 4 };
258
227
Set2 = {1 , 2 , 3 , 4 };
259
228
Removed.clear ();
260
229
Remaining.clear ();
261
- // Set2 should not be touched.
262
- ExpectedSet2 = Set2;
263
- // Set should get back that all of Set2 was removed from Set1, and nothing
264
- // left in Set2 was not removed from Set1.
265
- ExpectedRemoved = Set2;
266
230
267
231
set_subtract (Set1, Set2, Removed, Remaining);
268
232
// Set1 should get Set1 - Set2, which should be empty.
269
233
EXPECT_THAT (Set1, IsEmpty ());
270
- EXPECT_EQ (ExpectedSet2, Set2);
271
- EXPECT_EQ (ExpectedRemoved, Removed);
234
+ // Set2 should not be touched.
235
+ EXPECT_THAT (Set2, UnorderedElementsAre (1 , 2 , 3 , 4 ));
236
+ // Set should get back that all of Set2 was removed from Set1, and nothing
237
+ // left in Set2 was not removed from Set1.
238
+ EXPECT_THAT (Removed, UnorderedElementsAre (1 , 2 , 3 , 4 ));
272
239
EXPECT_THAT (Remaining, IsEmpty ());
273
240
274
241
Set1 = {1 , 2 , 3 , 4 };
275
242
Set2 = {5 , 6 };
276
243
Removed.clear ();
277
244
Remaining.clear ();
245
+
246
+ set_subtract (Set1, Set2, Removed, Remaining);
278
247
// Set1 should get Set1 - Set2, which should be Set1 as they are
279
248
// non-overlapping.
280
- ExpectedSet1 = { 1 , 2 , 3 , 4 } ;
249
+ EXPECT_THAT (Set1, UnorderedElementsAre ( 1 , 2 , 3 , 4 )) ;
281
250
// Set2 should not be touched.
282
- ExpectedSet2 = Set2;
251
+ EXPECT_THAT (Set2, UnorderedElementsAre (5 , 6 ));
252
+ EXPECT_THAT (Removed, IsEmpty ());
283
253
// Set should get back that none of Set2 was removed from Set1, and all
284
254
// of Set2 was not removed from Set1.
285
- ExpectedRemaining = Set2;
286
-
287
- set_subtract (Set1, Set2, Removed, Remaining);
288
- EXPECT_EQ (ExpectedSet1, Set1);
289
- EXPECT_EQ (ExpectedSet2, Set2);
290
- EXPECT_THAT (Removed, IsEmpty ());
291
- EXPECT_EQ (ExpectedRemaining, Remaining);
255
+ EXPECT_THAT (Remaining, UnorderedElementsAre (5 , 6 ));
292
256
}
293
257
294
258
TEST (SetOperationsTest, SetIsSubset) {
0 commit comments