@@ -313,8 +313,8 @@ TEST(SmallPtrSetTest, ConstTest) {
313
313
IntSet.insert (B);
314
314
EXPECT_EQ (IntSet.count (B), 1u );
315
315
EXPECT_EQ (IntSet.count (C), 1u );
316
- EXPECT_NE (IntSet.find (B), IntSet. end ( ));
317
- EXPECT_NE (IntSet.find (C), IntSet. end ( ));
316
+ EXPECT_TRUE (IntSet.contains (B ));
317
+ EXPECT_TRUE (IntSet.contains (C ));
318
318
}
319
319
320
320
// Verify that we automatically get the const version of PointerLikeTypeTraits
@@ -327,7 +327,7 @@ TEST(SmallPtrSetTest, ConstNonPtrTest) {
327
327
TestPair Pair (&A[0 ], 1 );
328
328
IntSet.insert (Pair);
329
329
EXPECT_EQ (IntSet.count (Pair), 1u );
330
- EXPECT_NE (IntSet.find (Pair), IntSet. end ( ));
330
+ EXPECT_TRUE (IntSet.contains (Pair));
331
331
}
332
332
333
333
// Test equality comparison.
@@ -367,3 +367,31 @@ TEST(SmallPtrSetTest, EqualityComparison) {
367
367
EXPECT_NE (c, e);
368
368
EXPECT_NE (e, d);
369
369
}
370
+
371
+ TEST (SmallPtrSetTest, Contains) {
372
+ SmallPtrSet<int *, 2 > Set;
373
+ int buf[4 ] = {0 , 11 , 22 , 11 };
374
+ EXPECT_FALSE (Set.contains (&buf[0 ]));
375
+ EXPECT_FALSE (Set.contains (&buf[1 ]));
376
+
377
+ Set.insert (&buf[0 ]);
378
+ Set.insert (&buf[1 ]);
379
+ EXPECT_TRUE (Set.contains (&buf[0 ]));
380
+ EXPECT_TRUE (Set.contains (&buf[1 ]));
381
+ EXPECT_FALSE (Set.contains (&buf[3 ]));
382
+
383
+ Set.insert (&buf[1 ]);
384
+ EXPECT_TRUE (Set.contains (&buf[0 ]));
385
+ EXPECT_TRUE (Set.contains (&buf[1 ]));
386
+ EXPECT_FALSE (Set.contains (&buf[3 ]));
387
+
388
+ Set.erase (&buf[1 ]);
389
+ EXPECT_TRUE (Set.contains (&buf[0 ]));
390
+ EXPECT_FALSE (Set.contains (&buf[1 ]));
391
+
392
+ Set.insert (&buf[1 ]);
393
+ Set.insert (&buf[2 ]);
394
+ EXPECT_TRUE (Set.contains (&buf[0 ]));
395
+ EXPECT_TRUE (Set.contains (&buf[1 ]));
396
+ EXPECT_TRUE (Set.contains (&buf[2 ]));
397
+ }
0 commit comments