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
coverage:
if [ -d fimdlp/testcpp/build/CMakeFiles ]; then rm -fr fimdlp/testcpp/build/CMakeFiles/* ; fi;
make test
cd fimdlp/testcpp && ./cover

View File

@@ -41,12 +41,10 @@ namespace mdlp {
X = X_;
y = y_;
if (X.size() != y.size()) {
cerr << "X and y must have the same size" << endl;
return *this;
throw invalid_argument("X and y must have the same size");
}
if (X.size() == 0) {
cerr << "X and y must have at least one element" << endl;
return *this;
if (X.size() == 0 || y.size() == 0) {
throw invalid_argument("X and y must have at least one element");
}
this->indices = sortIndices(X_);
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)
{
X = { 5.7, 5.3, 5.2, 5.1, 5.0, 5.6, 5.1, 6.0, 5.1, 5.9 };