-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
172 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
#include <algorithm> | ||
#include <memory> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include "algo_factory.h" | ||
#include "all_csv_configs.h" | ||
#include "builtin.h" | ||
#include "config/indices/type.h" | ||
#include "config/names.h" | ||
#include "csv_config_util.h" | ||
#include "fd/fd_verifier/dynamic_fd_verifier.h" | ||
#include "fd/fd_verifier/dynamic_stats_calculator.h" | ||
|
||
namespace { | ||
using namespace algos::fd_verifier; | ||
|
||
void TestSorting(std::unique_ptr<DynamicFDVerifier> verifier) { | ||
auto const& highlights = verifier->GetHighlights(); | ||
if (highlights.size() < 2) { | ||
return; | ||
} | ||
verifier->SortHighlightsByProportionDescending(); | ||
ASSERT_TRUE(std::is_sorted(highlights.begin(), highlights.end(), | ||
StatsCalculator::CompareHighlightsByProportionDescending())); | ||
verifier->SortHighlightsByProportionAscending(); | ||
ASSERT_TRUE(std::is_sorted(highlights.begin(), highlights.end(), | ||
StatsCalculator::CompareHighlightsByProportionAscending())); | ||
verifier->SortHighlightsBySizeDescending(); | ||
ASSERT_TRUE(std::is_sorted(highlights.begin(), highlights.end(), | ||
StatsCalculator::CompareHighlightsBySizeDescending())); | ||
verifier->SortHighlightsBySizeAscending(); | ||
ASSERT_TRUE(std::is_sorted(highlights.begin(), highlights.end(), | ||
StatsCalculator::CompareHighlightsBySizeAscending())); | ||
verifier->SortHighlightsByNumDescending(); | ||
ASSERT_TRUE(std::is_sorted(highlights.begin(), highlights.end(), | ||
StatsCalculator::CompareHighlightsByNumDescending())); | ||
verifier->SortHighlightsByNumAscending(); | ||
ASSERT_TRUE(std::is_sorted(highlights.begin(), highlights.end(), | ||
StatsCalculator::CompareHighlightsByNumAscending())); | ||
} | ||
} // namespace | ||
|
||
namespace tests { | ||
namespace onam = config::names; | ||
|
||
const CSVConfig EMPTY{}; | ||
|
||
bool is_empty(CSVConfig const& config) { | ||
return config.has_header == EMPTY.has_header && config.path == EMPTY.path && config.separator == EMPTY.separator; | ||
} | ||
|
||
struct DynFDVerifyingParams { | ||
algos::StdParamsMap params; | ||
long double const error = 0.; | ||
size_t const num_error_clusters = 0; | ||
size_t const num_error_rows = 0; | ||
|
||
DynFDVerifyingParams(config::IndicesType lhs_indices, config::IndicesType rhs_indices, | ||
size_t const num_error_clusters = 0, size_t const num_error_rows = 0, | ||
long double const error = 0., CSVConfig const& insert_config = EMPTY, | ||
CSVConfig const& update_config = EMPTY, | ||
std::unordered_set<size_t> delete_config = {}, | ||
CSVConfig const& csv_config = kTestDynamicFDInit) | ||
: params({{onam::kCsvConfig, csv_config}, | ||
{onam::kLhsIndices, std::move(lhs_indices)}, | ||
{onam::kRhsIndices, std::move(rhs_indices)}}), | ||
error(error), | ||
num_error_clusters(num_error_clusters), | ||
num_error_rows(num_error_rows) { | ||
if (!is_empty(insert_config)) { | ||
params[onam::kInsertStatements] = MakeInputTable(insert_config); | ||
} | ||
if (!is_empty(update_config)) { | ||
params[onam::kUpdateStatements] = MakeInputTable(update_config); | ||
} | ||
if (!delete_config.empty()) { | ||
params[onam::kDeleteStatements] = std::move(delete_config); | ||
} | ||
} | ||
|
||
|
||
}; | ||
|
||
class TestFDVerifying : public ::testing::TestWithParam<DynFDVerifyingParams> {}; | ||
|
||
class TestDynamicFDVerifying : public ::testing::TestWithParam<DynFDVerifyingParams> {}; | ||
|
||
TEST_P(TestFDVerifying, InitializationTest) { | ||
auto const& p = GetParam(); | ||
auto mp = algos::StdParamsMap(p.params); | ||
auto verifier = algos::CreateAndLoadAlgorithm<algos::fd_verifier::DynamicFDVerifier>(mp); | ||
EXPECT_EQ(verifier->FDHolds(), p.num_error_clusters == 0); | ||
EXPECT_DOUBLE_EQ(verifier->GetError(), p.error); | ||
EXPECT_EQ(verifier->GetNumErrorRows(), p.num_error_rows); | ||
EXPECT_EQ(verifier->GetNumErrorClusters(), p.num_error_clusters); | ||
|
||
TestSorting(std::move(verifier)); | ||
} | ||
|
||
// clang-format off | ||
INSTANTIATE_TEST_SUITE_P( | ||
DynamicFDVerifierTestSuite, TestFDVerifying, | ||
::testing::Values( | ||
DynFDVerifyingParams({0, 1, 2, 3, 4}, {5}, 0, 0, 0.), | ||
DynFDVerifyingParams({1, 2}, {0, 3}, 1, 2, 2.L/132), | ||
DynFDVerifyingParams({2, 4}, {0, 1, 3, 5}, 0, 0, 0.), | ||
DynFDVerifyingParams({1}, {2, 3}, 4, 12, 18.L/132), | ||
DynFDVerifyingParams({1, 4}, {2, 3, 5}, 3, 8, 10.L/132), | ||
DynFDVerifyingParams({0, 1}, {1, 4}, 2, 6, 8.L/132) | ||
)); | ||
|
||
// clang-format on | ||
|
||
TEST_P(TestDynamicFDVerifying, ModifyingTest) { | ||
auto const& p = GetParam(); | ||
auto mp = algos::StdParamsMap(p.params); | ||
auto verifier = algos::CreateAndLoadAlgorithm<algos::fd_verifier::DynamicFDVerifier>(mp); | ||
verifier->Execute(); | ||
EXPECT_EQ(verifier->FDHolds(), p.num_error_clusters == 0); | ||
EXPECT_DOUBLE_EQ(verifier->GetError(), p.error); | ||
EXPECT_EQ(verifier->GetNumErrorRows(), p.num_error_rows); | ||
EXPECT_EQ(verifier->GetNumErrorClusters(), p.num_error_clusters); | ||
|
||
TestSorting(std::move(verifier)); | ||
} | ||
|
||
// clang-format off | ||
INSTANTIATE_TEST_SUITE_P( | ||
DynamicFDVerifierTestSuite, TestDynamicFDVerifying, | ||
::testing::Values( | ||
DynFDVerifyingParams({0, 1, 2, 3, 4}, {5}, 1, 2, 1.L/105, kTestDynamicFDInsert), // | ||
DynFDVerifyingParams({4}, {3}, 0, 0, 0., EMPTY, kTestDynamicFDUpdate), // | ||
DynFDVerifyingParams({1, 2}, {0, 3}, 0, 0, 0., EMPTY, EMPTY, {1, 6, 3}), // | ||
DynFDVerifyingParams({2, 4}, {0, 1, 3, 5}, 2, 4, 2.L/105, kTestDynamicFDInsert, kTestDynamicFDUpdate), // | ||
DynFDVerifyingParams({1}, {2, 3}, 5, 12, 7.L/66, kTestDynamicFDInsert, EMPTY, {1, 6, 3}), | ||
DynFDVerifyingParams({1, 4}, {2, 3, 5}, 2, 5, 1.L/12, EMPTY, kTestDynamicFDUpdate, {1, 6, 3}), | ||
DynFDVerifyingParams({0, 1}, {1, 4}, 2, 5, 1.L/22, kTestDynamicFDInsert, kTestDynamicFDUpdate, {1, 6, 3}) // | ||
)); | ||
|
||
// clang-format on | ||
|
||
} // namespace tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Col0,Col1,Col2,Col3,Col4,Col5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
Col0,Col1,Col2,Col3,Col4,Col5 | ||
1,1,1,1.233,-,1 | ||
1,1,1,0,8,2 | ||
1,1,2.1,0,8,3 | ||
1,2,2,hjkl,444,4 | ||
1,2,2,hjkl,444,4 | ||
1,2,,hjkl,444,5 | ||
1,3,3,0,9,6 | ||
1,3,3,0,9,6 | ||
1,3,NULL,999,-,7 | ||
1,4,4,hjkl,555,8 | ||
1,4,4,hjkl,555,8 | ||
1,4,abc,hjkl,555,9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Col0,Col1,Col2,Col3,Col4,Col5 | ||
1,5,5,mnop,10,10 | ||
1,5,5,mnop,10,11 | ||
1,5,666,hjkl,666,11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
_id,Col0,Col1,Col2,Col3,Col4,Col5 | ||
0,2,1,1,999,-,10 | ||
4,1,2,2,hjkl,444,5 |