diff --git a/Makefile b/Makefile index b7d92df..9b99264 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/fimdlp/CPPFImdlp.cpp b/fimdlp/CPPFImdlp.cpp index 27621d3..4b415c6 100644 --- a/fimdlp/CPPFImdlp.cpp +++ b/fimdlp/CPPFImdlp.cpp @@ -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); diff --git a/fimdlp/cppfimdlp.cpython-310-darwin.so b/fimdlp/cppfimdlp.cpython-310-darwin.so index 285ee7f..60cc322 100755 Binary files a/fimdlp/cppfimdlp.cpython-310-darwin.so and b/fimdlp/cppfimdlp.cpython-310-darwin.so differ diff --git a/fimdlp/testcpp/FImdlp_unittest.cc b/fimdlp/testcpp/FImdlp_unittest.cc index ced121f..e16a47f 100644 --- a/fimdlp/testcpp/FImdlp_unittest.cc +++ b/fimdlp/testcpp/FImdlp_unittest.cc @@ -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 };