Fix tests

This commit is contained in:
2024-01-09 18:44:41 +01:00
parent 2fd83e940a
commit d145e71909
6 changed files with 23 additions and 24 deletions

View File

@@ -1,12 +1,11 @@
if(ENABLE_TESTING)
set(TEST_PLATFORM "unit_tests_platform")
include_directories(
${BayesNet_SOURCE_DIR}/src/BayesNet
${BayesNet_SOURCE_DIR}/src/Platform
${BayesNet_SOURCE_DIR}/lib/Files
${BayesNet_SOURCE_DIR}/lib/mdlp
${BayesNet_SOURCE_DIR}/lib/json/include
${BayesNet_SOURCE_DIR}/lib/argparse/include
${Platform_SOURCE_DIR}/src/Platform
${Platform_SOURCE_DIR}/lib/argparse/include
${Platform_SOURCE_DIR}/lib/PyClassifiers/lib/BayesNet/lib/mdlp
${Platform_SOURCE_DIR}/lib/Files
${CMAKE_BINARY_DIR}/configured_files/include
)
set(TEST_SOURCES_PLATFORM TestUtils.cc)
add_executable(${TEST_PLATFORM} ${TEST_SOURCES_PLATFORM})

View File

@@ -1,10 +1,11 @@
#include "TestUtils.h"
#include "config.h"
class Paths {
public:
static std::string datasets()
{
return "../../data/";
return { data_path.begin(), data_path.end() };
}
};
@@ -34,7 +35,7 @@ std::vector<mdlp::labels_t> discretizeDataset(std::vector<mdlp::samples_t>& X, m
return Xd;
}
bool file_exists(const std::std::string& name)
bool file_exists(const std::string& name)
{
if (FILE* file = fopen(name.c_str(), "r")) {
fclose(file);
@@ -44,7 +45,7 @@ bool file_exists(const std::std::string& name)
}
}
tuple<torch::Tensor, torch::Tensor, std::vector<std::string>, std::string, map<std::string, std::vector<int>>> loadDataset(const std::std::string& name, bool class_last, bool discretize_dataset)
tuple<torch::Tensor, torch::Tensor, std::vector<std::string>, std::string, map<std::string, std::vector<int>>> loadDataset(const std::string& name, bool class_last, bool discretize_dataset)
{
auto handler = ArffFiles();
handler.load(Paths::datasets() + static_cast<std::string>(name) + ".arff", class_last);
@@ -78,7 +79,7 @@ tuple<torch::Tensor, torch::Tensor, std::vector<std::string>, std::string, map<s
return { Xd, torch::tensor(y, torch::kInt32), features, className, states };
}
tuple<std::vector<std::vector<int>>, std::vector<int>, std::vector<std::string>, std::string, map<std::string, std::vector<int>>> loadFile(const std::std::string& name)
tuple<std::vector<std::vector<int>>, std::vector<int>, std::vector<std::string>, std::string, map<std::string, std::vector<int>>> loadFile(const std::string& name)
{
auto handler = ArffFiles();
handler.load(Paths::datasets() + static_cast<std::string>(name) + ".arff");

View File

@@ -4,11 +4,11 @@
#include <string>
#include <vector>
#include <map>
#include <std::tuple>
#include <tuple>
#include "ArffFiles.h"
#include "CPPFImdlp.h"
bool file_exists(const std::std::string& name);
bool file_exists(const std::string& name);
std::pair<vector<mdlp::labels_t>, map<std::string, int>> discretize(std::vector<mdlp::samples_t>& X, mdlp::labels_t& y, std::vector<string> features);
std::vector<mdlp::labels_t> discretizeDataset(std::vector<mdlp::samples_t>& X, mdlp::labels_t& y);
std::tuple<vector<vector<int>>, std::vector<int>, std::vector<string>, std::string, map<std::string, std::vector<int>>> loadFile(const std::string& name);