Skip to content

Commit

Permalink
package tests for storage
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearkatie committed May 23, 2024
1 parent de4fa10 commit 9a7cb92
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
110 changes: 110 additions & 0 deletions src/storage_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void StorageTest::InitParameters(){
max_inv_size = 200;
throughput = 20;
discrete_handling = 0;
package = "foo";
// Active period longer than any of the residence time related-tests needs


Expand All @@ -42,13 +43,15 @@ void StorageTest::SetUpStorage(){
src_facility_->inventory_tracker.set_capacity(max_inv_size);
src_facility_->throughput = throughput;
src_facility_->discrete_handling = discrete_handling;
src_facility_->package = package;
}

void StorageTest::TestInitState(Storage* fac){
EXPECT_EQ(residence_time, fac->residence_time);
EXPECT_EQ(max_inv_size, fac->max_inv_size);
EXPECT_EQ(throughput, fac->throughput);
EXPECT_EQ(in_r1, fac->in_recipe);
EXPECT_EQ(package, fac->package);
}

void StorageTest::TestAddMat(Storage* fac,
Expand Down Expand Up @@ -869,6 +872,113 @@ TEST_F(StorageTest, CCap_Inventory) {
EXPECT_EQ(1, qr.GetVal<double>("Quantity", 4));
}

TEST_F(StorageTest, PackageExactly) {
std::string config =
" <in_commods> <val>spent_fuel</val> </in_commods> "
" <out_commods> <val>dry_spent</val> </out_commods> "
" <throughput>10</throughput> "
" <package>foo</package>";

int simdur = 3;

cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
sim.context()->AddPackage("foo", 1, 2, "first");
cyclus::Package::Ptr p = sim.context()->GetPackageByName("foo");

sim.AddSource("spent_fuel").capacity(2).Finalize();
sim.AddSink("dry_spent").Finalize();

int id = sim.Run();

std::vector<cyclus::Cond> tr_conds;
tr_conds.push_back(cyclus::Cond("Commodity", "==", std::string("dry_spent")));
cyclus::QueryResult qr_trans = sim.db().Query("Transactions", &tr_conds);
EXPECT_EQ(2, qr_trans.rows.size());

EXPECT_EQ(1, qr_trans.GetVal<int>("Time", 0));
EXPECT_EQ(2, qr_trans.GetVal<int>("Time", 1));

std::vector<cyclus::Cond> res_conds;
res_conds.push_back(cyclus::Cond("PackageId", "==", p->id()));
cyclus::QueryResult qr_res = sim.db().Query("Resources", &res_conds);
EXPECT_EQ(qr_res.rows.size(), 2);
// Given the PRNG with default seed, the resource should have mass 9.41273
EXPECT_EQ(qr_res.GetVal<double>("Quantity", 0), 2);
EXPECT_EQ(qr_res.GetVal<double>("Quantity", 1), 2);
}

TEST_F(StorageTest, PackageSplitEqual) {
std::string config =
" <in_commods> <val>commodity</val> </in_commods> "
" <out_commods> <val>commodity1</val> </out_commods> "
" <throughput>10</throughput> "
" <package>foo</package>";

int simdur = 3;

cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
sim.context()->AddPackage("foo", 1, 2, "equal");
cyclus::Package::Ptr p = sim.context()->GetPackageByName("foo");

sim.AddSource("commodity").capacity(3).Finalize();
sim.AddSink("commodity1").Finalize();

int id = sim.Run();

std::vector<cyclus::Cond> tr_conds;
tr_conds.push_back(cyclus::Cond("Commodity", "==", std::string("commodity1")));
cyclus::QueryResult qr_trans = sim.db().Query("Transactions", &tr_conds);
EXPECT_EQ(4, qr_trans.rows.size());

EXPECT_EQ(1, qr_trans.GetVal<int>("Time", 0));
EXPECT_EQ(1, qr_trans.GetVal<int>("Time", 1));
EXPECT_EQ(2, qr_trans.GetVal<int>("Time", 2));
EXPECT_EQ(2, qr_trans.GetVal<int>("Time", 3));

std::vector<cyclus::Cond> res_conds;
res_conds.push_back(cyclus::Cond("PackageId", "==", p->id()));
cyclus::QueryResult qr_res = sim.db().Query("Resources", &res_conds);
EXPECT_EQ(qr_res.rows.size(), 4);
EXPECT_EQ(qr_res.GetVal<double>("Quantity", 0), 1.5);
EXPECT_EQ(qr_res.GetVal<double>("Quantity", 1), 1.5);
EXPECT_EQ(qr_res.GetVal<double>("Quantity", 2), 1.5);
EXPECT_EQ(qr_res.GetVal<double>("Quantity", 2), 1.5);
}

TEST_F(StorageTest, PackageMerge) {
std::string config =
" <in_commods> <val>commodity</val> </in_commods> "
" <out_commods> <val>commodity1</val> </out_commods> "
" <throughput>1</throughput> "
" <package>foo</package>";

int simdur = 5;

cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);
sim.context()->AddPackage("foo", 1, 2, "first");
cyclus::Package::Ptr p = sim.context()->GetPackageByName("foo");

sim.AddSource("commodity").capacity(0.5).Finalize();
sim.AddSink("commodity1").Finalize();

int id = sim.Run();

std::vector<cyclus::Cond> tr_conds;
tr_conds.push_back(cyclus::Cond("Commodity", "==", std::string("commodity1")));

cyclus::QueryResult qr_trans = sim.db().Query("Transactions", &tr_conds);
EXPECT_EQ(2, qr_trans.rows.size());

EXPECT_EQ(2, qr_trans.GetVal<int>("Time", 0));
EXPECT_EQ(4, qr_trans.GetVal<int>("Time", 1));

std::vector<cyclus::Cond> res_conds;
res_conds.push_back(cyclus::Cond("PackageId", "==", p->id()));
cyclus::QueryResult qr_res = sim.db().Query("Resources", &res_conds);
EXPECT_EQ(qr_res.rows.size(), 2);
EXPECT_EQ(qr_res.GetVal<double>("Quantity", 0), 1);
EXPECT_EQ(qr_res.GetVal<double>("Quantity", 1), 1);
}

} // namespace cycamore

Expand Down
1 change: 1 addition & 0 deletions src/storage_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class StorageTest : public ::testing::Test {
int residence_time;
double throughput, max_inv_size;
bool discrete_handling;
std::string package;
};
} // namespace cycamore
#endif // STORAGE_TESTS_H_
Expand Down

0 comments on commit 9a7cb92

Please sign in to comment.