Skip to content

Commit

Permalink
Add ND verification tests
Browse files Browse the repository at this point in the history
Implement tests for ND verification
  • Loading branch information
p-senichenkov authored and chernishev committed Aug 16, 2024
1 parent f117646 commit 3e3c499
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
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 kTestND = CreateCsvConfig("TestND.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 kTestND;
extern CSVConfig const kOdTestNormOd;
extern CSVConfig const kOdTestNormSmall2x3;
extern CSVConfig const kOdTestNormSmall3x3;
Expand Down
69 changes: 69 additions & 0 deletions src/tests/test_nd_verifier.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include <gtest/gtest.h>

#include "algorithms/algo_factory.h"
#include "algorithms/nd/nd.h"
#include "algorithms/nd/nd_verifier/nd_verifier.h"
#include "all_csv_configs.h"
#include "config/names.h"

namespace tests {
namespace onam = config::names;

struct NDVerifyingParams {
algos::StdParamsMap params;

NDVerifyingParams(config::IndicesType lhs_indices, config::IndicesType rhs_indices,
model::WeightType weight = UINT_MAX, CSVConfig const& csv_config = kTestND,
bool null_eq_null = true)
: params({{onam::kCsvConfig, csv_config},
{onam::kLhsIndices, std::move(lhs_indices)},
{onam::kRhsIndices, std::move(rhs_indices)},
{onam::kEqualNulls, null_eq_null},
{onam::kWeight, weight}}) {}
};

class TestNDVerifying : public ::testing::TestWithParam<NDVerifyingParams> {};

TEST_P(TestNDVerifying, DefaultTest) {
auto const& p = GetParam();
auto mp = algos::StdParamsMap(p.params);
auto verifier = algos::CreateAndLoadAlgorithm<algos::nd_verifier::NDVerifier>(mp);
verifier->Execute();
EXPECT_TRUE(verifier->NDHolds());
}

// clang-format off
INSTANTIATE_TEST_SUITE_P(
NDVerifierTestSuite, TestNDVerifying,
::testing::Values(
// Constant lhs:
NDVerifyingParams({0}, {1}, 4),
NDVerifyingParams({0}, {2}, 6),
NDVerifyingParams({0}, {3}, 4),
NDVerifyingParams({0}, {4}, 5),
NDVerifyingParams({0}, {5}, 9),
// Non-constant lhs:
NDVerifyingParams({1}, {5}, 3),
NDVerifyingParams({4}, {0}, 1),
// Multiple columns:
NDVerifyingParams({0, 1}, {3, 5}, 3),
NDVerifyingParams({1, 2}, {3, 6}, 2),
NDVerifyingParams({1, 2, 3}, {6}, 2)
));

INSTANTIATE_TEST_CASE_P(
NDVerifierHeavyDatasets, TestNDVerifying,
::testing::Values(
NDVerifyingParams({5}, {6}, 1000000, kIowa1kk), // I just want to see execution time. Real weight doesn't matter (but it shouldn't be very big)
NDVerifyingParams({16, 17, 18}, {20, 23}, 1000000, kIowa1kk) // Also, I want to see how execution time depends on number of columns
));

INSTANTIATE_TEST_CASE_P(
NDVerifierTestNullEqualNull, TestNDVerifying,
::testing::Values( // 6-th column contains 2 values and 7 empty cells
NDVerifyingParams({0}, {6}, 3, kTestND, true),
NDVerifyingParams({0}, {6}, 7, kTestND, false)
));
// clang-format on

} // namespace tests
13 changes: 13 additions & 0 deletions test_input_data/TestND.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Col0,Col1,Col2,Col3,Col4,Col5,Col6
1,a,x,1.233,-,11,aa
1,a,x,0,8,22,
1,a,xy,0,8,33,
1,b,y,hjkl,444,44,aa
1,b,y,hjkl,444,44,bb
1,b,xy,hjkl,444,55,aa
1,c,z,0,9,66,
1,c,z,0,9,66,
1,c,z,999,-,77,bb
1,d,k,hjkl,555,88,aa
1,d,k,hjkl,555,88,aa
1,d,abc,hjkl,555,99,

0 comments on commit 3e3c499

Please sign in to comment.