diff --git a/src/package.cc b/src/package.cc index 99bb38000a..fc6829449b 100644 --- a/src/package.cc +++ b/src/package.cc @@ -44,7 +44,7 @@ double Package::GetFillMass(double qty) { int num_max_fill = std::ceil(qty / fill_max_); if (num_min_fill >= num_max_fill) { // all material can fit in package(s) - double fill_mass = qty / num_max_fill; + fill_mass = qty / num_max_fill; } else { // some material will remain unpackaged, fill up as many max packages as possible fill_mass = fill_max_; diff --git a/tests/package_tests.cc b/tests/package_tests.cc index 023be279a5..52c80a0d38 100644 --- a/tests/package_tests.cc +++ b/tests/package_tests.cc @@ -1,8 +1,11 @@ #include #include +#include "error.h" #include "package.h" +#include "test_context.h" +#include "test_agents/test_facility.h" using cyclus::Package; @@ -40,3 +43,44 @@ TEST(PackageTests, Create) { TEST(PackageTests, UnpackagedID) { EXPECT_EQ(1, Package::unpackaged_id()); } + +TEST(PackageTests, InvalidPackage) { + // can't create package with name "unpackaged" + EXPECT_THROW(Package::Create("unpackaged", 0, 1, "first"), cyclus::ValueError); + // can't have negative min/max + EXPECT_THROW(Package::Create("foo", -1, 1, "first"), cyclus::ValueError); + EXPECT_THROW(Package::Create("foo", 0, -1, "first"), cyclus::ValueError); + // can't have min bigger than max + EXPECT_THROW(Package::Create("foo", 100, 1, "first"), cyclus::ValueError); +} + +TEST(PackageTests, GetFillMass) { + double min = 0.3; + double max = 0.9; + double tight_min = 0.85; + + Package::Ptr p = Package::Create("foo", min, max, "first"); + Package::Ptr q = Package::Create("bar", min, max, "equal"); + Package::Ptr r = Package::Create("bar", tight_min, max, "equal"); + + double exp; + + double no_fit = 0.05; + EXPECT_EQ(0, p->GetFillMass(no_fit)); + EXPECT_EQ(0, q->GetFillMass(no_fit)); + + double perfect_fit = 0.9; + EXPECT_EQ(perfect_fit, p->GetFillMass(perfect_fit)); + EXPECT_EQ(perfect_fit, q->GetFillMass(perfect_fit)); + + double partial_fit = 1; + EXPECT_EQ(max, p->GetFillMass(partial_fit)); + exp = partial_fit / 2; + EXPECT_EQ(exp, q->GetFillMass(partial_fit)); + EXPECT_EQ(max, r->GetFillMass(partial_fit)); + + double two_packages = 1.4; + EXPECT_EQ(max, p->GetFillMass(two_packages)); + exp = two_packages / 2; + EXPECT_EQ(exp, q->GetFillMass(two_packages)); +} \ No newline at end of file