Add tests for the quiet parameter and fix initialization mistake

This commit is contained in:
2024-12-13 14:32:27 +01:00
parent d1335f9f8a
commit 0406322c62
4 changed files with 46 additions and 8 deletions

View File

@@ -12,7 +12,7 @@
TEST_CASE("Version Test", "[Folding]")
{
std::string actual_version = { folding_project_version.begin(), folding_project_version.end() };
std::string actual_version = "1.1.1";
auto data = std::vector<int>(100);
folding::StratifiedKFold stratified_kfold(5, data, 17);
REQUIRE(stratified_kfold.version() == actual_version);
@@ -186,4 +186,38 @@ TEST_CASE("StratifiedKFold Test", "[Folding]")
}
}
}
}
TEST_CASE("Stratified KFold quiet parameter", "[Folding]")
{
auto raw = RawDatasets("glass", true);
std::string expected = "Warning! The number of samples in class 2 (9) is less than the number of folds (10).\n";
SECTION("With vectors")
{
// Redirect cerr to a stringstream
std::streambuf* originalCerrBuffer = std::cerr.rdbuf();
std::stringstream capturedOutput;
std::cerr.rdbuf(capturedOutput.rdbuf());
// StratifiedKFold with quiet parameter set to false
folding::StratifiedKFold stratified_kfold(10, raw.yv, 17, false);
// Restore the original cerr buffer
std::cerr.rdbuf(originalCerrBuffer);
// Check the captured output
REQUIRE(capturedOutput.str() == expected);
REQUIRE(stratified_kfold.isFaulty());
}
SECTION("With tensors")
{
// Redirect cerr to a stringstream
std::streambuf* originalCerrBuffer = std::cerr.rdbuf();
std::stringstream capturedOutput;
std::cerr.rdbuf(capturedOutput.rdbuf());
// StratifiedKFold with quiet parameter set to false
folding::StratifiedKFold stratified_kfold(10, raw.yt, 17, false);
// Restore the original cerr buffer
std::cerr.rdbuf(originalCerrBuffer);
// Check the captured output
REQUIRE(capturedOutput.str() == expected);
REQUIRE(stratified_kfold.isFaulty());
}
}