From 0ab6ca139ff3c2d8588ce0bc39edbc8fcd288bae Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Tue, 14 May 2024 13:04:18 -0500 Subject: [PATCH] test packaging in sell policy --- tests/toolkit/matl_sell_policy_tests.cc | 51 +++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tests/toolkit/matl_sell_policy_tests.cc b/tests/toolkit/matl_sell_policy_tests.cc index e1f9f05446..0d5e8a45ee 100644 --- a/tests/toolkit/matl_sell_policy_tests.cc +++ b/tests/toolkit/matl_sell_policy_tests.cc @@ -10,6 +10,7 @@ #include "error.h" #include "pyne.h" #include "toolkit/resource_buff.h" +#include "package.h" #include "test_context.h" #include "test_agents/test_facility.h" @@ -151,5 +152,55 @@ TEST_F(MatlSellPolicyTests, Trades) { delete req; } +TEST_F(MatlSellPolicyTests, Package) { + using cyclus::QueryResult; + + int dur = 5; + double throughput = 1; + + cyclus::MockSim sim(dur); + cyclus::Agent* a = new TestFacility(sim.context()); + + sim.context()->AddPrototype(a->prototype(), a); + sim.agent = sim.context()->CreateAgent(a->prototype()); + sim.AddSink("commod").Finalize(); + TestFacility* fac = dynamic_cast(sim.agent); + + cyclus::toolkit::ResBuf buf; + + double qty = 5; + CompMap cm; + cm[922350000] = 0.05; + cm[922380000] = 0.95; + Composition::Ptr comp = Composition::CreateFromMass(cm); + mat = Material::Create(a, qty, comp, Package::unpackaged_id()); + + buf.Push(mat); + + sim.context()->AddPackage("foo", 1, 2, "first"); + Package::Ptr p = sim.context()->GetPackageByName("foo"); + + cyclus::toolkit::MatlSellPolicy sellpol; + sellpol.Init(fac, &buf, "buf", 4, false, 0, p->id()) + .Set("commod").Start(); + + EXPECT_NO_THROW(sim.Run()); + + QueryResult qr_trans = sim.db().Query("Transactions", NULL); + QueryResult qr_res = sim.db().Query("Resources", NULL); + EXPECT_EQ(3, qr_trans.rows.size()); + + EXPECT_EQ(0, qr_trans.GetVal("Time", 0)); + EXPECT_EQ(0, qr_trans.GetVal("Time", 1)); + EXPECT_EQ(1, qr_trans.GetVal("Time", 2)); + + // Resource 0 is the material of 5 that we first created. Resource 1/2 is + // the first resource split into 3 and 2. Resource 3/4 is split into 1 and 2 + EXPECT_NEAR(2, qr_res.GetVal("Quantity", 2), 0.00001); + EXPECT_NEAR(2, qr_res.GetVal("Quantity", 4), 0.00001); + + // All material should have been transacted, including the resource of size 1 + EXPECT_EQ(0, buf.quantity()); } } +} \ No newline at end of file