-
Notifications
You must be signed in to change notification settings - Fork 29
/
test_hash_table.cpp
61 lines (53 loc) · 1.47 KB
/
test_hash_table.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
59
60
61
#include "catch2/catch_amalgamated.hpp"
#include "jumble/hash_table.hpp"
#include <string>
typedef jumble::HashTable<std::string>::SizeType SizeType;
TEST_CASE("Basic") {
jumble::HashTable<std::string> table;
table.clear();
REQUIRE(table.isEmpty());
table.insert("Alice");
table.insert("Alice");
table.insert("Darth");
REQUIRE(table.getSize() == (SizeType)2);
REQUIRE(table.has("Alice"));
REQUIRE(table.has("Darth"));
table.remove("Darth");
table.remove("Bob");
REQUIRE(table.has("Alice"));
REQUIRE(!table.has("Darth"));
REQUIRE(table.getSize() == (SizeType)1);
table.clear();
REQUIRE(table.getSize() == (SizeType)0);
}
TEST_CASE("Rehash") {
jumble::HashTable<std::string> table(100);
for (int i = 0; i < 100; ++i) {
table.insert(std::to_string(i));
}
REQUIRE(table.getSize() == (SizeType)100);
{
table.rehash(300);
REQUIRE(table.getSize() == (SizeType)100);
bool res = true;
for (int i = 0; i < 100; ++i) {
if (!table.has(std::to_string(i))) {
res = false;
break;
}
}
REQUIRE(res);
}
{
table.rehash(500);
REQUIRE(table.getSize() == (SizeType)100);
bool res = true;
for (int i = 0; i < 100; ++i) {
if (!table.has(std::to_string(i))) {
res = false;
break;
}
}
REQUIRE(res);
}
}