Add some tests

This commit is contained in:
2022-12-04 22:16:08 +01:00
parent cd3df9f5fc
commit 80c1802e10
4 changed files with 16 additions and 5 deletions

View File

@@ -11,6 +11,7 @@ test:
cd fimdlp/testcpp && ./test cd fimdlp/testcpp && ./test
coverage: coverage:
if [ -d fimdlp/testcpp/build/CMakeFiles ]; then rm -fr fimdlp/testcpp/build/CMakeFiles/* ; fi;
make test make test
cd fimdlp/testcpp && ./cover cd fimdlp/testcpp && ./cover

View File

@@ -41,12 +41,10 @@ namespace mdlp {
X = X_; X = X_;
y = y_; y = y_;
if (X.size() != y.size()) { if (X.size() != y.size()) {
cerr << "X and y must have the same size" << endl; throw invalid_argument("X and y must have the same size");
return *this;
} }
if (X.size() == 0) { if (X.size() == 0 || y.size() == 0) {
cerr << "X and y must have at least one element" << endl; throw invalid_argument("X and y must have at least one element");
return *this;
} }
this->indices = sortIndices(X_); this->indices = sortIndices(X_);
this->xDiscretized = labels(X.size(), -1); this->xDiscretized = labels(X.size(), -1);

View File

@@ -59,6 +59,18 @@ namespace mdlp {
} }
}; };
TEST_F(TestFImdlp, FitErrorEmptyDataset)
{
X = samples();
y = labels();
EXPECT_THROW(fit(X, y), std::invalid_argument);
}
TEST_F(TestFImdlp, FitErrorDifferentSize)
{
X = { 1, 2, 3 };
y = { 1, 2 };
EXPECT_THROW(fit(X, y), std::invalid_argument);
}
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.7, 5.3, 5.2, 5.1, 5.0, 5.6, 5.1, 6.0, 5.1, 5.9 };