Skip to content

Commit

Permalink
Add DC verifier tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xJoskiy committed Nov 30, 2024
1 parent 8510134 commit 90eaa90
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/tests/test_dc_verifier.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <memory>
#include <string>

#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include "algorithms/algo_factory.h"
#include "algorithms/dc/verifier/dc_verifier.h"
#include "all_csv_configs.h"
#include "config/names_and_descriptions.h"

namespace tests {

using namespace algos;
using namespace algos::dc;

namespace mo = model;

static algos::StdParamsMap GetParamMap(CSVConfig const& csv_config, std::string dc) {
using namespace config::names;
return {{kCsvConfig, csv_config}, {kDenialConstraint, dc}};
}

struct DCTestParams {
std::string dc_string;
CSVConfig csv_config;
bool expected;
};

class TestDCVerifier : public ::testing::TestWithParam<DCTestParams> {};

TEST_P(TestDCVerifier, DefaultTest) {
DCTestParams const& p = GetParam();
algos::StdParamsMap params = GetParamMap(p.csv_config, p.dc_string);
std::unique_ptr<DCVerifier> dc_verifier = algos::CreateAndLoadAlgorithm<DCVerifier>(params);
dc_verifier->Execute();
bool res = dc_verifier->DCHolds();
EXPECT_EQ(res, p.expected);
}

// clang-format off
INSTANTIATE_TEST_SUITE_P(
DCVerifierTestSuite, TestDCVerifier, ::testing::Values(
DCTestParams("!(t.Col3 == s.Col3 and s.Col1 == t.Col1 and s.Col2 == t.Col2)", kTestDC, true),
DCTestParams("!(t.Col1 == s.Col1 and s.Col2 == t.Col2 and s.Col0 == t.Col0)", kTestDC, false),
DCTestParams("!(s.Col0 == t.Col0 and t.Col1 == s.Col1 and s.Col2 > t.Col4)", kTestDC, true),
DCTestParams("!(s.0 == t.0 and t.1 == s.1 and s.2 > t.4)", kTestDC, true),
DCTestParams("!(s.0 == t.0 and t.Col1 == s.Col1 and s.Col2 > t.4)", kTestDC, true),
DCTestParams("!(s.0 == t.1 and s.1 == t.2 and s.2 == t.3)", kBernoulliRelation, false),
DCTestParams("!(s.Col0 == t.Col0 and s.Col5 <= t.Col6)", kTestDC, true),
DCTestParams("!(t.Col7 > s.Col3 and s.Col1 == t.Col1)", kTestDC, true),
DCTestParams("!(t.Col2 == s.Col2 and s.Col4 >= t.Col5)", kTestDC, true),
DCTestParams("!(s.Salary < t.Salary and s.State == t.State and s.FedTaxRate > t.FedTaxRate)", kTestDC1, true),
DCTestParams("!(s.Salary <= t.Salary and s.State == t.State and s.FedTaxRate >= t.FedTaxRate)", kTestDC1, false),
DCTestParams("!(s.Salary > t.FedTaxRate and s.Salary <= t.FedTaxRate)", kTestDC1, true),
DCTestParams("!(s.Salary == t.FedTaxRate)", kTestDC1, true),
DCTestParams("!(s.Salary < s.Salary and t.State != t.State)", kTestDC1, true),
DCTestParams("!(t.Salary != t.FedTaxRate and s.Salary < s.FedTaxRate and t.State == t.State)", kTestDC1, true),
DCTestParams("!(t.Salary == t.FedTaxRate and s.Salary == s.FedTaxRate and s.Salary == t.FedTaxRate)", kTestDC1, true),
DCTestParams("!(t.Salary == s.FedTaxRate and s.Salary == t.FedTaxRate)", kTestDC1, true),
DCTestParams("!(t.Salary != s.FedTaxRate and s.Salary != t.FedTaxRate)", kTestDC1, false)
)
);

// clang-format on

} // namespace tests
8 changes: 8 additions & 0 deletions test_input_data/TestDC.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Col0,Col1,Col2,Col3,Col4,Col5,Col6,Col7
0,1,2,helloworld,10,10.2,64.81099,aa
1,2,3,helloworld,15,71.12,16.693,bb
3,4,5,hope it works,23,43.87,-15.8,aa
0,1,2,cum deo,7,64.811,2.19,aa
3,4,19,ridiculous,10,15.9,-43.01,bb
1,1,14,crucio,12,17.693,69.012,crm
3,1,38,lumos,31,-0.19,-1.12,bb
11 changes: 11 additions & 0 deletions test_input_data/TestDC1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
State,Salary,FedTaxRate
NewYork,3000,0.2
NewYork,4000,0.25
NewYork,5000,0.3
Wisconsin,5000,0.15
Wisconsin,6000,0.2
Wisconsin,4000,0.1
Texas,1000,0.15
Texas,2000,0.25
Texas,3000,0.3
Texas,3000,0.31

0 comments on commit 90eaa90

Please sign in to comment.