Skip to content

Commit 768d94c

Browse files
committed
Use catch2 magic to make tests more readable
1 parent 8c98894 commit 768d94c

File tree

1 file changed

+8
-29
lines changed

1 file changed

+8
-29
lines changed

tests/test-middle.cpp

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,9 +1005,8 @@ TEMPLATE_TEST_CASE("middle: add relation with attributes", "",
10051005
}
10061006
}
10071007

1008-
class test_pending_processor : public middle_t::pending_processor
1008+
struct test_pending_processor : public middle_t::pending_processor
10091009
{
1010-
public:
10111010
test_pending_processor() = default;
10121011

10131012
void enqueue_ways(osmid_t id) override { m_way_ids.push_back(id); }
@@ -1016,26 +1015,6 @@ class test_pending_processor : public middle_t::pending_processor
10161015
void process_ways() override {}
10171016
void process_relations() override {}
10181017

1019-
void check_way_ids_equal_to(std::initializer_list<osmid_t> list) noexcept
1020-
{
1021-
REQUIRE(compare(m_way_ids, list));
1022-
}
1023-
1024-
void check_rel_ids_equal_to(std::initializer_list<osmid_t> list) noexcept
1025-
{
1026-
REQUIRE(compare(m_rel_ids, list));
1027-
}
1028-
1029-
private:
1030-
static bool compare(std::vector<osmid_t> const &l1,
1031-
std::initializer_list<osmid_t> const &l2) noexcept
1032-
{
1033-
if (l1.size() != l2.size()) {
1034-
return false;
1035-
}
1036-
return std::equal(l1.cbegin(), l1.cend(), l2.begin());
1037-
}
1038-
10391018
std::vector<osmid_t> m_way_ids;
10401019
std::vector<osmid_t> m_rel_ids;
10411020
};
@@ -1087,7 +1066,7 @@ TEMPLATE_TEST_CASE("middle: change nodes in way", "", options_slim_default,
10871066
REQUIRE_FALSE(mid->has_pending());
10881067
test_pending_processor proc;
10891068
mid->iterate_ways(proc);
1090-
proc.check_way_ids_equal_to({});
1069+
REQUIRE(proc.m_way_ids.empty());
10911070

10921071
mid->commit();
10931072
}
@@ -1108,7 +1087,7 @@ TEMPLATE_TEST_CASE("middle: change nodes in way", "", options_slim_default,
11081087
REQUIRE(mid->has_pending());
11091088
test_pending_processor proc;
11101089
mid->iterate_ways(proc);
1111-
proc.check_way_ids_equal_to({20});
1090+
REQUIRE_THAT(proc.m_way_ids, Catch::Equals<osmid_t>({20}));
11121091

11131092
check_way(mid, way20);
11141093
check_way_nodes(mid, way20.id(), {&node10a, &node11});
@@ -1140,7 +1119,7 @@ TEMPLATE_TEST_CASE("middle: change nodes in way", "", options_slim_default,
11401119
REQUIRE(mid->has_pending());
11411120
test_pending_processor proc;
11421121
mid->iterate_ways(proc);
1143-
proc.check_way_ids_equal_to({20, 22});
1122+
REQUIRE_THAT(proc.m_way_ids, Catch::Equals<osmid_t>({20, 22}));
11441123

11451124
check_way(mid, way20);
11461125
check_way_nodes(mid, way20.id(), {&node10a, &node11});
@@ -1179,7 +1158,7 @@ TEMPLATE_TEST_CASE("middle: change nodes in way", "", options_slim_default,
11791158
REQUIRE_FALSE(mid->has_pending());
11801159
test_pending_processor proc;
11811160
mid->iterate_ways(proc);
1182-
proc.check_way_ids_equal_to({});
1161+
REQUIRE(proc.m_way_ids.empty());
11831162

11841163
mid->commit();
11851164
}
@@ -1248,7 +1227,7 @@ TEMPLATE_TEST_CASE("middle: change nodes in relation", "", options_slim_default,
12481227
test_pending_processor proc;
12491228
mid->iterate_relations(proc);
12501229

1251-
proc.check_rel_ids_equal_to({30});
1230+
REQUIRE_THAT(proc.m_rel_ids, Catch::Equals<osmid_t>({30}));
12521231
check_relation(mid, rel30);
12531232

12541233
mid->commit();
@@ -1267,10 +1246,10 @@ TEMPLATE_TEST_CASE("middle: change nodes in relation", "", options_slim_default,
12671246
REQUIRE(mid->has_pending());
12681247
test_pending_processor proc;
12691248
mid->iterate_ways(proc);
1270-
proc.check_way_ids_equal_to({20});
1249+
REQUIRE_THAT(proc.m_way_ids, Catch::Equals<osmid_t>({20}));
12711250

12721251
mid->iterate_relations(proc);
1273-
proc.check_rel_ids_equal_to({31});
1252+
REQUIRE_THAT(proc.m_rel_ids, Catch::Equals<osmid_t>({31}));
12741253
check_relation(mid, rel31);
12751254
}
12761255
}

0 commit comments

Comments
 (0)