From 1378b2257f8a6a3e1359a15a709894669f7b4f19 Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Mon, 27 Nov 2023 18:09:50 -0700 Subject: [PATCH] test multiple cycles of active/dormant --- tests/toolkit/matl_buy_policy_tests.cc | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/toolkit/matl_buy_policy_tests.cc b/tests/toolkit/matl_buy_policy_tests.cc index a1852734d8..56d3b166d3 100644 --- a/tests/toolkit/matl_buy_policy_tests.cc +++ b/tests/toolkit/matl_buy_policy_tests.cc @@ -204,6 +204,46 @@ TEST_F(MatlBuyPolicyTests, ActiveDormant) { EXPECT_NO_THROW(sim.Run()); EXPECT_DOUBLE_EQ(2, inbuf.quantity()); + + delete a; +} + +TEST_F(MatlBuyPolicyTests, ActiveDormantMultipleCycles) { + using cyclus::QueryResult; + + int active = 2; + int dormant = 3; + int dur = 15; + 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.AddSource("commod1").Finalize(); + + TestFacility* fac = dynamic_cast(sim.agent); + + cyclus::toolkit::ResBuf inbuf; + cyclus::toolkit::MatlBuyPolicy policy; + policy.Init(fac, &inbuf, "inbuf", throughput, active, dormant) + .Set("commod1").Start(); + + EXPECT_NO_THROW(sim.Run()); + + QueryResult qr = sim.db().Query("Transactions", NULL); + // confirm that transactions are only occurring during active periods + int first_cycle = qr.GetVal("Time", 0); + EXPECT_EQ(0, first_cycle); + int second_cycle = qr.GetVal("Time", 2); + EXPECT_EQ(5, second_cycle); + int third_cycle = qr.GetVal("Time", 5); + EXPECT_EQ(11, third_cycle); + + // confirm total inbuf recieved material + EXPECT_DOUBLE_EQ(7, inbuf.quantity()); + + delete a; } }