Skip to content

Commit

Permalink
test packaging in sell policy
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearkatie committed May 14, 2024
1 parent 89bd1df commit 0ab6ca1
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions tests/toolkit/matl_sell_policy_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<cyclus::Agent>(a->prototype());
sim.AddSink("commod").Finalize();
TestFacility* fac = dynamic_cast<TestFacility*>(sim.agent);

cyclus::toolkit::ResBuf<cyclus::Material> 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<int>("Time", 0));
EXPECT_EQ(0, qr_trans.GetVal<int>("Time", 1));
EXPECT_EQ(1, qr_trans.GetVal<int>("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<double>("Quantity", 2), 0.00001);
EXPECT_NEAR(2, qr_res.GetVal<double>("Quantity", 4), 0.00001);

// All material should have been transacted, including the resource of size 1
EXPECT_EQ(0, buf.quantity());
}
}
}

0 comments on commit 0ab6ca1

Please sign in to comment.