-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
99 lines (72 loc) · 2.21 KB
/
Copy pathtest.cpp
File metadata and controls
99 lines (72 loc) · 2.21 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
#include "pch.h"
#include "HashTable.h"
TEST(Test1, Insert) {
Value value1(10, 20);
Value value2(30, 40);
Value value3(50, 60);
Value value4(70, 80);
pair <Key, Value> pair1("key1", value1);
pair <Key, Value> pair2("key2", value2);
pair <Key, Value> pair3("key3", value3);
pair <Key, Value> pair4("key3", value4);
HashTable* table = new HashTable();
EXPECT_EQ(true, table->insert(pair1.first, pair1.second));
EXPECT_EQ(true, table->insert(pair2.first, pair2.second));
EXPECT_EQ(true, table->insert(pair3.first, pair3.second));
EXPECT_EQ(false, table->insert(pair1.first, pair1.second));
table->erase(pair3.first);
EXPECT_EQ(true, table->insert(pair4.first, pair4.second));
delete table;
}
TEST(Test2, Contain) {
Value value1(10, 20);
pair <Key, Value> pair1("key1", value1);
HashTable* table = new HashTable();
EXPECT_EQ(false, table->contains(pair1.first));
table->insert(pair1.first, pair1.second);
EXPECT_EQ(true, table->contains(pair1.first));
table->erase(pair1.first);
EXPECT_EQ(false, table->contains(pair1.first));
delete table;
}
TEST(Test3, Erase) {
Value value1(10, 20);
pair <Key, Value> pair1("key1", value1);
HashTable* table = new HashTable();
EXPECT_EQ(false, table->erase(pair1.first));
table->insert(pair1.first, pair1.second);
EXPECT_EQ(true, table->erase(pair1.first));
delete table;
}
TEST(Test4, At) {
Value value1(10, 20);
pair <Key, Value> pair1("key1", value1);
HashTable* table = new HashTable();
try {
table->at(pair1.first);
}
catch (std::invalid_argument& e) {
table->insert(pair1.first, pair1.second); //ïîïðàâèòü ñ value
Value& value = table->at("key1");
EXPECT_EQ(10, value.age);
EXPECT_EQ(20, value.weight);
EXPECT_EQ("key1", pair1.first);
}
delete table;
}
TEST(Test5, Operator) {
Value value1(10, 20);
pair <Key, Value> pair1("key1", value1);
HashTable* table = new HashTable();
try {
(*table)["key1"];
}
catch (std::invalid_argument& e) { //value
table->insert(pair1.first, pair1.second);
Value& value = (*table)["key1"];
EXPECT_EQ(10, value.age);
EXPECT_EQ(20, value.weight);
EXPECT_EQ("key1", pair1.first);
}
delete table;
}