Skip to content

Commit

Permalink
[graph/test] Fix graph_test
Browse files Browse the repository at this point in the history
  • Loading branch information
ldhulipala committed Jan 14, 2022
1 parent a62d177 commit cddd911
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
2 changes: 0 additions & 2 deletions gbbs/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ struct symmetric_graph {
uintE packNeighbors(uintE id, P& p, uint8_t* tmp) {
uintE new_degree =
get_vertex(id).out_neighbors().pack(p, (std::tuple<uintE, W>*)tmp);
// std::cout << "Packed id = " << id << " old_degree = " <<
// v_data[id].degree << " new_degree = " << new_degree << std::endl;
v_data[id].degree = new_degree; // updates the degree
return new_degree;
}
Expand Down
25 changes: 11 additions & 14 deletions gbbs/unit_tests/graph_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ sym_ptr_graph_from_edges(sequence<std::tuple<uintE, uintE, Wgh>>& A, size_t n,
// Constructs and returns the following test graph with edge weights:
// 2 3
// 0 --- 1 --- 2
static inline gbbs::symmetric_ptr_graph<gbbs::symmetric_vertex, int>
static inline std::pair<gbbs::symmetric_ptr_graph<gbbs::symmetric_vertex, int>, symmetric_vertex<int>*>
ThreeNodeSymPtrGraphFromEdges() {
using edge = std::tuple<uintE, uintE, int>;
const uintE n = 3;
Expand All @@ -42,10 +42,7 @@ ThreeNodeSymPtrGraphFromEdges() {
edges[1] = std::make_tuple(1, 0, 2);
edges[2] = std::make_tuple(1, 2, 3);
edges[3] = std::make_tuple(2, 1, 3);
auto P = sym_ptr_graph_from_edges(edges, n);
auto& graph = P.first;
gbbs::free_array(P.second, graph.n);
return graph;
return sym_ptr_graph_from_edges(edges, n);
}

} // namespace
Expand Down Expand Up @@ -130,55 +127,58 @@ TEST(TestSymPtrGraphFromEdges, TestGraphWithSingletons) {
sequence<edge> edges(2);
edges[0] = std::make_tuple(0, 1, 1);
edges[1] = std::make_tuple(1, 0, 1);
std::cout << "In SymPtrGraph" << std::endl;
auto P = sym_ptr_graph_from_edges(edges, n);
auto& graph = P.first;
std::cout << "Created SymPtrGraph" << std::endl;

ASSERT_EQ(graph.n, n);
ASSERT_EQ(graph.get_vertex(0).out_degree(), 1);
ASSERT_EQ(graph.get_vertex(1).out_degree(), 1);
ASSERT_EQ(graph.get_vertex(2).out_degree(), 0);
ASSERT_EQ(graph.get_vertex(3).out_degree(), 0);
gbbs::free_array(P.second, graph.n);
std::cout << "Exiting SymPtrGraph" << std::endl;
}

TEST(TestSymPtrGraphFromEdges, EdgeSequenceConstructionWorks) {
// Graph diagram:
// 2 3
// 0 --- 1 --- 2
auto graph = ThreeNodeSymPtrGraphFromEdges();
auto graph_and_vtxs = ThreeNodeSymPtrGraphFromEdges();
auto& graph = graph_and_vtxs.first;
auto edges = graph.edges();
EXPECT_EQ(edges[0], std::make_tuple(0, 1, 2));
EXPECT_EQ(edges[1], std::make_tuple(1, 0, 2));
EXPECT_EQ(edges[2], std::make_tuple(1, 2, 3));
EXPECT_EQ(edges[3], std::make_tuple(2, 1, 3));
gbbs::free_array(graph_and_vtxs.second, graph.n);
}

TEST(TestSymPtrGraphFromEdges, MapEdgesWorks) {
// Graph diagram:
// 2 3
// 0 --- 1 --- 2
auto graph = ThreeNodeSymPtrGraphFromEdges();
auto graph_and_vtxs = ThreeNodeSymPtrGraphFromEdges();
auto& graph = graph_and_vtxs.first;
// NOTE: graph.mapEdges() does not return anything so we are testing it by
// disabling parallelism and sum the edge weights into a single variable for
// testing purposes.
int sum = 0;
auto map_fn = [&](uintE x, uintE y, int w) { sum += w; };
graph.mapEdges(map_fn, /*parallel_inner_map=*/false);
EXPECT_EQ(sum, /* 2 + 2 + 3 + 3 = */ 10);
gbbs::free_array(graph_and_vtxs.second, graph.n);
}

TEST(TestSymPtrGraphFromEdges, ReduceEdgesWorks) {
// Graph diagram:
// 2 3
// 0 --- 1 --- 2
auto graph = ThreeNodeSymPtrGraphFromEdges();
auto graph_and_vtxs = ThreeNodeSymPtrGraphFromEdges();
auto& graph = graph_and_vtxs.first;
auto map_fn = [](uintE x, uintE y, int w) -> int { return w; };
auto reduce_fn = parlay::make_monoid([](int a, int b) { return a + b; }, 0);
auto result = graph.reduceEdges(map_fn, reduce_fn);
EXPECT_EQ(result, /* 2 + 2 + 3 + 3 = */ 10);
gbbs::free_array(graph_and_vtxs.second, graph.n);
}

TEST(TestSymPtrGraphFromEdges, TestBrokenPath) {
Expand All @@ -196,10 +196,8 @@ TEST(TestSymPtrGraphFromEdges, TestBrokenPath) {
edges[3] = std::make_tuple(last_vtx_id, 0, 1);
edges[4] = std::make_tuple(1, last_vtx_id, 1);
edges[5] = std::make_tuple(last_vtx_id, 1, 1);
std::cout << "In SymPtrGraph" << std::endl;
auto P = sym_ptr_graph_from_edges(edges, n, /* is_sorted = */ false);
auto& G = P.first;
std::cout << "Created SymPtrGraph" << std::endl;

ASSERT_EQ(G.n, 11);
ASSERT_EQ(G.get_vertex(0).out_degree(), 2);
Expand All @@ -214,7 +212,6 @@ TEST(TestSymPtrGraphFromEdges, TestBrokenPath) {
ASSERT_EQ(G.get_vertex(9).out_degree(), 2);
ASSERT_EQ(G.get_vertex(10).out_degree(), 3);
gbbs::free_array(P.second, G.n);
std::cout << "Exiting SymPtrGraph" << std::endl;
}

TEST(TestSymPtrGraphCopy, TestGraphWithSingletons) {
Expand Down

0 comments on commit cddd911

Please sign in to comment.