6 #include <gtest/gtest.h>
12 TEST(HashSetTests, TestInt)
16 EXPECT_TRUE(hashSet.Size());
17 EXPECT_TRUE(hashSet.Contains(3));
18 EXPECT_FALSE(hashSet.Contains(8));
20 EXPECT_TRUE(hashSet.insert(8));
21 EXPECT_TRUE(hashSet.Contains(8));
22 EXPECT_FALSE(hashSet.insert(8));
24 EXPECT_TRUE(hashSet.Remove(1));
25 EXPECT_FALSE(hashSet.Contains(1));
26 EXPECT_FALSE(hashSet.Remove(1));
29 for (
auto & item : hashSet.Items())
31 EXPECT_EQ(sum, 0 + 2 + 3 + 4 + 5 + 6 + 7 + 8);
35 EXPECT_EQ(hashSet.Size(), 9u);
37 auto numRemoved = hashSet.RemoveWhere(
42 EXPECT_EQ(numRemoved, 4u);
45 EXPECT_EQ(hashSet.Size(), 0u);
48 TEST(HashSetTests, TestUniquePointer)
52 hashSet.
insert(std::make_unique<int>(0));
53 EXPECT_EQ(hashSet.
Size(), 1u);
55 hashSet.
Remove(std::make_unique<int>(0));
56 EXPECT_EQ(hashSet.
Size(), 1u);
59 EXPECT_EQ(hashSet.
Size(), 0u);
62 TEST(HashSetTests, TestPair)
67 auto result = hashSet.
insert({ 7, 70 });
69 EXPECT_EQ(hashSet.Size(), 3u);
72 result = hashSet.insert({ 1, 10 });
74 EXPECT_EQ(hashSet.Size(), 3u);
77 EXPECT_TRUE(hashSet.Contains({ 5, 50 }));
78 EXPECT_FALSE(hashSet.Contains({ 50, 5 }));
81 result = hashSet.Remove({ 5, 50 });
83 EXPECT_EQ(hashSet.Size(), 2u);
84 result = hashSet.Remove({ 5, 50 });
86 EXPECT_EQ(hashSet.Size(), 2u);
89 TEST(HashSetTests, TestIsSubsetOf)
95 EXPECT_TRUE(set12.IsSubsetOf(set12));
96 EXPECT_TRUE(set12.IsSubsetOf(set123));
97 EXPECT_TRUE(set12.IsSubsetOf(set1234));
98 EXPECT_FALSE(set123.IsSubsetOf(set12));
99 EXPECT_TRUE(set123.IsSubsetOf(set1234));
100 EXPECT_FALSE(set1234.IsSubsetOf(set12));
101 EXPECT_FALSE(set1234.IsSubsetOf(set123));
104 TEST(HashSetTests, TestUnionWith)
114 EXPECT_FALSE(result);
115 EXPECT_EQ(set123.Size(), 3u);
120 EXPECT_EQ(set12.Size(), 3u);
121 EXPECT_EQ(set12, set123);
125 EXPECT_FALSE(result);
130 EXPECT_EQ(set45.Size(), 5u);
131 EXPECT_TRUE(set123.IsEmpty());
134 TEST(HashSetTests, TestIntersectWith)
143 EXPECT_EQ(set123, set12);
145 set123.IntersectWith(set45);
146 EXPECT_EQ(set123.Size(), 0u);
151 set123.IntersectWithAndClear(set12);
153 EXPECT_EQ(set123.Size(), 2u);
154 EXPECT_EQ(set12.Size(), 0u);
157 TEST(HashSetTests, TestDifferenceWith)
165 const auto set12Copy = set12;
168 EXPECT_EQ(set123.Size(), 1u);
169 EXPECT_TRUE(set123.Contains(3));
172 EXPECT_EQ(set12, set12Copy);
178 set12.DifferenceWith(set123);
179 EXPECT_EQ(set12.Size(), 1u);
180 EXPECT_TRUE(set12.Contains(2));
183 set45.DifferenceWith(set123);
184 set45.DifferenceWith(set12);
185 EXPECT_EQ(set45.Size(), 2u);
188 set45.DifferenceWith(set45);
189 EXPECT_TRUE(set45.IsEmpty());
TEST(HashSetTests, TestInt)
void DifferenceWith(const HashSet< ItemType > &other)
bool insert(ItemType item)
std::size_t Size() const noexcept
void IntersectWith(const HashSet< ItemType > &other)
bool UnionWithAndClear(HashSet< ItemType > &other)
bool Remove(ItemType item)
bool UnionWith(const HashSet< ItemType > &other)