Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
N-Maas committed Dec 17, 2024
1 parent 3bd8536 commit bd91250
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/lib_generic_impls.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* This file is part of Mt-KaHyPar.
*
* Copyright (C) 2023 Tobias Heuer <tobias.heuer@kit.edu>
* Copyright (C) 2024 Nikolai Maas <nikolai.maas@kit.edu>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down
55 changes: 55 additions & 0 deletions tests/interface/interface_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ namespace mt_kahypar {
mt_kahypar_hypergraph_t hypergraph = mt_kahypar_create_hypergraph(
context, num_vertices, num_hyperedges, hyperedge_indices.get(),
hyperedges.get(), nullptr, vertex_weights.get(), &error);
ASSERT_FALSE(mt_kahypar_is_graph(hypergraph));

ASSERT_EQ(2, mt_kahypar_hypernode_degree(hypergraph, 0));
ASSERT_EQ(1, mt_kahypar_hypernode_degree(hypergraph, 1));
Expand All @@ -346,6 +347,60 @@ namespace mt_kahypar {
mt_kahypar_free_hypergraph(hypergraph);
}

TEST(MtKaHyPar, GetsPropertiesOfGraphWithNodeWeights) {
mt_kahypar_error_t error;
mt_kahypar_context_t* context = mt_kahypar_context_from_preset(DEFAULT);
const mt_kahypar_hypernode_id_t num_vertices = 5;
const mt_kahypar_hyperedge_id_t num_hyperedges = 6;

std::unique_ptr<mt_kahypar_hypernode_weight_t[]> vertex_weights =
std::make_unique<mt_kahypar_hypernode_weight_t[]>(7);
vertex_weights[0] = 1; vertex_weights[1] = 2; vertex_weights[2] = 3;
vertex_weights[3] = 4; vertex_weights[4] = 5;

std::unique_ptr<mt_kahypar_hypernode_id_t[]> edges =
std::make_unique<mt_kahypar_hypernode_id_t[]>(12);
edges[0] = 0; edges[1] = 1;
edges[2] = 0; edges[3] = 2;
edges[4] = 1; edges[5] = 2;
edges[6] = 1; edges[7] = 3;
edges[8] = 2; edges[9] = 3;
edges[10] = 3; edges[11] = 4;

mt_kahypar_hypergraph_t graph = mt_kahypar_create_graph(
context, num_vertices, num_hyperedges, edges.get(), nullptr, vertex_weights.get(), &error);
ASSERT_TRUE(mt_kahypar_is_graph(graph));

ASSERT_EQ(2, mt_kahypar_hypernode_degree(graph, 0));
ASSERT_EQ(3, mt_kahypar_hypernode_degree(graph, 1));
ASSERT_EQ(3, mt_kahypar_hypernode_degree(graph, 2));
ASSERT_EQ(3, mt_kahypar_hypernode_degree(graph, 3));
ASSERT_EQ(1, mt_kahypar_hypernode_degree(graph, 4));

for (size_t i = 0; i < 5; ++i) {
ASSERT_EQ(vertex_weights[i], mt_kahypar_hypernode_weight(graph, i));
}
for (size_t i = 0; i < 12; ++i) {
ASSERT_EQ(1, mt_kahypar_hyperedge_weight(graph, i));
ASSERT_EQ(2, mt_kahypar_hyperedge_size(graph, i));
}

ASSERT_EQ(0, mt_kahypar_edge_source(graph, 0)); ASSERT_EQ(1, mt_kahypar_edge_target(graph, 0));
ASSERT_EQ(0, mt_kahypar_edge_source(graph, 1)); ASSERT_EQ(2, mt_kahypar_edge_target(graph, 1));
ASSERT_EQ(1, mt_kahypar_edge_source(graph, 2)); ASSERT_EQ(0, mt_kahypar_edge_target(graph, 2));
ASSERT_EQ(1, mt_kahypar_edge_source(graph, 3)); ASSERT_EQ(2, mt_kahypar_edge_target(graph, 3));
ASSERT_EQ(1, mt_kahypar_edge_source(graph, 4)); ASSERT_EQ(3, mt_kahypar_edge_target(graph, 4));
ASSERT_EQ(2, mt_kahypar_edge_source(graph, 5)); ASSERT_EQ(0, mt_kahypar_edge_target(graph, 5));
ASSERT_EQ(2, mt_kahypar_edge_source(graph, 6)); ASSERT_EQ(1, mt_kahypar_edge_target(graph, 6));
ASSERT_EQ(2, mt_kahypar_edge_source(graph, 7)); ASSERT_EQ(3, mt_kahypar_edge_target(graph, 7));
ASSERT_EQ(3, mt_kahypar_edge_source(graph, 8)); ASSERT_EQ(1, mt_kahypar_edge_target(graph, 8));
ASSERT_EQ(3, mt_kahypar_edge_source(graph, 9)); ASSERT_EQ(2, mt_kahypar_edge_target(graph, 9));
ASSERT_EQ(3, mt_kahypar_edge_source(graph, 10)); ASSERT_EQ(4, mt_kahypar_edge_target(graph, 10));
ASSERT_EQ(4, mt_kahypar_edge_source(graph, 11)); ASSERT_EQ(3, mt_kahypar_edge_target(graph, 11));

mt_kahypar_free_hypergraph(graph);
}

TEST(MtKaHyPar, IteratesOverUnweightedStaticHypergraph) {
mt_kahypar_error_t error;
mt_kahypar_context_t* context = mt_kahypar_context_from_preset(DEFAULT);
Expand Down

0 comments on commit bd91250

Please sign in to comment.