added test for xml node Discrete constructor

This commit is contained in:
myerspat 2022-12-19 17:25:20 -05:00
parent 90509d928b
commit 748e7da3f9

View file

@ -1,6 +1,7 @@
#include "openmc/distribution.h"
#include "openmc/random_lcg.h"
#include <catch2/catch_test_macros.hpp>
#include <pugixml.hpp>
TEST_CASE("Test alias method sampling of a discrete distribution")
{
@ -38,3 +39,25 @@ TEST_CASE("Test alias method sampling of a discrete distribution")
// expected mean
REQUIRE(std::abs(dist_mean - mean) < 3 * std);
}
TEST_CASE("Test alias sampling method for pugixml constructor")
{
// XML doc node for Discrete contructor
pugi::xml_document doc;
pugi::xml_node energy = doc.append_child("energy");
pugi::xml_node parameters = energy.append_child("parameters");
parameters.append_child(pugi::node_pcdata)
.set_value("17140457.745328166 1.0");
// Initialize discrete distribution and seed
openmc::Discrete dist(energy);
uint64_t seed = openmc::init_seed(0, 0);
// Assertions
REQUIRE(dist.x().size() == 1);
REQUIRE(dist.p().size() == 1);
REQUIRE(dist.alias().size() == 0);
REQUIRE(dist.x()[0] == 17140457.745328166);
REQUIRE(dist.p()[0] == 1.0);
REQUIRE(dist.sample(&seed) == 17140457.745328166);
}