From 415de170b3a1f029204a425de4e19455d9d08f94 Mon Sep 17 00:00:00 2001 From: AntonChern Date: Wed, 25 Sep 2024 08:00:23 +0300 Subject: [PATCH] Add tests for GFD mining Add minimal GFD and GFD with multiple conclusion tests --- src/tests/test_gfd_mining.cpp | 53 +++++++++++++++++++ test_input_data/graph_data/blogs_graph.dot | 27 ++++++++++ test_input_data/graph_data/channels_graph.dot | 34 ++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 src/tests/test_gfd_mining.cpp create mode 100644 test_input_data/graph_data/blogs_graph.dot create mode 100644 test_input_data/graph_data/channels_graph.dot diff --git a/src/tests/test_gfd_mining.cpp b/src/tests/test_gfd_mining.cpp new file mode 100644 index 0000000000..c269940583 --- /dev/null +++ b/src/tests/test_gfd_mining.cpp @@ -0,0 +1,53 @@ +#include +#include + +#include "algorithms/algo_factory.h" +#include "algorithms/gfd/gfd_miner.h" +#include "config/names.h" +#include "csv_config_util.h" + +using namespace algos; +using algos::StdParamsMap; + +namespace tests { + +namespace { + +auto current_path = kTestDataDir / "graph_data"; + +class GfdMiningTest : public ::testing::Test { +public: + static std::unique_ptr CreateGfdMiningInstance( + std::filesystem::path const& graph_path, std::size_t const& k, + std::size_t const& sigma) { + StdParamsMap option_map = {{config::names::kGraphData, graph_path}, + {config::names::kGfdK, k}, + {config::names::kGfdSigma, sigma}}; + return algos::CreateAndLoadAlgorithm(option_map); + } +}; + +TEST_F(GfdMiningTest, TestMinGfd) { + auto graph_path = current_path / "blogs_graph.dot"; + auto algorithm = CreateGfdMiningInstance(graph_path, 2, 3); + algorithm->Execute(); + std::vector gfd_list = algorithm->GfdList(); + int expected_size = gfd_list.size(); + algorithm = CreateGfdMiningInstance(graph_path, 3, 3); + algorithm->Execute(); + gfd_list = algorithm->GfdList(); + ASSERT_EQ(expected_size, gfd_list.size()); +} + +TEST_F(GfdMiningTest, TestComplexConclusion) { + auto graph_path = current_path / "channels_graph.dot"; + auto algorithm = CreateGfdMiningInstance(graph_path, 2, 3); + int expected_size = 1; + algorithm->Execute(); + std::vector gfd_list = algorithm->GfdList(); + ASSERT_EQ(expected_size, gfd_list.size()); +} + +} // namespace + +} // namespace tests diff --git a/test_input_data/graph_data/blogs_graph.dot b/test_input_data/graph_data/blogs_graph.dot new file mode 100644 index 0000000000..9edd0b7314 --- /dev/null +++ b/test_input_data/graph_data/blogs_graph.dot @@ -0,0 +1,27 @@ +graph G { +0[label=blog author=Leonardo]; +1[label=blog author=Raphael]; +2[label=blog author=Donatello]; +3[label=blog author=Michelangelo]; +4[label=blog author=Donatello]; +5[label=blog author=Michelangelo]; +6[label=blog author=Donatello]; +7[label=account name=Leonardo]; +8[label=account name=Donatello]; +9[label=account name=Raphael]; +10[label=account name=Michelangelo]; +7--0 [label=post]; +7--1 [label=like]; +7--2 [label=like]; +8--0 [label=like]; +8--2 [label=post]; +8--4 [label=post]; +8--5 [label=like]; +8--6 [label=post]; +9--1 [label=post]; +9--3 [label=like]; +10--3 [label=post]; +10--4 [label=like]; +10--5 [label=post]; +10--6 [label=like]; +} diff --git a/test_input_data/graph_data/channels_graph.dot b/test_input_data/graph_data/channels_graph.dot new file mode 100644 index 0000000000..1112601e4b --- /dev/null +++ b/test_input_data/graph_data/channels_graph.dot @@ -0,0 +1,34 @@ +graph G { +0[label=task difficulty=easy]; +1[label=task difficulty=normal]; +2[label=task difficulty=normal]; +3[label=task difficulty=hard]; +4[label=task difficulty=hard]; +5[label=task difficulty=hard]; +6[label=student name=James degree=bachelor year=2]; +7[label=student name=Michael degree=master year=1]; +8[label=student name=Robert degree=bachelor year=3]; +9[label=student name=John degree=master year=2]; +10[label=student name=David degree=bachelor year=4]; +11[label=student name=William degree=master year=2]; +12[label=student name=Richard degree=master year=2]; +13[label=student name=Joseph degree=master year=2]; +14[label=student name=Thomas degree=master year=2]; +15[label=student name=Christopher degree=master year=2]; +0--6 [label=performs]; +1--6 [label=performs]; +1--7 [label=performs]; +1--10 [label=performs]; +2--7 [label=performs]; +2--8 [label=performs]; +2--9 [label=performs]; +3--9 [label=performs]; +3--11 [label=performs]; +3--12 [label=performs]; +4--12 [label=performs]; +4--13 [label=performs]; +4--14 [label=performs]; +5--11 [label=performs]; +5--14 [label=performs]; +5--15 [label=performs]; +}