Skip to content

Commit 1f661f5

Browse files
committed
Move sharing map and sharing node unit tests to util
1 parent 47463a3 commit 1f661f5

File tree

3 files changed

+67
-63
lines changed

3 files changed

+67
-63
lines changed

unit/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ SRC += unit_tests.cpp \
2727
java_bytecode/java_utils_test.cpp \
2828
java_bytecode/inherited_static_fields/inherited_static_fields.cpp \
2929
pointer-analysis/custom_value_set_analysis.cpp \
30-
sharing_node.cpp \
31-
sharing_map.cpp \
3230
solvers/refinement/string_constraint_generator_valueof/calculate_max_string_length.cpp \
3331
solvers/refinement/string_constraint_generator_valueof/get_numeric_value_from_character.cpp \
3432
solvers/refinement/string_constraint_generator_valueof/is_digit_with_radix.cpp \
@@ -47,6 +45,8 @@ SRC += unit_tests.cpp \
4745
util/message.cpp \
4846
util/optional.cpp \
4947
util/parameter_indices.cpp \
48+
util/sharing_node.cpp \
49+
util/sharing_map.cpp \
5050
util/simplify_expr.cpp \
5151
util/small_shared_two_way_ptr.cpp \
5252
util/string_utils/split_string.cpp \

unit/sharing_map.cpp renamed to unit/util/sharing_map.cpp

+32-28
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ void sharing_map_interface_test()
4343
{
4444
smt sm;
4545

46-
smt::const_find_type r1=sm.insert(std::make_pair("i", "0"));
46+
smt::const_find_type r1 = sm.insert(std::make_pair("i", "0"));
4747
REQUIRE(r1.second);
4848

49-
smt::const_find_type r2=sm.insert("j", "1");
49+
smt::const_find_type r2 = sm.insert("j", "1");
5050
REQUIRE(r2.second);
5151

52-
smt::const_find_type r3=sm.insert(std::make_pair("i", "0"));
52+
smt::const_find_type r3 = sm.insert(std::make_pair("i", "0"));
5353
REQUIRE(!r3.second);
5454

5555
REQUIRE(sm.size() == 2);
@@ -61,12 +61,12 @@ void sharing_map_interface_test()
6161
smt sm1;
6262
smt sm2(sm1);
6363

64-
smt::find_type r1=sm1.place("i", "0");
64+
smt::find_type r1 = sm1.place("i", "0");
6565
REQUIRE(r1.second);
6666
REQUIRE(!sm2.has_key("i"));
6767

68-
std::string &s1=r1.first;
69-
s1="1";
68+
std::string &s1 = r1.first;
69+
s1 = "1";
7070

7171
REQUIRE(sm1.at("i") == "1");
7272
}
@@ -77,36 +77,40 @@ void sharing_map_interface_test()
7777
sm.insert("i", "0");
7878
sm.insert("j", "1");
7979

80-
const smt &sm2=sm;
80+
const smt &sm2 = sm;
8181

8282
std::string s;
83-
s=sm2.at("i");
83+
s = sm2.at("i");
8484
REQUIRE(s == "0");
8585

86-
try {
86+
try
87+
{
8788
sm2.at("k");
8889
REQUIRE(false);
89-
} catch (...) {}
90+
}
91+
catch(...)
92+
{
93+
}
9094

91-
s=sm2.at("j");
95+
s = sm2.at("j");
9296
REQUIRE(s == "1");
9397

9498
REQUIRE(sm.has_key("i"));
9599
REQUIRE(sm.has_key("j"));
96100
REQUIRE(!sm.has_key("k"));
97101

98-
std::string &s2=sm.at("i");
99-
s2="3";
102+
std::string &s2 = sm.at("i");
103+
s2 = "3";
100104
REQUIRE(sm2.at("i") == "3");
101105

102106
REQUIRE(sm.size() == 2);
103107

