2023-07-18 11:44:08 +00:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
|
|
#include <catch2/catch_approx.hpp>
|
|
|
|
#include <catch2/generators/catch_generators.hpp>
|
|
|
|
#include <string>
|
2023-07-20 08:40:08 +00:00
|
|
|
#include "KDB.h"
|
2023-07-18 11:44:08 +00:00
|
|
|
|
|
|
|
TEST_CASE("Test Bayesian Network")
|
|
|
|
{
|
2023-07-19 13:05:44 +00:00
|
|
|
auto [Xd, y, features, className, states] = loadFile("iris");
|
2023-07-18 11:44:08 +00:00
|
|
|
|
|
|
|
SECTION("Test get features")
|
|
|
|
{
|
|
|
|
auto net = bayesnet::Network();
|
2023-08-05 12:40:42 +00:00
|
|
|
net.addNode("A");
|
|
|
|
net.addNode("B");
|
2023-07-18 11:44:08 +00:00
|
|
|
REQUIRE(net.getFeatures() == vector<string>{"A", "B"});
|
2023-08-05 12:40:42 +00:00
|
|
|
net.addNode("C");
|
2023-07-18 11:44:08 +00:00
|
|
|
REQUIRE(net.getFeatures() == vector<string>{"A", "B", "C"});
|
|
|
|
}
|
2023-07-19 13:05:44 +00:00
|
|
|
SECTION("Test get edges")
|
|
|
|
{
|
|
|
|
auto net = bayesnet::Network();
|
2023-08-05 12:40:42 +00:00
|
|
|
net.addNode("A");
|
|
|
|
net.addNode("B");
|
|
|
|
net.addNode("C");
|
2023-07-19 13:05:44 +00:00
|
|
|
net.addEdge("A", "B");
|
|
|
|
net.addEdge("B", "C");
|
|
|
|
REQUIRE(net.getEdges() == vector<pair<string, string>>{ {"A", "B"}, { "B", "C" } });
|
|
|
|
net.addEdge("A", "C");
|
|
|
|
REQUIRE(net.getEdges() == vector<pair<string, string>>{ {"A", "B"}, { "A", "C" }, { "B", "C" } });
|
|
|
|
}
|
2023-07-18 11:44:08 +00:00
|
|
|
}
|