BayesNet/tests/TestBayesNetwork.cc

34 lines
1.0 KiB
C++
Raw Normal View History

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>
#include "TestUtils.h"
#include "KDB.h"
2023-07-18 11:44:08 +00:00
2023-10-05 13:45:36 +00:00
TEST_CASE("Test Bayesian Network", "[BayesNet]")
2023-07-18 11:44:08 +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"});
}
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");
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
}