From dfc4049f54c92e5b860b2a86986b920d933287e2 Mon Sep 17 00:00:00 2001 From: AntonChern Date: Mon, 4 Dec 2023 17:52:09 +0300 Subject: [PATCH] Add tests Input data is presented as dot-files. Undirected graphs are used. --- src/tests/CMakeLists.txt | 2 +- src/tests/test_gfd_validation.cpp | 58 +++++++++++++++++++ test_input_data/graph_data/directors.dot | 23 ++++++++ test_input_data/graph_data/directors_gfd.dot | 7 +++ test_input_data/graph_data/quadrangle.dot | 14 +++++ test_input_data/graph_data/quadrangle_gfd.dot | 7 +++ 6 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 src/tests/test_gfd_validation.cpp create mode 100644 test_input_data/graph_data/directors.dot create mode 100644 test_input_data/graph_data/directors_gfd.dot create mode 100644 test_input_data/graph_data/quadrangle.dot create mode 100644 test_input_data/graph_data/quadrangle_gfd.dot diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index 6e0c2ee822..ce7b50e2f9 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -9,7 +9,7 @@ add_executable(${BINARY} ${test_sources}) add_test(NAME ${BINARY} COMMAND ${BINARY}) # linking with gtest and implemented classes -target_link_libraries(${BINARY} PRIVATE ${CMAKE_PROJECT_NAME}_lib gtest gmock) +target_link_libraries(${BINARY} PRIVATE ${CMAKE_PROJECT_NAME}_lib gtest gmock Boost::graph) # copying sample csv's for testing add_custom_target(copy-files ALL diff --git a/src/tests/test_gfd_validation.cpp b/src/tests/test_gfd_validation.cpp new file mode 100644 index 0000000000..e5f4ad660b --- /dev/null +++ b/src/tests/test_gfd_validation.cpp @@ -0,0 +1,58 @@ +#include +#include + +#include "algorithms/algo_factory.h" +#include "algorithms/gfd/gfd_validation.h" +#include "config/names.h" +#include "datasets.h" + +using namespace algos; +using algos::StdParamsMap; + +namespace { + +auto current_path = test_data_dir / "graph_data"; + +template +class GfdValidationTest : public ::testing::Test { +protected: + std::unique_ptr CreateGfdValidationInstance( + std::filesystem::path const& graph_path, const std::vector& gfd_paths) { + StdParamsMap optionMap = {{config::names::kCsvPath, graph_path}, + {config::names::kGfdData, gfd_paths}}; + return algos::CreateAndLoadAlgorithm(optionMap); + } +}; + +TYPED_TEST_SUITE_P(GfdValidationTest); + +TYPED_TEST_P(GfdValidationTest, TestTrivially) { + auto graph_path = current_path / "quadrangle.dot"; + auto gfd_path = current_path / "quadrangle_gfd.dot"; + std::vector gfd_paths = {gfd_path}; + auto algorithm = TestFixture::CreateGfdValidationInstance(graph_path, gfd_paths); + int expected_size = 1; + algorithm->Execute(); + std::vector GfdList = algorithm->GfdList(); + ASSERT_EQ(expected_size, GfdList.size()); +} + +TYPED_TEST_P(GfdValidationTest, TestExistingMatches) { + auto graph_path = current_path / "directors.dot"; + auto gfd_path = current_path / "directors_gfd.dot"; + std::vector gfd_paths = {gfd_path}; + auto algorithm = TestFixture::CreateGfdValidationInstance(graph_path, gfd_paths); + int expected_size = 0; + algorithm->Execute(); + std::vector GfdList = algorithm->GfdList(); + ASSERT_EQ(expected_size, GfdList.size()); +} + +REGISTER_TYPED_TEST_SUITE_P(GfdValidationTest, TestTrivially, TestExistingMatches); + +using GfdAlgorithms = + ::testing::Types; + +INSTANTIATE_TYPED_TEST_SUITE_P(GfdValidationTest, GfdValidationTest, GfdAlgorithms); + +} // namespace diff --git a/test_input_data/graph_data/directors.dot b/test_input_data/graph_data/directors.dot new file mode 100644 index 0000000000..25cdc269d5 --- /dev/null +++ b/test_input_data/graph_data/directors.dot @@ -0,0 +1,23 @@ +graph G { +0[label="person" name="James Cameron" celebrity="high"]; +1[label="film" name="Avatar" success="high" year="2009"]; +2[label="film" name="Titanic" success="high" year="1997"]; +3[label="film" name="Piranha II" success="low" year="1981"]; +4[label="film" name="Terminator" success="high" year="1984"]; +5[label="person" name="Robert Zemeckis" celebrity="high"]; +6[label="film" name="The Walk" success="high" year="2015"]; +7[label="film" name="Back to the future" success="high" year="1985"]; +8[label="film" name="Forrest Gump" success="high" year="1994"]; +9[label="person" name="James Toback" celebrity="low"]; +10[label="film" name="Tyson" success="high" year="2008"]; +11[label="film" name="Fingers" success="high" year="1978"]; +0--1 [label="directed"]; +0--2 [label="directed"]; +0--3 [label="directed"]; +0--4 [label="directed"]; +5--6 [label="directed"]; +5--7 [label="directed"]; +5--8 [label="directed"]; +9--10 [label="directed"]; +9--11 [label="directed"]; +} diff --git a/test_input_data/graph_data/directors_gfd.dot b/test_input_data/graph_data/directors_gfd.dot new file mode 100644 index 0000000000..97bbcef324 --- /dev/null +++ b/test_input_data/graph_data/directors_gfd.dot @@ -0,0 +1,7 @@ +0.celebrity=high +1.success=high +graph G { +0[label=person]; +1[label=film]; +0--1 [label=directed]; +} diff --git a/test_input_data/graph_data/quadrangle.dot b/test_input_data/graph_data/quadrangle.dot new file mode 100644 index 0000000000..71e9c7a347 --- /dev/null +++ b/test_input_data/graph_data/quadrangle.dot @@ -0,0 +1,14 @@ +graph G { +0[label=quadrilateral angles=arbitrary sides=arbitrary]; +1[label=parallelogram angles=pairwise_equal sides=pairwise_equal]; +2[label=trapezoid angles=arbitrary sides=parallel_and_arbitrary]; +3[label=rectangle angles=equal sides=pairwise_equal]; +4[label=rhombus angles=pairwise_equal sides=equal]; +5[label=square angles=equal sides=equal]; +0--1 [label=two_pairs_of_parallel_sides]; +0--2 [label=one_pair_of_parallel_sides]; +1--3 [label=equality_of_angles]; +1--4 [label=equality_of_sides]; +3--5 [label=equality_of_sides]; +4--5 [label=equality_of_angles]; +} diff --git a/test_input_data/graph_data/quadrangle_gfd.dot b/test_input_data/graph_data/quadrangle_gfd.dot new file mode 100644 index 0000000000..0ad28e783e --- /dev/null +++ b/test_input_data/graph_data/quadrangle_gfd.dot @@ -0,0 +1,7 @@ + +0.sides=1.sides +graph G { +0[label=polygon]; +1[label=triangle]; +0--1 [label=three_sides]; +}