Skip to content

Commit

Permalink
Add tests for GFD mining
Browse files Browse the repository at this point in the history
Add minimal GFD and GFD with multiple conclusion tests
  • Loading branch information
AntonChern committed Nov 13, 2024
1 parent 2086510 commit 61bc27f
Show file tree
Hide file tree
Showing 12 changed files with 322 additions and 0 deletions.
113 changes: 113 additions & 0 deletions src/tests/test_gfd_mining.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>

#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 {

class GfdMiningTest : public ::testing::Test {
public:
std::filesystem::path const current_path = kTestDataDir / "graph_data";

static std::unique_ptr<algos::GfdMiner> 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<GfdMiner>(option_map);
}
};

TEST_F(GfdMiningTest, TestMinGfd) {
std::filesystem::path const gfd_path = GfdMiningTest::current_path / "blogs_gfd.dot";
std::ifstream f(gfd_path);
Gfd gfd = parser::graph_parser::ReadGfd(f);
std::vector<Gfd> gfds = {gfd};

std::filesystem::path const graph_path = GfdMiningTest::current_path / "blogs_graph.dot";
auto algorithm = CreateGfdMiningInstance(graph_path, 2, 3);
algorithm->Execute();
std::vector<Gfd> gfd_list = algorithm->GfdList();
algorithm = CreateGfdMiningInstance(graph_path, 3, 3);
algorithm->Execute();
std::size_t expected_size = gfd_list.size();
gfd_list = algorithm->GfdList();
ASSERT_EQ(expected_size, gfd_list.size());
for (std::size_t index = 0; index < gfd_list.size(); ++index) {
ASSERT_TRUE(gfds.at(index) == gfd_list.at(index));
}
}

TEST_F(GfdMiningTest, TestComplexConclusion) {
std::filesystem::path const gfd_path = GfdMiningTest::current_path / "channels_gfd.dot";
std::ifstream f(gfd_path);
Gfd gfd = parser::graph_parser::ReadGfd(f);
std::vector<Gfd> gfds = {gfd};

std::filesystem::path const graph_path = GfdMiningTest::current_path / "channels_graph.dot";
auto algorithm = CreateGfdMiningInstance(graph_path, 2, 3);
algorithm->Execute();
std::vector<Gfd> gfd_list = algorithm->GfdList();
std::size_t expected_size = 1;
ASSERT_EQ(expected_size, gfd_list.size());
for (std::size_t index = 0; index < gfd_list.size(); ++index) {
ASSERT_TRUE(gfds.at(index) == gfd_list.at(index));
}
}

TEST_F(GfdMiningTest, TestMovies) {
std::filesystem::path const graph_path = GfdMiningTest::current_path / "movies_graph.dot";
auto algorithm = CreateGfdMiningInstance(graph_path, 4, 2);
algorithm->Execute();
std::vector<Gfd> gfd_list = algorithm->GfdList();
std::size_t expected_size = 0;
ASSERT_EQ(expected_size, gfd_list.size());
}

TEST_F(GfdMiningTest, TestSymbols) {
std::vector<Gfd> gfds = {};
std::size_t expected_size = 2;
for (std::size_t index = 0; index < expected_size; ++index) {
std::filesystem::path const gfd_path =
GfdMiningTest::current_path / ("symbols_gfd" + std::to_string(index + 1) + ".dot");
std::ifstream f(gfd_path);
Gfd gfd = parser::graph_parser::ReadGfd(f);
gfds.push_back(gfd);
}
std::filesystem::path const graph_path = GfdMiningTest::current_path / "symbols_graph.dot";
auto algorithm = CreateGfdMiningInstance(graph_path, 2, 5);
algorithm->Execute();
std::vector<Gfd> gfd_list = algorithm->GfdList();
ASSERT_EQ(expected_size, gfd_list.size());
for (std::size_t index = 0; index < gfd_list.size(); ++index) {
ASSERT_TRUE(gfds.at(index) == gfd_list.at(index));
}
}

TEST_F(GfdMiningTest, TestShapes) {
std::vector<Gfd> gfds = {};
std::size_t expected_size = 2;
for (std::size_t index = 0; index < expected_size; ++index) {
std::filesystem::path const gfd_path =
GfdMiningTest::current_path / ("shapes_gfd" + std::to_string(index + 1) + ".dot");
std::ifstream f(gfd_path);
Gfd gfd = parser::graph_parser::ReadGfd(f);
gfds.push_back(gfd);
}
std::filesystem::path const graph_path = GfdMiningTest::current_path / "shapes_graph.dot";
auto algorithm = CreateGfdMiningInstance(graph_path, 3, 10);
algorithm->Execute();
std::vector<Gfd> gfd_list = algorithm->GfdList();
ASSERT_EQ(expected_size, gfd_list.size());
for (std::size_t index = 0; index < gfd_list.size(); ++index) {
ASSERT_TRUE(gfds.at(index) == gfd_list.at(index));
}
}

} // namespace tests
7 changes: 7 additions & 0 deletions test_input_data/graph_data/blogs_gfd.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

