-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_HashTable.cpp
More file actions
124 lines (99 loc) · 2.93 KB
/
test_HashTable.cpp
File metadata and controls
124 lines (99 loc) · 2.93 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <gtest.h>
#include "string"
#include "Polynomials.h"
#include "HashTable.h"
class HashTableTest : public:: testing:: Test {
protected:
HashTableOpenAdress tab;
std::string str1 = "x^2y^0z^0+x^0y^0z^0";
Polynomials poly = Polynomials(str1);
virtual void SetUp() {
tab = HashTableOpenAdress(100000);
for (int i = 0; i < 100000; i++) {
std::string name = std:: to_string(i);
tab.insert(name, poly);
}
}
virtual void TearDown() {
}
};
// --------------- POSITIVE TESTS ---------------- //
// SMOKE //
TEST(HashTable, can_create_table) {
ASSERT_NO_THROW(HashTableOpenAdress tab);
}
TEST(HashTable, can_create_table_fix_len) {
ASSERT_NO_THROW(HashTableOpenAdress tab(10));
}
TEST(HashTable, can_copy_table) {
HashTableOpenAdress tab1;
ASSERT_NO_THROW(HashTableOpenAdress(tab1));
}
TEST(HashTable, can_asign_table) {
HashTableOpenAdress tab1;
HashTableOpenAdress tab2;
ASSERT_NO_THROW(tab1 = tab2);
}
// FUNCTIONS //
TEST_F(HashTableTest, can_find_on_exist_key) {
EXPECT_EQ(1, tab.find("0"));
}
TEST_F(HashTableTest, can_find_on_unexist_key) {
EXPECT_EQ(0, tab.find("111111n"));
}
TEST_F(HashTableTest, can_erase_on_exist_key) {
tab.erase("90");
EXPECT_EQ(0, tab.find("90"));
}
TEST_F(HashTableTest, size_down_after_erase) {
int size1 = tab.GetCountItems();
tab.erase("94");
int size2 = tab.GetCountItems();
EXPECT_EQ(size1-1, size2);
}
TEST_F(HashTableTest, can_erase_on_unexist_key) {
tab.erase("3333333g");
EXPECT_EQ(0, tab.find("3333333g"));
}
TEST_F(HashTableTest, can_insert_on_unexist_key) {
std::string name = "nnnnnname";
std::string str1 = "x^2y^0z^0+x^0y^0z^0";
Polynomials poly = Polynomials(str1);
tab.insert(name, poly);
EXPECT_EQ(1, tab.find(name));
}
TEST_F(HashTableTest, size_up_after_insert) {
std::string name = "n110101";
std::string str1 = "x^2y^0z^0+x^0y^0z^0";
Polynomials poly = Polynomials(str1);
int size1 = tab.GetCountItems();
tab.insert(name, poly);
int size2 = tab.GetCountItems();
EXPECT_EQ(size1+1, size2);
}
TEST_F(HashTableTest, can_insert_on_unexist_key_repacking) {
std::string name = std:: to_string(900099);
std::string str1 = "x^2y^0z^0+x^0y^0z^0";
Polynomials poly = Polynomials(str1);
tab.insert(name, poly);
EXPECT_EQ(1, tab.find(name));
}
TEST(HashTable, size_up_after_repacking) {
HashTableOpenAdress tab1;
std::string name1 = std::to_string(900099999);
std::string name2 = std::to_string(99999);
std::string str1 = "x^2y^0z^0+x^0y^0z^0";
Polynomials poly = Polynomials(str1);
tab1.insert(name1, poly);
int size1 = tab1.GetSize();
tab1.insert(name2, poly);
EXPECT_EQ(size1*2, tab1.GetSize());
}
TEST(HashTable, can_get_size) {
HashTableOpenAdress tab(10);
EXPECT_EQ(10, tab.GetSize());
}
// --------------- NEGATIVE TESTS ---------------- //
TEST(HashTable, cant_create_tab_negative_len) {
ASSERT_ANY_THROW(HashTableOpenAdress tab1(-1));
}