Skip to content

Commit

Permalink
more package test
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearkatie committed May 20, 2024
1 parent b70a1a0 commit 95ff3f0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/package.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
44 changes: 44 additions & 0 deletions tests/package_tests.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include <string>

#include <gtest/gtest.h>
#include "error.h"

#include "package.h"
#include "test_context.h"
#include "test_agents/test_facility.h"

using cyclus::Package;

Expand Down Expand Up @@ -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));
}

0 comments on commit 95ff3f0

Please sign in to comment.