Refactor tests

This commit is contained in:
2023-03-21 00:53:18 +01:00
parent 12222f7903
commit 27ea3bf338
4 changed files with 160 additions and 155 deletions

View File

@@ -45,7 +45,7 @@ namespace mdlp {
int get_depth() const; int get_depth() const;
inline string version() const { return "1.1.1"; }; static inline string version() { return "1.1.1"; };
}; };
} }
#endif #endif

View File

@@ -4,6 +4,7 @@
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include "ArffFiles.h" #include "ArffFiles.h"
#define EXPECT_THROW_WITH_MESSAGE(stmt, etype, whatstring) EXPECT_THROW( \ #define EXPECT_THROW_WITH_MESSAGE(stmt, etype, whatstring) EXPECT_THROW( \
try { \ try { \
stmt; \ stmt; \
@@ -14,30 +15,33 @@ throw; \
, etype) , etype)
namespace mdlp { namespace mdlp {
class TestFImdlp: public CPPFImdlp, public testing::Test { class TestFImdlp : public CPPFImdlp, public testing::Test {
public: public:
precision_t precision = 0.000001; precision_t precision = 0.000001f;
TestFImdlp(): CPPFImdlp() {}
TestFImdlp() : CPPFImdlp() {}
string data_path; string data_path;
void SetUp()
{ void SetUp() override {
X = { 4.7, 4.7, 4.7, 4.7, 4.8, 4.8, 4.8, 4.8, 4.9, 4.95, 5.7, 5.3, 5.2, 5.1, 5.0, 5.6, 5.1, 6.0, 5.1, 5.9 }; X = {4.7f, 4.7f, 4.7f, 4.7f, 4.8f, 4.8f, 4.8f, 4.8f, 4.9f, 4.95f, 5.7f, 5.3f, 5.2f, 5.1f, 5.0f, 5.6f, 5.1f,
y = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2 }; 6.0f, 5.1f, 5.9f};
y = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2};
fit(X, y); fit(X, y);
data_path = set_data_path(); data_path = set_data_path();
} }
string set_data_path()
{ static string set_data_path() {
string path = "../datasets/"; string path = "../datasets/";
ifstream file(path+"iris.arff"); ifstream file(path + "iris.arff");
if (file.is_open()) { if (file.is_open()) {
file.close(); file.close();
return path; return path;
} }
return "../../tests/datasets/"; return "../../tests/datasets/";
} }
void checkSortedVector()
{ void checkSortedVector() {
indices_t testSortedIndices = sortIndices(X, y); indices_t testSortedIndices = sortIndices(X, y);
precision_t prev = X[testSortedIndices[0]]; precision_t prev = X[testSortedIndices[0]];
for (unsigned long i = 0; i < X.size(); ++i) { for (unsigned long i = 0; i < X.size(); ++i) {
@@ -46,26 +50,18 @@ namespace mdlp {
prev = X[testSortedIndices[i]]; prev = X[testSortedIndices[i]];
} }
} }
void checkCutPoints(cutPoints_t& computed, cutPoints_t& expected)
{ void checkCutPoints(cutPoints_t &computed, cutPoints_t &expected) const {
EXPECT_EQ(computed.size(), expected.size()); EXPECT_EQ(computed.size(), expected.size());
for (unsigned long i = 0; i < computed.size(); i++) { for (unsigned long i = 0; i < computed.size(); i++) {
cout << "(" << computed[i] << ", " << expected[i] << ") "; cout << "(" << computed[i] << ", " << expected[i] << ") ";
EXPECT_NEAR(computed[i], expected[i], precision); EXPECT_NEAR(computed[i], expected[i], precision);
} }
} }
template<typename T, typename A>
void checkVectors(std::vector<T, A> const& expected, std::vector<T, A> const& computed) bool test_result(const samples_t &X_, size_t cut, float midPoint, size_t limit, const string &title) {
{
ASSERT_EQ(expected.size(), computed.size());
for (auto i = 0; i < expected.size(); i++) {
EXPECT_NEAR(expected[i], computed[i], precision);
}
}
bool test_result(samples_t& X_, size_t cut, float midPoint, size_t limit, string title)
{
pair<precision_t, size_t> result; pair<precision_t, size_t> result;
labels_t y_ = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; labels_t y_ = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
X = X_; X = X_;
y = y_; y = y_;
indices = sortIndices(X, y); indices = sortIndices(X, y);
@@ -75,12 +71,13 @@ namespace mdlp {
EXPECT_EQ(result.second, limit); EXPECT_EQ(result.second, limit);
return true; return true;
} }
void test_dataset(CPPFImdlp& test, string filename, vector<cutPoints_t>& expected, int depths[])
{ void test_dataset(CPPFImdlp &test, const string &filename, vector<cutPoints_t> &expected,
vector<int> &depths) const {
ArffFiles file; ArffFiles file;
file.load(data_path + filename + ".arff", true); file.load(data_path + filename + ".arff", true);
vector<samples_t>& X = file.getX(); vector<samples_t> &X = file.getX();
labels_t& y = file.getY(); labels_t &y = file.getY();
auto attributes = file.getAttributes(); auto attributes = file.getAttributes();
for (auto feature = 0; feature < attributes.size(); feature++) { for (auto feature = 0; feature < attributes.size(); feature++) {
test.fit(X[feature], y); test.fit(X[feature], y);
@@ -92,202 +89,206 @@ namespace mdlp {
} }
} }
}; };
TEST_F(TestFImdlp, FitErrorEmptyDataset)
{ TEST_F(TestFImdlp, FitErrorEmptyDataset) {
X = samples_t(); X = samples_t();
y = labels_t(); y = labels_t();
EXPECT_THROW_WITH_MESSAGE(fit(X, y), invalid_argument, "X and y must have at least one element"); EXPECT_THROW_WITH_MESSAGE(fit(X, y), invalid_argument, "X and y must have at least one element");
} }
TEST_F(TestFImdlp, FitErrorDifferentSize)
{ TEST_F(TestFImdlp, FitErrorDifferentSize) {
X = { 1, 2, 3 }; X = {1, 2, 3};
y = { 1, 2 }; y = {1, 2};
EXPECT_THROW_WITH_MESSAGE(fit(X, y), invalid_argument, "X and y must have the same size"); EXPECT_THROW_WITH_MESSAGE(fit(X, y), invalid_argument, "X and y must have the same size");
} }
TEST_F(TestFImdlp, FitErrorMinLengtMaxDepth)
{ TEST_F(TestFImdlp, FitErrorMinLengtMaxDepth) {
auto testLength = CPPFImdlp(2, 10, 0); auto testLength = CPPFImdlp(2, 10, 0);
auto testDepth = CPPFImdlp(3, 0, 0); auto testDepth = CPPFImdlp(3, 0, 0);
X = { 1, 2, 3 }; X = {1, 2, 3};
y = { 1, 2, 3 }; y = {1, 2, 3};
EXPECT_THROW_WITH_MESSAGE(testLength.fit(X, y), invalid_argument, "min_length must be greater than 2"); EXPECT_THROW_WITH_MESSAGE(testLength.fit(X, y), invalid_argument, "min_length must be greater than 2");
EXPECT_THROW_WITH_MESSAGE(testDepth.fit(X, y), invalid_argument, "max_depth must be greater than 0"); EXPECT_THROW_WITH_MESSAGE(testDepth.fit(X, y), invalid_argument, "max_depth must be greater than 0");
} }
TEST_F(TestFImdlp, FitErrorMaxCutPoints)
{ TEST_F(TestFImdlp, FitErrorMaxCutPoints) {
auto testmin = CPPFImdlp(2, 10, -1); auto testmin = CPPFImdlp(2, 10, -1);
auto testmax = CPPFImdlp(3, 0, 200); auto testmax = CPPFImdlp(3, 0, 200);
X = { 1, 2, 3 }; X = {1, 2, 3};
y = { 1, 2, 3 }; y = {1, 2, 3};
EXPECT_THROW_WITH_MESSAGE(testmin.fit(X, y), invalid_argument, "wrong proposed num_cuts value"); EXPECT_THROW_WITH_MESSAGE(testmin.fit(X, y), invalid_argument, "wrong proposed num_cuts value");
EXPECT_THROW_WITH_MESSAGE(testmax.fit(X, y), invalid_argument, "wrong proposed num_cuts value"); EXPECT_THROW_WITH_MESSAGE(testmax.fit(X, y), invalid_argument, "wrong proposed num_cuts value");
} }
TEST_F(TestFImdlp, SortIndices)
{ TEST_F(TestFImdlp, SortIndices) {
X = { 5.7, 5.3, 5.2, 5.1, 5.0, 5.6, 5.1, 6.0, 5.1, 5.9 }; X = {5.7f, 5.3f, 5.2f, 5.1f, 5.0f, 5.6f, 5.1f, 6.0f, 5.1f, 5.9f};
y = { 1, 1, 1, 1, 1, 2, 2, 2, 2, 2 }; y = {1, 1, 1, 1, 1, 2, 2, 2, 2, 2};
indices = { 4, 3, 6, 8, 2, 1, 5, 0, 9, 7 }; indices = {4, 3, 6, 8, 2, 1, 5, 0, 9, 7};
checkSortedVector(); checkSortedVector();
X = { 5.77, 5.88, 5.99 }; X = {5.77f, 5.88f, 5.99f};
y = { 1, 2, 1 }; y = {1, 2, 1};
indices = { 0, 1, 2 }; indices = {0, 1, 2};
checkSortedVector(); checkSortedVector();
X = { 5.33, 5.22, 5.11 }; X = {5.33f, 5.22f, 5.11f};
y = { 1, 2, 1 }; y = {1, 2, 1};
indices = { 2, 1, 0 }; indices = {2, 1, 0};
checkSortedVector(); checkSortedVector();
X = { 5.33, 5.22, 5.33 }; X = {5.33f, 5.22f, 5.33f};
y = { 2, 2, 1 }; y = {2, 2, 1};
indices = { 1, 2, 0 }; indices = {1, 2, 0};
} }
TEST_F(TestFImdlp, TestShortDatasets)
{ TEST_F(TestFImdlp, TestShortDatasets) {
vector<precision_t> computed; vector<precision_t> computed;
X = { 1 }; X = {1};
y = { 1 }; y = {1};
fit(X, y); fit(X, y);
computed = getCutPoints(); computed = getCutPoints();
EXPECT_EQ(computed.size(), 0); EXPECT_EQ(computed.size(), 0);
X = { 1, 3 }; X = {1, 3};
y = { 1, 2 }; y = {1, 2};
fit(X, y); fit(X, y);
computed = getCutPoints(); computed = getCutPoints();
EXPECT_EQ(computed.size(), 0); EXPECT_EQ(computed.size(), 0);
X = { 2, 4 }; X = {2, 4};
y = { 1, 2 }; y = {1, 2};
fit(X, y); fit(X, y);
computed = getCutPoints(); computed = getCutPoints();
EXPECT_EQ(computed.size(), 0); EXPECT_EQ(computed.size(), 0);
X = { 1, 2, 3 }; X = {1, 2, 3};
y = { 1, 2, 2 }; y = {1, 2, 2};
fit(X, y); fit(X, y);
computed = getCutPoints(); computed = getCutPoints();
EXPECT_EQ(computed.size(), 1); EXPECT_EQ(computed.size(), 1);
EXPECT_NEAR(computed[0], 1.5, precision); EXPECT_NEAR(computed[0], 1.5, precision);
} }
TEST_F(TestFImdlp, TestArtificialDataset)
{ TEST_F(TestFImdlp, TestArtificialDataset) {
fit(X, y); fit(X, y);
cutPoints_t expected = { 5.05 }; cutPoints_t expected = {5.05f};
vector<precision_t> computed = getCutPoints(); vector<precision_t> computed = getCutPoints();
int expectedSize = expected.size();
EXPECT_EQ(computed.size(), expected.size()); EXPECT_EQ(computed.size(), expected.size());
for (unsigned long i = 0; i < computed.size(); i++) { for (unsigned long i = 0; i < computed.size(); i++) {
EXPECT_NEAR(computed[i], expected[i], precision); EXPECT_NEAR(computed[i], expected[i], precision);
} }
} }
TEST_F(TestFImdlp, TestIris)
{ TEST_F(TestFImdlp, TestIris) {
vector<cutPoints_t> expected = { vector<cutPoints_t> expected = {
{ 5.45, 5.75 }, {5.45f, 5.75f},
{ 2.75, 2.85, 2.95, 3.05, 3.35 }, {2.75f, 2.85f, 2.95f, 3.05f, 3.35f},
{ 2.45, 4.75, 5.05 }, {2.45f, 4.75f, 5.05f},
{ 0.8, 1.75 } {0.8f, 1.75f}
}; };
int depths[] = { 3, 5, 5, 5 }; vector<int> depths = {3, 5, 4, 3};
auto test = CPPFImdlp(); auto test = CPPFImdlp();
//test_dataset(test, "iris.arff", expected, depths); test_dataset(test, "iris", expected, depths);
} }
TEST_F(TestFImdlp, ComputeCutPointsGCase)
{ TEST_F(TestFImdlp, ComputeCutPointsGCase) {
cutPoints_t expected; cutPoints_t expected;
expected = { 1.5 }; expected = {1.5};
samples_t X_ = { 0, 1, 2, 2, 2 }; samples_t X_ = {0, 1, 2, 2, 2};
labels_t y_ = { 1, 1, 1, 2, 2 }; labels_t y_ = {1, 1, 1, 2, 2};
fit(X_, y_); fit(X_, y_);
auto computed = getCutPoints(); auto computed = getCutPoints();
checkCutPoints(computed, expected); checkCutPoints(computed, expected);
} }
TEST_F(TestFImdlp, ValueCutPoint)
{ TEST_F(TestFImdlp, ValueCutPoint) {
// Case titles as stated in the doc // Case titles as stated in the doc
samples_t X1a{ 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 4.0 }; samples_t X1a{3.1f, 3.2f, 3.3f, 3.4f, 3.5f, 3.6f, 3.7f, 3.8f, 3.9f, 4.0f};
test_result(X1a, 6, 7.3 / 2, 6, "1a"); test_result(X1a, 6, 7.3f / 2, 6, "1a");
samples_t X2a = { 3.1, 3.2, 3.3, 3.4, 3.7, 3.7, 3.7, 3.8, 3.9, 4.0 }; samples_t X2a = {3.1f, 3.2f, 3.3f, 3.4f, 3.7f, 3.7f, 3.7f, 3.8f, 3.9f, 4.0f};
test_result(X2a, 6, 7.1 / 2, 4, "2a"); test_result(X2a, 6, 7.1f / 2, 4, "2a");
samples_t X2b = { 3.7, 3.7, 3.7, 3.7, 3.7, 3.7, 3.7, 3.8, 3.9, 4.0 }; samples_t X2b = {3.7f, 3.7f, 3.7f, 3.7f, 3.7f, 3.7f, 3.7f, 3.8f, 3.9f, 4.0f};
test_result(X2b, 6, 7.5 / 2, 7, "2b"); test_result(X2b, 6, 7.5f / 2, 7, "2b");
samples_t X3a = { 3.1, 3.2, 3.3, 3.4, 3.7, 3.7, 3.7, 3.8, 3.9, 4.0 }; samples_t X3a = {3.f, 3.2f, 3.3f, 3.4f, 3.7f, 3.7f, 3.7f, 3.8f, 3.9f, 4.0f};
test_result(X3a, 4, 7.1 / 2, 4, "3a"); test_result(X3a, 4, 7.1f / 2, 4, "3a");
samples_t X3b = { 3.1, 3.2, 3.3, 3.4, 3.7, 3.7, 3.7, 3.7, 3.7, 3.7 }; samples_t X3b = {3.1f, 3.2f, 3.3f, 3.4f, 3.7f, 3.7f, 3.7f, 3.7f, 3.7f, 3.7f};
test_result(X3b, 4, 7.1 / 2, 4, "3b"); test_result(X3b, 4, 7.1f / 2, 4, "3b");
samples_t X4a = { 3.1, 3.2, 3.7, 3.7, 3.7, 3.7, 3.7, 3.7, 3.9, 4.0 }; samples_t X4a = {3.1f, 3.2f, 3.7f, 3.7f, 3.7f, 3.7f, 3.7f, 3.7f, 3.9f, 4.0f};
test_result(X4a, 4, 6.9 / 2, 2, "4a"); test_result(X4a, 4, 6.9f / 2, 2, "4a");
samples_t X4b = { 3.7, 3.7, 3.7, 3.7, 3.7, 3.7, 3.7, 3.8, 3.9, 4.0 }; samples_t X4b = {3.7f, 3.7f, 3.7f, 3.7f, 3.7f, 3.7f, 3.7f, 3.8f, 3.9f, 4.0f};
test_result(X4b, 4, 7.5 / 2, 7, "4b"); test_result(X4b, 4, 7.5f / 2, 7, "4b");
samples_t X4c = { 3.1, 3.2, 3.7, 3.7, 3.7, 3.7, 3.7, 3.7, 3.7, 3.7 }; samples_t X4c = {3.1f, 3.2f, 3.7f, 3.7f, 3.7f, 3.7f, 3.7f, 3.7f, 3.7f, 3.7f};
test_result(X4c, 4, 6.9 / 2, 2, "4c"); test_result(X4c, 4, 6.9f / 2, 2, "4c");
} }
TEST_F(TestFImdlp, MaxDepth)
{ TEST_F(TestFImdlp, MaxDepth) {
// Set max_depth to 1 // Set max_depth to 1
auto test = CPPFImdlp(3, 1, 0); auto test = CPPFImdlp(3, 1, 0);
vector<cutPoints_t> expected = { vector<cutPoints_t> expected = {
{ 5.45 }, {5.45f},
{ 3.35 }, {3.35f},
{ 2.45 }, {2.45f},
{0.8 } {0.8f}
}; };
int depths[] = { 1, 1, 1, 1 }; vector<int> depths = {1, 1, 1, 1};
test_dataset(test, "iris", expected, depths); test_dataset(test, "iris", expected, depths);
} }
TEST_F(TestFImdlp, MinLength)
{ TEST_F(TestFImdlp, MinLength) {
auto test = CPPFImdlp(75, 100, 0); auto test = CPPFImdlp(75, 100, 0);
// Set min_length to 75 // Set min_length to 75
vector<cutPoints_t> expected = { vector<cutPoints_t> expected = {
{ 5.45, 5.75 }, {5.45f, 5.75f},
{ 2.85, 3.35 }, {2.85f, 3.35f},
{ 2.45, 4.75 }, {2.45f, 4.75f},
{ 0.8, 1.75 } {0.8f, 1.75f}
}; };
int depths[] = { 3, 2, 2, 2 }; vector<int> depths = {3, 2, 2, 2};
test_dataset(test, "iris", expected, depths); test_dataset(test, "iris", expected, depths);
} }
TEST_F(TestFImdlp, MinLengthMaxDepth)
{ TEST_F(TestFImdlp, MinLengthMaxDepth) {
// Set min_length to 75 // Set min_length to 75
auto test = CPPFImdlp(75, 2, 0); auto test = CPPFImdlp(75, 2, 0);
vector<cutPoints_t> expected = { vector<cutPoints_t> expected = {
{ 5.45, 5.75 }, {5.45f, 5.75f},
{ 2.85, 3.35 }, {2.85f, 3.35f},
{ 2.45, 4.75 }, {2.45f, 4.75f},
{ 0.8, 1.75 } {0.8f, 1.75f}
}; };
int depths[] = { 2, 2, 2, 2 }; vector<int> depths = {2, 2, 2, 2};
test_dataset(test, "iris", expected, depths); test_dataset(test, "iris", expected, depths);
} }
TEST_F(TestFImdlp, MaxCutPointsInteger)
{ TEST_F(TestFImdlp, MaxCutPointsInteger) {
// Set min_length to 75 // Set min_length to 75
auto test = CPPFImdlp(75, 2, 1); auto test = CPPFImdlp(75, 2, 1);
vector<cutPoints_t> expected = { vector<cutPoints_t> expected = {
{ 5.45 }, {5.45f},
{ 3.35 }, {3.35f},
{ 2.45 }, {2.45f},
{ 0.8} {0.8f}
}; };
int depths[] = { 1, 1, 1, 1 }; vector<int> depths = {1, 1, 1, 1};
test_dataset(test, "iris", expected, depths); test_dataset(test, "iris", expected, depths);
} }
TEST_F(TestFImdlp, MaxCutPointsFloat)
{ TEST_F(TestFImdlp, MaxCutPointsFloat) {
// Set min_length to 75 // Set min_length to 75
auto test = CPPFImdlp(75, 2, 0.2); auto test = CPPFImdlp(75, 2, 0.2f);
vector<cutPoints_t> expected = { vector<cutPoints_t> expected = {
{ 5.45, 5.75 }, {5.45f, 5.75f},
{ 2.85, 3.35 }, {2.85f, 3.35f},
{ 2.45, 4.75 }, {2.45f, 4.75f},
{ 0.8, 1.75 } {0.8f, 1.75f}
}; };
int depths[] = { 2, 2, 2, 2 }; vector<int> depths = {2, 2, 2, 2};
test_dataset(test, "iris", expected, depths); test_dataset(test, "iris", expected, depths);
} }
TEST_F(TestFImdlp, ProposedCuts)
{ TEST_F(TestFImdlp, ProposedCuts) {
vector<pair<float, size_t>> proposed_list = { { 0.1, 2}, { 0.5, 10}, {0.07, 1}, {1, 1}, {2, 2} }; vector<pair<float, size_t>> proposed_list = {{0.1f, 2},
size_t expected, computed; {0.5f, 10},
for (auto proposed_item : proposed_list) { {0.07f, 1},
{1.0f, 1},
{2.0f, 2}};
size_t expected;
size_t computed;
for (auto proposed_item: proposed_list) {
tie(proposed_cuts, expected) = proposed_item; tie(proposed_cuts, expected) = proposed_item;
computed = compute_max_num_cut_points(); computed = compute_max_num_cut_points();
ASSERT_EQ(expected, computed); ASSERT_EQ(expected, computed);

View File

@@ -5,19 +5,18 @@
namespace mdlp { namespace mdlp {
class TestMetrics: public Metrics, public testing::Test { class TestMetrics: public Metrics, public testing::Test {
public: public:
labels_t y; labels_t y_ = { 1, 1, 1, 1, 1, 2, 2, 2, 2, 2 };
samples_t X; indices_t indices_ = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
indices_t indices; precision_t precision = 0.000001f;
precision_t precision = 0.000001;
TestMetrics(): Metrics(y, indices) {} TestMetrics(): Metrics(y_, indices_) {};
void SetUp()
void SetUp() override
{ {
y = { 1, 1, 1, 1, 1, 2, 2, 2, 2, 2 }; setData(y_, indices_);
indices = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
setData(y, indices);
} }
}; };
TEST_F(TestMetrics, NumClasses) TEST_F(TestMetrics, NumClasses)
{ {
y = { 1, 1, 1, 1, 1, 1, 1, 1, 2, 1 }; y = { 1, 1, 1, 1, 1, 1, 1, 1, 2, 1 };
@@ -25,20 +24,22 @@ namespace mdlp {
EXPECT_EQ(2, computeNumClasses(0, 10)); EXPECT_EQ(2, computeNumClasses(0, 10));
EXPECT_EQ(2, computeNumClasses(8, 10)); EXPECT_EQ(2, computeNumClasses(8, 10));
} }
TEST_F(TestMetrics, Entropy) TEST_F(TestMetrics, Entropy)
{ {
EXPECT_EQ(1, entropy(0, 10)); EXPECT_EQ(1, entropy(0, 10));
EXPECT_EQ(0, entropy(0, 5)); EXPECT_EQ(0, entropy(0, 5));
y = { 1, 1, 1, 1, 1, 1, 1, 1, 2, 1 }; y = { 1, 1, 1, 1, 1, 1, 1, 1, 2, 1 };
setData(y, indices); setData(y, indices);
ASSERT_NEAR(0.468996, entropy(0, 10), precision); ASSERT_NEAR(0.468996f, entropy(0, 10), precision);
} }
TEST_F(TestMetrics, InformationGain) TEST_F(TestMetrics, InformationGain)
{ {
ASSERT_NEAR(1, informationGain(0, 5, 10), precision); ASSERT_NEAR(1, informationGain(0, 5, 10), precision);
ASSERT_NEAR(1, informationGain(0, 5, 10), precision); // For cache ASSERT_NEAR(1, informationGain(0, 5, 10), precision); // For cache
y = { 1, 1, 1, 1, 1, 1, 1, 1, 2, 1 }; y = { 1, 1, 1, 1, 1, 1, 1, 1, 2, 1 };
setData(y, indices); setData(y, indices);
ASSERT_NEAR(0.108032, informationGain(0, 5, 10), precision); ASSERT_NEAR(0.108032f, informationGain(0, 5, 10), precision);
} }
} }

View File

@@ -1,6 +1,9 @@
if [ -d build ] ; then if [ -d build ] ; then
rm -fr build rm -fr build
fi fi
if [ -d gcovr-report ] ; then
rm -fr gcovr-report
fi
cmake -S . -B build -Wno-dev cmake -S . -B build -Wno-dev
cmake --build build cmake --build build
cd build cd build