0.author=1.name
graph G {
0[label=blog];
1[label=account];
0--1 [label=post];
}
27 changes: 27 additions & 0 deletions test_input_data/graph_data/blogs_graph.dot
Original file line number Diff line number Diff line change
@@ -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];
}
7 changes: 7 additions & 0 deletions test_input_data/graph_data/channels_gfd.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
0.difficulty=hard
1.degree=master 1.year=2
graph G {
0[label=task];
1[label=student];
0--1 [label=performs];
}
34 changes: 34 additions & 0 deletions test_input_data/graph_data/channels_graph.dot
Original file line number Diff line number Diff line change
@@ -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];
}
21 changes: 21 additions & 0 deletions test_input_data/graph_data/movies_graph.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
graph G {
0[label=Person name=Igor];
1[label=Person name=Misha];
2[label=Person name=Olya];
3[label=Movie name="American Pie"];
4[label=Movie name="Saw"];
5[label=Movie name="Home Alone"];
6[label=Genre name="Comedy"];
7[label=Genre name="Horror"];
0--1 [label=IsFriend];
0--5 [label=Watched];
1--2 [label=IsFriend];
1--4 [label=Watched];
1--5 [label=Watched];
2--3 [label=Watched];
2--4 [label=Watched];
2--5 [label=Watched];
3--6 [label=HasGenre];
4--7 [label=HasGenre];
5--6 [label=HasGenre];
}
5 changes: 5 additions & 0 deletions test_input_data/graph_data/shapes_gfd1.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

0.style=filled
graph G {
0[label=v];
}
7 changes: 7 additions & 0 deletions test_input_data/graph_data/shapes_gfd2.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

0.style=1.style 1.style=filled
graph G {
0[label=v];
1[label=v];
0--1 [label=e];
}
22 changes: 22 additions & 0 deletions test_input_data/graph_data/shapes_graph.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
graph G {
0[label="v" shape=circle color=lightblue style=filled width="0.5"];
1[label="v" shape=square color=lightgreen style=filled width="0.6"];
2[label="v" shape=ellipse color=lightyellow style=filled width="0.7"];
3[label="v" shape=diamond color=lightcoral style=filled width="0.5"];
4[label="v" shape=octagon color=lightpink style=filled width="0.6"];
5[label="v" shape=circle color=lightsalmon style=filled width="0.7"];
6[label="v" shape=square color=lightcyan style=filled width="0.5"];
7[label="v" shape=ellipse color=lightgray style=filled width="0.6"];
8[label="v" shape=diamond color=lightgoldenrodyellow style=filled width="0.7"];
9[label="v" shape=octagon color=lightblue style=filled width="0.5"];
0--1[label="e"];
0--2[label="e"];
1--3[label="e"];
1--4[label="e"];
2--5[label="e"];
3--6[label="e"];
4--7[label="e"];
5--8[label="e"];
6--9[label="e"];
7--0[label="e"];
}
7 changes: 7 additions & 0 deletions test_input_data/graph_data/symbols_gfd1.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
0.sound=consonant 1.sound=consonant
0.sound=1.sound
graph G {
0[label=vertex];
1[label=vertex];
0--1 [label=e];
}
7 changes: 7 additions & 0 deletions test_input_data/graph_data/symbols_gfd2.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
0.sound=1.sound
0.sound=consonant 1.sound=consonant
graph G {
0[label=vertex];
1[label=vertex];
0--1 [label=e];
}
65 changes: 65 additions & 0 deletions test_input_data/graph_data/symbols_graph.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
graph G {
0[label=vertex symbol=a sound=vowel];
1[label=vertex symbol=b sound=consonant];
2[label=vertex symbol=c sound=consonant];
3[label=vertex symbol=d sound=consonant];
4[label=vertex symbol=e sound=vowel];
5[label=vertex symbol=f sound=consonant];
6[label=vertex symbol=g sound=consonant];
7[label=vertex symbol=h sound=consonant];
8[label=vertex symbol=i sound=vowel];
9[label=vertex symbol=j sound=consonant];
10[label=vertex symbol=k sound=consonant];
11[label=vertex symbol=l sound=consonant];
12[label=vertex symbol=m sound=consonant];
13[label=vertex symbol=n sound=consonant];
14[label=vertex symbol=o sound=vowel];
15[label=vertex symbol=p sound=consonant];
16[label=vertex symbol=q sound=consonant];
17[label=vertex symbol=r sound=consonant];
18[label=vertex symbol=s sound=consonant];
19[label=vertex symbol=t sound=consonant];
20[label=vertex symbol=z sound=consonant];
0--1[label=e];
0--2[label=e];
0--3[label=e];
1--2[label=e];
1--4[label=e];
2--4[label=e];
2--5[label=e];
3--5[label=e];
3--6[label=e];
4--7[label=e];
5--6[label=e];
5--7[label=e];
5--8[label=e];
5--9[label=e];
6--10[label=e];
7--11[label=e];
7--14[label=e];
8--9[label=e];
8--11[label=e];
8--12[label=e];
9--10[label=e];
9--12[label=e];
9--13[label=e];
10--13[label=e];
10--17[label=e];
11--12[label=e];
11--14[label=e];
12--13[label=e];
12--14[label=e];
12--15[label=e];
13--16[label=e];
13--17[label=e];
14--15[label=e];
14--18[label=e];
15--16[label=e];
15--18[label=e];
15--19[label=e];
16--17[label=e];
16--19[label=e];
17--19[label=e];
18--20[label=e];
19--20[label=e];
}

0 comments on commit 61bc27f

Please sign in to comment.