104-
smt::find_type r=sm.find("i");
108+
smt::find_type r = sm.find("i");
105109
REQUIRE(r.second);
106-
r.first="4";
110+
r.first = "4";
107111
REQUIRE(sm2.at("i") == "4");
108112

109-
smt::const_find_type rc=sm2.find("k");
113+
smt::const_find_type rc = sm2.find("k");
110114
REQUIRE(!rc.second);
111115
}
112116

@@ -154,27 +158,27 @@ void sharing_map_interface_test()
154158
sm["i"];
155159
REQUIRE(sm.has_key("i"));
156160

157-
sm["i"]="0";
161+
sm["i"] = "0";
158162
REQUIRE(sm.at("i") == "0");
159163

160-
sm["j"]="1";
164+
sm["j"] = "1";
161165
REQUIRE(sm.at("j") == "1");
162166
}
163167
}
164168

165169
void sharing_map_copy_test()
166170
{
167171
smt sm1;
168-
const smt &sm2=sm1;
172+
const smt &sm2 = sm1;
169173

170174
fill(sm1);
171175

172176
REQUIRE(sm2.find("i").first == "0");
173177
REQUIRE(sm2.find("j").first == "1");
174178
REQUIRE(sm2.find("k").first == "2");
175179

176-
smt sm3=sm1;
177-
const smt &sm4=sm3;
180+
smt sm3 = sm1;
181+
const smt &sm4 = sm3;
178182

179183
REQUIRE(sm3.erase("l") == 0);
180184
REQUIRE(sm3.erase("i") == 1);
@@ -195,7 +199,7 @@ class some_keyt
195199

196200
bool operator==(const some_keyt &other) const
197201
{
198-
return s==other.s;
202+
return s == other.s;
199203
}
200204
};
201205

