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

Implement OD verifier algorithm #420

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions src/tests/all_csv_configs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ CSVConfig const kTestEmpty = CreateCsvConfig("TestEmpty.csv", ',', true);
CSVConfig const kTestSingleColumn = CreateCsvConfig("TestSingleColumn.csv", ',', true);
CSVConfig const kTestLong = CreateCsvConfig("TestLong.csv", ',', true);
CSVConfig const kTestFD = CreateCsvConfig("TestFD.csv", ',', true);
CSVConfig const kTestODVerifier = CreateCsvConfig("ODVerificationData.csv", ',', true);
CSVConfig const kOdTestNormOd = CreateCsvConfig("od_norm_data/OD_norm.csv", ',', true);
CSVConfig const kOdTestNormSmall2x3 = CreateCsvConfig("od_norm_data/small_2x3.csv", ',', true);
CSVConfig const kOdTestNormSmall3x3 = CreateCsvConfig("od_norm_data/small_3x3.csv", ',', true);
Expand Down
1 change: 1 addition & 0 deletions src/tests/all_csv_configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ extern CSVConfig const kTestEmpty;
extern CSVConfig const kTestSingleColumn;
extern CSVConfig const kTestLong;
extern CSVConfig const kTestFD;
extern CSVConfig const kTestODVerifier;
extern CSVConfig const kOdTestNormOd;
extern CSVConfig const kOdTestNormSmall2x3;
extern CSVConfig const kOdTestNormSmall3x3;
Expand Down
1 change: 1 addition & 0 deletions src/tests/test_ind_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string>
#include <utility>
#include <vector>
#include <set>

#include "algorithms/ind/ind.h"
#include "algorithms/ind/ind_algorithm.h"
Expand Down
52 changes: 52 additions & 0 deletions src/tests/test_od_verifier.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <gtest/gtest.h>

#include "algo_factory.h"
#include "all_csv_configs.h"
#include "config/names.h"
#include "od/od_verifier/od_verifier.h"

namespace tests {

struct ODVerifyingParams {
algos::StdParamsMap params;
size_t const row_violate_ods_by_split = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did I understand correctly that this field stores the number of rows that violate the order dependency by split? If so, the field should be renamed.

size_t const row_violate_ods_by_swap = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did I understand correctly that this field stores the number of rows that violate the order dependency by swap? If so, the field should be renamed.


ODVerifyingParams(config::IndicesType lhs_indices, config::IndicesType rhs_indices,
config::IndicesType context, bool ascending, size_t const row_error_split = 0,
size_t const row_error_swap = 0,
CSVConfig const& csv_config = kTestODVerifier)
: params({{config::names::kCsvConfig, csv_config},
{config::names::kLhsIndices, std::move(lhs_indices)},
{config::names::kRhsIndices, std::move(rhs_indices)},
{config::names::kODContext, std::move(context)},
{config::names::kAscendingOD, ascending}}),
row_violate_ods_by_split(row_error_split),
row_violate_ods_by_swap(row_error_swap) {}
};

class TestODVerifying : public ::testing::TestWithParam<ODVerifyingParams> {};

TEST_P(TestODVerifying, DefaultTest) {
auto const& p = GetParam();
auto mp = algos::StdParamsMap(p.params);
auto verifier = algos::CreateAndLoadAlgorithm<algos::od_verifier::ODVerifier>(mp);
verifier->Execute();
EXPECT_EQ(verifier->GetNumRowsViolateBySwap(), p.row_violate_ods_by_swap);
EXPECT_EQ(verifier->GetNumRowsViolateBySplit(), p.row_violate_ods_by_split);
}

// clang-format off
INSTANTIATE_TEST_SUITE_P(
ODVerifierTestSuite, TestODVerifying,
::testing::Values(
ODVerifyingParams({1}, {2}, {0}, true, 0, 0),
ODVerifyingParams({1}, {2}, {}, true, 1, 2),
ODVerifyingParams({3}, {4}, {0}, true, 0, 1),
ODVerifyingParams({1}, {2}, {0}, false, 0, 3),
ODVerifyingParams({3}, {4}, {0}, false, 0, 2),
ODVerifyingParams({5}, {6}, {0}, true, 1, 0)
));
// clang-format on

} // namespace tests
7 changes: 7 additions & 0 deletions test_input_data/ODVerificationData.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
1,2,3,4,5,6,7
2020,10,1000,10,1000,10,1000
2020,20,2000,20,2000,10,1000
2020,30,3000,30,10,10,1001
2021,10,1000,40,1000,10,1002
2021,20,1500,50,2000,10,1002
2022,5,10000,60,1000,10,1003
Loading