Skip to content

Commit

Permalink
Merge pull request #1712 from gonuke/package_tests
Browse files Browse the repository at this point in the history
add tests for Package
  • Loading branch information
nuclearkatie committed Mar 31, 2024
2 parents 2eab074 + 6aa3f9e commit 2fcd1be
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ Since last release
* Adds support for Cython3 (#1636)
* Adds TotalInvTracker, which allows an inventory cap to be set for multiple resource buffers, and is now required for material buy policy (#1646)
* AddMutalReqs and AddReciepe functions and exclusive bids in python API of DRE (#1584)
* Created Package class and optional declaration of packages in input files (#1673, #1699), package id is default unpackaged (#1711) and is a member of resources (materials/products) (#1675). Can pop resources as packaged from resource buffer, pushing resource onto a buffer defaults to stripping packaging (#1683)
* Created Package class and optional declaration of packages in input files (#1673, #1699, #1712), package id is default unpackaged (#1711) and is a member of
resources (materials/products) (#1675). Can pop resources as packaged from resource buffer, pushing resource onto a buffer defaults to stripping packaging (#1683)
* CI support for Rocky Linux (#1691)
* Added support for a ResBuf to behave as a single bulk storage with mixing & extraction of resources (#1687)

Expand Down
3 changes: 2 additions & 1 deletion src/package.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

namespace cyclus {

int Package::next_id_ = 1;
// unpackaged id is 1, so start the user-declared packaging id at 2
int Package::next_id_ = 2;

template <class T>
double Package::GetFillMass(typename T::Ptr r) {
Expand Down
5 changes: 3 additions & 2 deletions src/package.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ class Package {
Package(std::string name, double fill_min, double fill_max, std::string strategy);

private:
std::string name_;
static const int unpackaged_id_ = 1;
static int next_id_;

std::string name_;
int id_;
double fill_min_;
double fill_max_;
std::string strategy_;
static const int unpackaged_id_ = 1;
};

} // namespace cyclus
Expand Down
7 changes: 2 additions & 5 deletions src/product.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ int Product::package_id() {
}

void Product::ChangePackageId(int new_package_id) {
if (ctx_ != NULL) {
throw ValueError("Package Id cannot be changed with NULL context");
}
if (new_package_id == package_id_) {
if (new_package_id == package_id_ || ctx_ == NULL) {
// no change needed
return;
}
Expand All @@ -97,7 +94,7 @@ void Product::ChangePackageId(int new_package_id) {
if (quantity_ >= min && quantity_ <= max) {
package_id_ = new_package_id;
} else {
throw ValueError("Material quantity is outside of package fill limits.");
throw ValueError("Product quantity is outside of package fill limits.");
}
}

Expand Down
42 changes: 42 additions & 0 deletions tests/package_tests.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <string>

#include <gtest/gtest.h>

#include "package.h"

using cyclus::Package;

TEST(PackageTests, Create) {

std::string exp_name = "foo";
double exp_min = 0.1;
double exp_max = 0.9;
std::string exp_strat = "first";

Package::Ptr p = Package::Create(exp_name, exp_min, exp_max, exp_strat);

EXPECT_EQ(exp_name, p->name());
EXPECT_DOUBLE_EQ(exp_min, p->fill_min());
EXPECT_DOUBLE_EQ(exp_max, p->fill_max());
EXPECT_EQ(exp_strat, p->strategy());

// note: can't test this against a specific package ID because
// that value changes depending on which order all the
// tests are run and whether they are all run
// Therefore: test that it's not the same as the unpackaged ID
EXPECT_NE(Package::unpackaged_id(), p->id());

Package::Ptr q = Package::Create(exp_name, exp_min, exp_max, exp_strat);
// note: can't test this against a specific package ID because
// that value changes depending on which order all the
// tests are run and whether they are all run
// Therefore: test that it's not the same as the unpackaged ID
// or as the previous package
EXPECT_NE(Package::unpackaged_id(), q->id());
EXPECT_NE(q->id(), p->id());

}

TEST(PackageTests, UnpackagedID) {
EXPECT_EQ(1, Package::unpackaged_id());
}

0 comments on commit 2fcd1be

Please sign in to comment.