3#include <gtest/gtest.h>
8#include "resource_helpers.h"
9#include "test_context.h"
32 recipe = cyclus::Composition::CreateFromAtom(cyclus::CompMap());
43 cyclus::Context* ctx = tc.get();
45 (src_facility->Clone());
47 EXPECT_EQ(outcommod(src_facility), outcommod(cloned_fac));
48 EXPECT_EQ(throughput(src_facility), throughput(cloned_fac));
49 EXPECT_EQ(outrecipe(src_facility), outrecipe(cloned_fac));
55 EXPECT_NO_THROW(std::string s = src_facility->str());
58TEST_F(SourceTest, AddBids) {
60 using cyclus::BidPortfolio;
61 using cyclus::CapacityConstraint;
62 using cyclus::ExchangeContext;
63 using cyclus::Material;
67 boost::shared_ptr< ExchangeContext<Material> >
68 ec = GetContext(nreqs, commod);
70 src_facility->EnterNotify();
72 std::set<BidPortfolio<Material>::Ptr> ports =
73 src_facility->GetMatlBids(ec.get()->commod_requests);
75 ASSERT_TRUE(ports.size() > 0);
76 EXPECT_EQ(ports.size(), 1);
78 BidPortfolio<Material>::Ptr port = *ports.begin();
79 EXPECT_EQ(port->bidder(), src_facility);
80 EXPECT_EQ(port->bids().size(), nreqs);
82 const std::set< CapacityConstraint<Material> >& constrs = port->constraints();
83 ASSERT_TRUE(constrs.size() > 0);
84 EXPECT_EQ(constrs.size(), 1);
85 EXPECT_EQ(*constrs.begin(), CapacityConstraint<Material>(capacity));
88TEST_F(SourceTest, Response) {
90 using cyclus::Material;
91 using cyclus::Request;
93 using test_helpers::get_mat;
95 std::vector< Trade<Material> > trades;
96 std::vector<std::pair<Trade<Material>,
97 Material::Ptr> > responses;
100 EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses));
101 EXPECT_EQ(responses.size(), 0);
103 double qty = capacity / 3;
104 Request<Material>* request =
105 Request<Material>::Create(get_mat(), trader, commod);
107 Bid<Material>::Create(request, get_mat(), src_facility);
109 Trade<Material> trade(request, bid, qty);
110 trades.push_back(trade);
113 src_facility->GetMatlTrades(trades, responses);
114 EXPECT_EQ(responses.size(), 1);
115 EXPECT_EQ(responses[0].second->quantity(), qty);
116 EXPECT_EQ(responses[0].second->comp(), recipe);
119 trades.push_back(trade);
121 EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses));
122 EXPECT_EQ(responses.size(), 2);
125 src_facility->Tick();
131TEST_F(SourceTest, PositionInitialize) {
133 "<outcommod>spent_fuel</outcommod>"
136 cyclus::MockSim sim(cyclus::AgentSpec (
":cycamore:Source"), config, simdur);
139 cyclus::QueryResult qr = sim.db().Query(
"AgentPosition", NULL);
140 EXPECT_EQ(qr.GetVal<
double>(
"Latitude"), 0.0);
141 EXPECT_EQ(qr.GetVal<
double>(
"Longitude"), 0.0);
145TEST_F(SourceTest, Longitude) {
147 "<outcommod>spent_fuel</outcommod>"
148 "<latitude>-0.01</latitude>"
149 "<longitude>0.01</longitude>"
152 cyclus::MockSim sim(cyclus::AgentSpec (
":cycamore:Source"), config, simdur);
155 cyclus::QueryResult qr = sim.db().Query(
"AgentPosition", NULL);
156 EXPECT_EQ(qr.GetVal<
double>(
"Latitude"), -0.01);
157 EXPECT_EQ(qr.GetVal<
double>(
"Longitude"), 0.01);
161TEST_F(SourceTest, Package) {
162 using cyclus::QueryResult;
166 "<outcommod>commod</outcommod>"
167 "<outrecipe>recipe</outrecipe>"
168 "<package>testpackage</package>"
169 "<throughput>5</throughput>";
172 cyclus::MockSim sim(cyclus::AgentSpec (
":cycamore:Source"), config, simdur);
174 sim.context()->AddRecipe(recipe_name, recipe);
175 sim.context()->AddPackage(package_name, 3, 4,
"first");
176 package = sim.context()->GetPackage(package_name);
178 sim.AddSink(
"commod").Finalize();
180 EXPECT_NO_THROW(sim.Run());
182 QueryResult qr_tr = sim.db().Query(
"Transactions", NULL);
183 EXPECT_EQ(qr_tr.rows.size(), 3);
185 std::vector<Cond> conds;
186 conds.push_back(Cond(
"PackageName",
"==", package->name()));
187 QueryResult qr_res = sim.db().Query(
"Resources", &conds);
189 EXPECT_EQ(qr_res.rows.size(), 3);
192TEST_F(SourceTest, TransportUnit) {
193 using cyclus::QueryResult;
197 "<outcommod>commod</outcommod>"
198 "<outrecipe>recipe</outrecipe>"
199 "<package>testpackage</package>"
200 "<transport_unit>testtu</transport_unit>"
201 "<throughput>10</throughput>";
204 cyclus::MockSim sim(cyclus::AgentSpec (
":cycamore:Source"), config, simdur);
206 sim.context()->AddRecipe(recipe_name, recipe);
207 sim.context()->AddPackage(package_name, 3, 4,
"equal");
208 package = sim.context()->GetPackage(package_name);
209 sim.context()->AddTransportUnit(tu_name, 2, 2);
210 tu = sim.context()->GetTransportUnit(tu_name);
212 sim.AddSink(
"commod").Finalize();
214 EXPECT_NO_THROW(sim.Run());
216 QueryResult qr_tr = sim.db().Query(
"Transactions", NULL);
217 EXPECT_EQ(qr_tr.rows.size(), 4);
219 std::vector<Cond> conds;
220 conds.push_back(Cond(
"PackageName",
"==", package->name()));
221 QueryResult qr_res = sim.db().Query(
"Resources", &conds);
223 EXPECT_EQ(qr_res.rows.size(), 4);
225 QueryResult qr_allres = sim.db().Query(
"Resources", NULL);
228boost::shared_ptr< cyclus::ExchangeContext<cyclus::Material> >
230 using cyclus::Material;
231 using cyclus::Request;
232 using cyclus::ExchangeContext;
233 using test_helpers::get_mat;
236 boost::shared_ptr< ExchangeContext<Material> >
237 ec(
new ExchangeContext<Material>());
238 for (
int i = 0; i < nreqs; i++) {
239 ec->AddRequest(Request<Material>::Create(get_mat(),
trader,
commod));
251#ifndef CYCLUS_AGENT_TESTS_CONNECTED
254#define CYCLUS_AGENT_TESTS_CONNECTED cyclus_agent_tests_connected
static int cyclus_agent_tests_connected
INSTANTIATE_TEST_SUITE_P(DeployInst, InstitutionTests, Values(&DeployInstitutionConstructor))
cyclus::Agent * SourceConstructor(cyclus::Context *ctx)
std::string outrecipe(cycamore::Source *s)
cyclus::Composition::Ptr recipe
boost::shared_ptr< cyclus::ExchangeContext< cyclus::Material > > GetContext(int nreqs, std::string commodity)
std::string outcommod(cycamore::Source *s)
double throughput(cycamore::Source *s)
cycamore::Source * src_facility
This facility acts as a source of material with a fixed throughput (per time step) capacity and a lif...
virtual void Build(cyclus::Agent *parent)
— Facility Members — perform module-specific tasks when entering the simulation
TEST_F(EnrichmentTest, RequestQty)