forked from ad-freiburg/qlever
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HashSetTest.cpp
58 lines (49 loc) · 1.44 KB
/
HashSetTest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright 2015, University of Freiburg,
// Chair of Algorithms and Data Structures.
// Author: Niklas Schnelle ([email protected])
#include <gtest/gtest.h>
#include <utility>
#include <vector>
#include "../src/util/HashSet.h"
// Note: Since the HashSet class is a wrapper for a well tested hash set
// implementation the following tests only check the API for functionality and
// sanity
TEST(HashSetTest, sizeAndInsert) {
ad_utility::HashSet<int> set;
ASSERT_EQ(set.size(), 0u);
set.insert(42);
set.insert(41);
set.insert(12);
ASSERT_EQ(set.size(), 3u);
};
TEST(HashSetTest, insertRange) {
ad_utility::HashSet<int> set;
std::vector<int> values = {2, 3, 5, 7, 11};
set.insert(values.begin() + 1, values.end());
ASSERT_EQ(set.count(2), 0u);
ASSERT_EQ(set.count(4), 0u);
ASSERT_EQ(set.count(8), 0u);
ASSERT_EQ(set.count(3), 1u);
ASSERT_EQ(set.count(5), 1u);
ASSERT_EQ(set.count(7), 1u);
ASSERT_EQ(set.count(11), 1u);
};
TEST(HashSetTest, iterator) {
ad_utility::HashSet<int> set;
set.insert(41);
set.insert(12);
ASSERT_TRUE(++(++set.begin()) == set.end());
ad_utility::HashSet<int> settwo;
settwo.insert(set.begin(), set.end());
ASSERT_EQ(settwo.size(), 2u);
ASSERT_EQ(settwo.count(41), 1u);
ASSERT_EQ(settwo.count(12), 1u);
};
TEST(HashSetTest, erase) {
ad_utility::HashSet<int> set;
set.insert(41);
set.insert(12);
ASSERT_EQ(set.size(), 2u);
set.erase(41);
ASSERT_EQ(set.size(), 1u);
};