Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add datasets info for tests #303

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/tests/all_tables_config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "all_tables_config.h"

namespace tests {
extern TableConfig const kWDC_astronomical{"WDC_astronomical.csv", ',', true};
extern TableConfig const kWDC_symbols{"WDC_symbols.csv", ',', true};
extern TableConfig const kWDC_science{"WDC_science.csv", ',', true};
extern TableConfig const kWDC_satellites{"WDC_satellites.csv", ',', true};
extern TableConfig const kWDC_appearances{"WDC_appearances.csv", ',', true};
extern TableConfig const kWDC_astrology{"WDC_astrology.csv", ',', true};
extern TableConfig const kWDC_game{"WDC_game.csv", ',', true};
extern TableConfig const kWDC_kepler{"WDC_kepler.csv", ',', true};
extern TableConfig const kWDC_planetz{"WDC_planetz.csv", ',', true};
extern TableConfig const kWDC_age{"WDC_age.csv", ',', true};
extern TableConfig const kTestWide{"TestWide.csv", ',', true};
extern TableConfig const kabalone{"abalone.csv", ',', false};
extern TableConfig const kiris{"iris.csv", ',', false};
extern TableConfig const kadult{"adult.csv", ';', false};
extern TableConfig const kbreast_cancer{"breast_cancer.csv", ',', true};
extern TableConfig const kCIPublicHighway10k{"CIPublicHighway10k.csv", ',', true};
extern TableConfig const kneighbors10k{"neighbors10k.csv", ',', true};
extern TableConfig const kneighbors50k{"neighbors50k.csv", ',', true};
extern TableConfig const kneighbors100k{"neighbors100k.csv", ',', true};
extern TableConfig const kCIPublicHighway700{"CIPublicHighway700.csv", ',', true};
extern TableConfig const kEpicVitals{"EpicVitals.csv", '|', true};
extern TableConfig const kEpicMeds{"EpicMeds.csv", '|', true};
extern TableConfig const kiowa1kk{"iowa1kk.csv", ',', true};
extern TableConfig const kfd_reduced_30{"fd-reduced-30.csv", ',', true};
extern TableConfig const kflight_1k{"flight_1k.csv", ';', true};
extern TableConfig const kplista_1k{"plista_1k.csv", ';', false};
extern TableConfig const kletter{"letter.csv", ',', false};
extern TableConfig const kCIPublicHighway{"CIPublicHighway.csv", ',', true};
extern TableConfig const kLegacyPayors{"LegacyPayors.csv", '|', true};
extern TableConfig const kTestEmpty{"TestEmpty.csv", ',', true};
extern TableConfig const kTestSingleColumn{"TestSingleColumn.csv", ',', true};
extern TableConfig const kTestLong{"TestLong.csv", ',', true};
} // namespace tests
38 changes: 38 additions & 0 deletions src/tests/all_tables_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once

#include "table_config.h"

namespace tests {
extern TableConfig const kWDC_astronomical;
extern TableConfig const kWDC_symbols;
extern TableConfig const kWDC_science;
extern TableConfig const kWDC_satellites;
extern TableConfig const kWDC_appearances;
extern TableConfig const kWDC_astrology;
extern TableConfig const kWDC_game;
extern TableConfig const kWDC_kepler;
extern TableConfig const kWDC_planetz;
extern TableConfig const kWDC_age;
extern TableConfig const kTestWide;
extern TableConfig const kabalone;
extern TableConfig const kiris;
extern TableConfig const kadult;
extern TableConfig const kbreast_cancer;
extern TableConfig const kCIPublicHighway10k;
extern TableConfig const kneighbors10k;
extern TableConfig const kneighbors50k;
extern TableConfig const kneighbors100k;
extern TableConfig const kCIPublicHighway700;
extern TableConfig const kEpicVitals;
extern TableConfig const kEpicMeds;
extern TableConfig const kiowa1kk;
extern TableConfig const kfd_reduced_30;
extern TableConfig const kflight_1k;
extern TableConfig const kplista_1k;
extern TableConfig const kletter;
extern TableConfig const kCIPublicHighway;
extern TableConfig const kLegacyPayors;
extern TableConfig const kTestEmpty;
extern TableConfig const kTestSingleColumn;
extern TableConfig const kTestLong;
} // namespace tests
77 changes: 0 additions & 77 deletions src/tests/datasets.h

