Skip to content

Commit 9098b70

Browse files
coarser util tests (#63)
1 parent 08c5468 commit 9098b70

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ endif()
172172

173173
## coarsening
174174

175+
_add_test( coarser_util )
176+
175177
_add_test( stepbystep_coarsen_and_multilevel )
176178

177179
_add_test (heavy_edge_preprocessing)

tests/coarser_util.cpp

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
Copyright 2024 Huawei Technologies Co., Ltd.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
@author Toni Boehnlein, Benjamin Lozes, Pal Andras Papp, Raphael S. Steiner
17+
*/
18+
19+
#define BOOST_TEST_MODULE COARSER_UTIL_TEST
20+
#include <boost/test/unit_test.hpp>
21+
22+
#include <set>
23+
24+
#include "osp/coarser/coarser_util.hpp"
25+
#include "osp/graph_implementations/adj_list_impl/compact_sparse_graph.hpp"
26+
27+
using namespace osp;
28+
using namespace osp::coarser_util;
29+
30+
using GraphType = Compact_Sparse_Graph<true, true, true, true, true>;
31+
32+
BOOST_AUTO_TEST_CASE(ContractionMapValidity) {
33+
const std::vector<vertex_idx_t<GraphType>> contractionmap1 = {0, 1, 2, 3};
34+
BOOST_CHECK(check_valid_contraction_map<GraphType>(contractionmap1));
35+
36+
const std::vector<vertex_idx_t<GraphType>> contractionmap2 = {1, 2, 3};
37+
BOOST_CHECK(not check_valid_contraction_map<GraphType>(contractionmap2));
38+
39+
const std::vector<vertex_idx_t<GraphType>> contractionmap3 = {0, 1, 3, 4};
40+
BOOST_CHECK(not check_valid_contraction_map<GraphType>(contractionmap3));
41+
42+
const std::vector<vertex_idx_t<GraphType>> contractionmap4 = {0, 1, 0, 1};
43+
BOOST_CHECK(check_valid_contraction_map<GraphType>(contractionmap4));
44+
45+
const std::vector<vertex_idx_t<GraphType>> contractionmap5 = {2, 1, 2, 0, 1, 1};
46+
BOOST_CHECK(check_valid_contraction_map<GraphType>(contractionmap5));
47+
}
48+
49+
BOOST_AUTO_TEST_CASE(ExpansionMapValidity) {
50+
const std::vector<std::vector<vertex_idx_t<GraphType>>> expansionmap1 = {{0}, {1}, {2}, {3}};
51+
BOOST_CHECK(check_valid_expansion_map<GraphType>(expansionmap1));
52+
53+
const std::vector<std::vector<vertex_idx_t<GraphType>>> expansionmap2 = {{0}, {2}, {3}};
54+
BOOST_CHECK(not check_valid_expansion_map<GraphType>(expansionmap2));
55+
56+
const std::vector<std::vector<vertex_idx_t<GraphType>>> expansionmap3 = {{0, 3}};
57+
BOOST_CHECK(not check_valid_expansion_map<GraphType>(expansionmap3));
58+
59+
const std::vector<std::vector<vertex_idx_t<GraphType>>> expansionmap4 = {{0, 3}, {2, 1, 4}, {5}};
60+
BOOST_CHECK(check_valid_expansion_map<GraphType>(expansionmap4));
61+
62+
const std::vector<std::vector<vertex_idx_t<GraphType>>> expansionmap5 = {{0}, {}, {2}, {3}, {1}};
63+
BOOST_CHECK(not check_valid_expansion_map<GraphType>(expansionmap5));
64+
}
65+
66+
BOOST_AUTO_TEST_CASE(ContractionMapCoarsening) {
67+
std::set<std::pair<vertex_idx_t<GraphType>, vertex_idx_t<GraphType>>> edges({{0, 1}, {1, 2}});
68+
GraphType graph(6, edges);
69+
70+
GraphType coarseGraph1;
71+
72+
std::vector<vertex_idx_t<GraphType>> contractionMap({0, 0, 1, 1, 2, 3});
73+
BOOST_CHECK(construct_coarse_dag(graph, coarseGraph1, contractionMap));
74+
BOOST_CHECK(contractionMap == std::vector<vertex_idx_t<GraphType>>({0, 0, 1, 1, 2, 3}));
75+
76+
BOOST_CHECK_EQUAL(coarseGraph1.num_vertices(), 4);
77+
BOOST_CHECK_EQUAL(coarseGraph1.num_edges(), 1);
78+
79+
BOOST_CHECK_EQUAL(coarseGraph1.out_degree(0), 1);
80+
BOOST_CHECK_EQUAL(coarseGraph1.out_degree(1), 0);
81+
BOOST_CHECK_EQUAL(coarseGraph1.out_degree(2), 0);
82+
83+
BOOST_CHECK_EQUAL(coarseGraph1.in_degree(0), 0);
84+
BOOST_CHECK_EQUAL(coarseGraph1.in_degree(1), 1);
85+
BOOST_CHECK_EQUAL(coarseGraph1.in_degree(2), 0);
86+
87+
for (const auto &vert : coarseGraph1.children(0)) {
88+
BOOST_CHECK_EQUAL(vert, 1);
89+
}
90+
91+
for (const auto &vert : coarseGraph1.parents(1)) {
92+
BOOST_CHECK_EQUAL(vert, 0);
93+
}
94+
}

0 commit comments

Comments
 (0)