Skip to content

Commit

Permalink
more comments on testing
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearkatie committed May 30, 2024
1 parent 76cf88f commit 94878c4
Showing 1 changed file with 56 additions and 7 deletions.
63 changes: 56 additions & 7 deletions src/storage_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -873,10 +873,10 @@ TEST_F(StorageTest, CCap_Inventory) {
}

TEST_F(StorageTest, PackageExactly) {
// resource can be packaged without splitting or merging
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;
Expand All @@ -893,6 +893,7 @@ TEST_F(StorageTest, PackageExactly) {
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);
// two transactions out of storage, happening at time 1 and 2
EXPECT_EQ(2, qr_trans.rows.size());

EXPECT_EQ(1, qr_trans.GetVal<int>("Time", 0));
Expand All @@ -901,17 +902,17 @@ TEST_F(StorageTest, PackageExactly) {
std::vector<cyclus::Cond> res_conds;
res_conds.push_back(cyclus::Cond("PackageName", "==", p->name()));
cyclus::QueryResult qr_res = sim.db().Query("Resources", &res_conds);
// two resources that have been packaged, each of size two
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) {
// Resources must be split into two to package. Packaging strategy equal
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;
Expand All @@ -928,6 +929,8 @@ TEST_F(StorageTest, PackageSplitEqual) {
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);
// four transactions out of storage. Each resource is split, so two
// transactions at time 1, two at time 2
EXPECT_EQ(4, qr_trans.rows.size());

EXPECT_EQ(1, qr_trans.GetVal<int>("Time", 0));
Expand All @@ -938,11 +941,53 @@ TEST_F(StorageTest, PackageSplitEqual) {
std::vector<cyclus::Cond> res_conds;
res_conds.push_back(cyclus::Cond("PackageName", "==", p->name()));
cyclus::QueryResult qr_res = sim.db().Query("Resources", &res_conds);
// because package does split-equally, resources are all of size 1.5 (3/2)
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);
EXPECT_EQ(1.5, qr_res.GetVal<double>("Quantity", 0));
EXPECT_EQ(1.5, qr_res.GetVal<double>("Quantity", 1));
EXPECT_EQ(1.5, qr_res.GetVal<double>("Quantity", 2));
EXPECT_EQ(1.5, qr_res.GetVal<double>("Quantity", 3));
}

TEST_F(StorageTest, PackageSplitFirst) {
// Resources must be split into two to package. Packaging strategy first
std::string config =
" <in_commods> <val>commodity</val> </in_commods> "
" <out_commods> <val>commodity1</val> </out_commods> "
" <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()->GetPackage("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);
// four transactions out of storage. Each resource is split, so two
// transactions at time 1, two at time 2
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("PackageName", "==", p->name()));
cyclus::QueryResult qr_res = sim.db().Query("Resources", &res_conds);
// because package does split-first, resources are size 2 and 1
EXPECT_EQ(qr_res.rows.size(), 4);
EXPECT_EQ(2, qr_res.GetVal<double>("Quantity", 0));
EXPECT_EQ(1, qr_res.GetVal<double>("Quantity", 1));
EXPECT_EQ(2, qr_res.GetVal<double>("Quantity", 2));
EXPECT_EQ(1, qr_res.GetVal<double>("Quantity", 3));
}

TEST_F(StorageTest, PackageMerge) {
Expand All @@ -967,6 +1012,9 @@ TEST_F(StorageTest, PackageMerge) {
tr_conds.push_back(cyclus::Cond("Commodity", "==", std::string("commodity1")));

cyclus::QueryResult qr_trans = sim.db().Query("Transactions", &tr_conds);
// two transactions out of storage. Because the source only provides 0.5 each
// time step, it takes two time steps to acquire enough material to package.
// Therefore transactions at time 2 and 4
EXPECT_EQ(2, qr_trans.rows.size());

EXPECT_EQ(2, qr_trans.GetVal<int>("Time", 0));
Expand All @@ -975,6 +1023,7 @@ TEST_F(StorageTest, PackageMerge) {
std::vector<cyclus::Cond> res_conds;
res_conds.push_back(cyclus::Cond("PackageName", "==", p->name()));
cyclus::QueryResult qr_res = sim.db().Query("Resources", &res_conds);
// Combines two 0.5 mass resources to make packages with mass 1
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);
Expand Down

0 comments on commit 94878c4

Please sign in to comment.