This file was deleted.

41 changes: 41 additions & 0 deletions src/tests/table_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#pragma once

#include <filesystem>
#include <string_view>
#include <vector>

#include "config/tabular_data/input_table_type.h"
#include "parser/csv_parser/csv_parser.h"

namespace tests {

static auto const test_data_dir = std::filesystem::current_path() / "input_data";

/// csv table configuration info to create an input table
struct TableConfig {
std::string_view name;
char separator;
bool has_header;

std::filesystem::path GetPath() const {
return test_data_dir / name;
}

config::InputTable MakeInputTable() const {
return std::make_shared<CSVParser>(GetPath(), separator, has_header);
}
};

/// a struct consisting of a table config and the expected hash
struct TableConfigHash {
TableConfig config;
size_t hash;
};

/// a struct consisting of a tables config and the expected hash
struct TablesConfigHash {
std::vector<TableConfig> configs;
size_t hash;
};

} // namespace tests
2 changes: 1 addition & 1 deletion src/tests/test_ac_algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "algorithms/algebraic_constraints/bin_operation_enum.h"
#include "algorithms/algo_factory.h"
#include "config/names.h"
#include "datasets.h"
#include "table_config.h"
#include "types.h"

namespace {
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_algo_interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "algorithms/fd/pyro/pyro.h"
#include "config/error/type.h"
#include "config/names.h"
#include "datasets.h"
#include "table_config.h"

namespace tests {

Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_apriori.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "algorithms/algo_factory.h"
#include "algorithms/association_rules/apriori.h"
#include "config/names.h"
#include "datasets.h"
#include "table_config.h"

namespace fs = std::filesystem;

Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_cfd_algos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "algorithms/cfd/enums.h"
#include "algorithms/cfd/fd_first_algorithm.h"
#include "config/names.h"
#include "datasets.h"
#include "table_config.h"

namespace tests {
namespace fs = std::filesystem;
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_cfd_relation_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <gtest/gtest.h>

#include "algorithms/cfd/model/cfd_relation_data.h"
#include "datasets.h"
#include "parser/csv_parser/csv_parser.h"
#include "table_config.h"

namespace tests {

Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_data_stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "algorithms/algo_factory.h"
#include "algorithms/statistics/data_stats.h"
#include "datasets.h"
#include "table_config.h"

namespace tests {
namespace mo = model;
Expand Down
50 changes: 14 additions & 36 deletions src/tests/test_algorithm.cpp → src/tests/test_fd_algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@
#include "algorithms/fd/hyfd/hyfd.h"
#include "algorithms/fd/pyro/pyro.h"
#include "algorithms/fd/tane/tane.h"
#include "datasets.h"
#include "model/table/relational_schema.h"
#include "testing_utils.h"
#include "table_config.h"
#include "test_fd_util.h"

using std::string, std::vector;
using ::testing::ContainerEq, ::testing::Eq;

namespace fs = std::filesystem;

namespace tests {

/* This is a test suite for algorithm verification. It should be possible to run these tests for any
* algorithm that:
* 1. extends FDAlgorithm
Expand Down Expand Up @@ -76,20 +78,20 @@ std::set<std::pair<std::vector<unsigned int>, unsigned int>> FDsToSet(std::list<
TYPED_TEST_SUITE_P(AlgorithmTest);

TYPED_TEST_P(AlgorithmTest, ThrowsOnEmpty) {
auto algorithm = TestFixture::CreateAndConfToLoad(test_data_dir / "TestEmpty.csv", ',', true);
auto algorithm = TestFixture::CreateAndConfToLoad(kTestEmpty);
ASSERT_THROW(algorithm->LoadData(), std::runtime_error);
}

TYPED_TEST_P(AlgorithmTest, ReturnsEmptyOnSingleNonKey) {
auto algorithm = TestFixture::CreateAlgorithmInstance("TestSingleColumn.csv", ',', true);
auto algorithm = TestFixture::CreateAlgorithmInstance(kTestSingleColumn);
algorithm->Execute();
ASSERT_TRUE(algorithm->FdList().empty());
}

TYPED_TEST_P(AlgorithmTest, WorksOnLongDataset) {
std::set<std::pair<std::vector<unsigned int>, unsigned int>> true_fd_collection{{{2}, 1}};

auto algorithm = TestFixture::CreateAlgorithmInstance("TestLong.csv", ',', true);
auto algorithm = TestFixture::CreateAlgorithmInstance(kTestLong);
algorithm->Execute();
ASSERT_TRUE(CheckFdListEquality(true_fd_collection, algorithm->FdList()));
}
Expand All @@ -98,51 +100,25 @@ TYPED_TEST_P(AlgorithmTest, WorksOnWideDataset) {
std::set<std::pair<std::vector<unsigned int>, unsigned int>> true_fd_collection{
{{0}, 2}, {{0}, 4}, {{2}, 0}, {{2}, 4}, {{4}, 0}, {{4}, 2}, {{}, 1}, {{}, 3}};

auto algorithm = TestFixture::CreateAlgorithmInstance("TestWide.csv", ',', true);
auto algorithm = TestFixture::CreateAlgorithmInstance(kTestWide);
algorithm->Execute();
ASSERT_TRUE(CheckFdListEquality(true_fd_collection, algorithm->FdList()));
}

TYPED_TEST_P(AlgorithmTest, LightDatasetsConsistentHash) {
try {
for (auto const& dataset : LightDatasets::datasets_) {
auto algorithm = TestFixture::CreateAlgorithmInstance(dataset.name, dataset.separator,
dataset.has_header);
algorithm->Execute();
std::cout << dataset.name << std::endl;
EXPECT_EQ(algorithm->Fletcher16(), dataset.hash)
<< "FD collection hash changed for " << dataset.name;
}
} catch (std::runtime_error& e) {
std::cout << "Exception raised in test: " << e.what() << std::endl;
FAIL();
}
SUCCEED();
TestFixture::PerformConsistentHashTestOn(TestFixture::light_datasets_);
}

TYPED_TEST_P(AlgorithmTest, HeavyDatasetsConsistentHash) {
try {
for (auto const& dataset : HeavyDatasets::datasets_) {
auto algorithm = TestFixture::CreateAlgorithmInstance(dataset.name, dataset.separator,
dataset.has_header);
algorithm->Execute();
EXPECT_EQ(algorithm->Fletcher16(), dataset.hash)
<< "The new algorithm and Pyro yield different results at " << dataset.name;
}
} catch (std::runtime_error& e) {
std::cout << "Exception raised in test: " << e.what() << std::endl;
FAIL();
}
SUCCEED();
TestFixture::PerformConsistentHashTestOn(TestFixture::heavy_datasets_);
}

TYPED_TEST_P(AlgorithmTest, ConsistentRepeatedExecution) {
auto const path = test_data_dir / "WDC_astronomical.csv";
auto algorithm = TestFixture::CreateAlgorithmInstance(path, ',', true);
auto algorithm = TestFixture::CreateAlgorithmInstance(kWDC_astronomical);
algorithm->Execute();
auto first_res = FDsToSet(algorithm->FdList());
for (int i = 0; i < 3; ++i) {
algos::ConfigureFromMap(*algorithm, TestFixture::GetParamMap(path, ',', true));
algos::ConfigureFromMap(*algorithm, TestFixture::GetParamMap(kWDC_astronomical));
algorithm->Execute();
ASSERT_TRUE(CheckFdListEquality(first_res, algorithm->FdList()));
}
Expand All @@ -155,3 +131,5 @@ REGISTER_TYPED_TEST_SUITE_P(AlgorithmTest, ThrowsOnEmpty, ReturnsEmptyOnSingleNo
using Algorithms = ::testing::Types<algos::Tane, algos::Pyro, algos::FastFDs, algos::DFD,
algos::Depminer, algos::FDep, algos::FUN, algos::hyfd::HyFD>;
INSTANTIATE_TYPED_TEST_SUITE_P(AlgorithmTest, AlgorithmTest, Algorithms);

} // namespace tests
Loading