@@ -237,9 +241,9 @@ void sharing_map_view_test()
237241
SECTION("View")
238242
{
239243
smt sm;
240-
244+
241245
fill(sm);
242-
246+
243247
smt::viewt view;
244248
sm.get_view(view);
245249

@@ -270,7 +274,7 @@ void sharing_map_view_test()
270274
fill(sm1);
271275

272276
smt sm2(sm1);
273-
277+
274278
smt::delta_viewt delta_view;
275279

276280
sm1.get_delta_view(sm2, delta_view);
@@ -287,10 +291,10 @@ void sharing_map_view_test()
287291
fill(sm1);
288292

289293
smt sm2(sm1);
290-
auto r=sm2.find("i");
294+
auto r = sm2.find("i");
291295
REQUIRE(r.second);
292-
r.first="3";
293-
296+
r.first = "3";
297+
294298
smt::delta_viewt delta_view;
295299

296300
sm1.get_delta_view(sm2, delta_view);

unit/sharing_node.cpp renamed to unit/util/sharing_node.cpp

+33-33
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
/// \file Tests for sharing-node utility
44

5-
#include <util/sharing_node.h>
65
#include <testing-utils/catch.hpp>
6+
#include <util/sharing_node.h>
77

88
void sharing_node_test()
99
{
@@ -12,7 +12,7 @@ void sharing_node_test()
1212
SECTION("Internal nodes")
1313
{
1414
snt sn1;
15-
const snt &sn2=sn1;
15+
const snt &sn2 = sn1;
1616

1717
const snt *p2;
1818

@@ -27,22 +27,22 @@ void sharing_node_test()
2727
REQUIRE(!sn2.is_container());
2828
REQUIRE(!sn2.is_leaf());
2929

30-
REQUIRE(sn2.get_sub().size()==3);
30+
REQUIRE(sn2.get_sub().size() == 3);
3131

32-
p2=sn2.find_child(0);
33-
REQUIRE(p2!=nullptr);
32+
p2 = sn2.find_child(0);
33+
REQUIRE(p2 != nullptr);
3434

35-
p2=sn1.find_child(0);
36-
REQUIRE(p2!=nullptr);
35+
p2 = sn1.find_child(0);
36+
REQUIRE(p2 != nullptr);
3737

38-
p2=sn2.find_child(3);
39-
REQUIRE(p2==nullptr);
38+
p2 = sn2.find_child(3);
39+
REQUIRE(p2 == nullptr);
4040

41-
p2=sn1.find_child(3);
42-
REQUIRE(p2==nullptr);
41+
p2 = sn1.find_child(3);
42+
REQUIRE(p2 == nullptr);
4343

4444
sn1.remove_child(0);
45-
REQUIRE(sn2.get_sub().size()==2);
45+
REQUIRE(sn2.get_sub().size() == 2);
4646

4747
sn1.clear();
4848
REQUIRE(sn2.is_empty());
@@ -58,65 +58,65 @@ void sharing_node_test()
5858
sn1.add_child(0);
5959
sn1.add_child(1);
6060

61-
p1=sn1.add_child(2);
62-
p2=p1;
61+
p1 = sn1.add_child(2);
62+
p2 = p1;
6363

64-
REQUIRE(p1->find_leaf("a")==nullptr);
65-
REQUIRE(p2->find_leaf("a")==nullptr);
64+
REQUIRE(p1->find_leaf("a") == nullptr);
65+
REQUIRE(p2->find_leaf("a") == nullptr);
6666

6767
p1->place_leaf("a", "b");
68-
REQUIRE(p2->get_container().size()==1);
68+
REQUIRE(p2->get_container().size() == 1);
6969
p1->place_leaf("c", "d");
70-
REQUIRE(p2->get_container().size()==2);
70+
REQUIRE(p2->get_container().size() == 2);
7171

7272
REQUIRE(p2->is_container());
7373

7474
p1->remove_leaf("a");
75-
REQUIRE(p2->get_container().size()==1);
75+
REQUIRE(p2->get_container().size() == 1);
7676
}
7777

7878
SECTION("Copy test 1")
7979
{
8080
snt sn1;
8181
snt sn2;
8282

83-
sn2=sn1;
84-
REQUIRE(sn1.data.use_count()==3);
85-
REQUIRE(sn2.data.use_count()==3);
83+
sn2 = sn1;
84+
REQUIRE(sn1.data.use_count() == 3);
85+
REQUIRE(sn2.data.use_count() == 3);
8686

8787
sn1.add_child(0);
88-
REQUIRE(sn1.data.use_count()==1);
88+
REQUIRE(sn1.data.use_count() == 1);
8989
// the newly created node is empty as well
90-
REQUIRE(sn2.data.use_count()==3);
90+
REQUIRE(sn2.data.use_count() == 3);
9191

92-
sn2=sn1;
93-
REQUIRE(sn2.data.use_count()==2);
92+
sn2 = sn1;
93+
REQUIRE(sn2.data.use_count() == 2);
9494
}
9595

9696
SECTION("Copy test 2")
9797
{
9898
snt sn1;
99-
const snt &sn1c=sn1;
99+
const snt &sn1c = sn1;
100100
snt *p;
101101

102-
p=sn1.add_child(0);
102+
p = sn1.add_child(0);
103103
p->place_leaf("x", "y");
104104

105-
p=sn1.add_child(1);
105+
p = sn1.add_child(1);
106106
p->place_leaf("a", "b");
107107
p->place_leaf("c", "d");
108108

109109
snt sn2;
110-
const snt &sn2c=sn2;
111-
sn2=sn1;
110+
const snt &sn2c = sn2;
111+
sn2 = sn1;
112112

113113
REQUIRE(sn1.is_internal());
114114
REQUIRE(sn2.is_internal());
115115

116116
sn1.remove_child(0);
117-
REQUIRE(sn1c.get_sub().size()==1);
117+
REQUIRE(sn1c.get_sub().size() == 1);
118118

119-
REQUIRE(sn2c.get_sub().size()==2);
119+
REQUIRE(sn2c.get_sub().size() == 2);
120120
}
121121
}
122122

0 commit comments

Comments
 (0)