CYCAMORE
src/source_tests.cc
Go to the documentation of this file.
1 #include "source_tests.h"
2 
3 #include <gtest/gtest.h>
4 
5 #include <sstream>
6 
7 #include "cyc_limits.h"
8 #include "resource_helpers.h"
9 #include "test_context.h"
10 
11 namespace cycamore {
12 
13 void SourceTest::SetUp() {
14  src_facility = new cycamore::Source(tc.get());
15  trader = tc.trader();
17  SetUpSource();
18 }
19 
20 void SourceTest::TearDown() {
21  delete src_facility;
22 }
23 
25  commod = "commod";
26  recipe_name = "recipe";
27  capacity = 5; // some magic number..
28 
29  recipe = cyclus::Composition::CreateFromAtom(cyclus::CompMap());
30  tc.get()->AddRecipe(recipe_name, recipe);
31 }
32 
37 }
38 
39 TEST_F(SourceTest, Clone) {
40  cyclus::Context* ctx = tc.get();
41  cycamore::Source* cloned_fac = dynamic_cast<cycamore::Source*>
42  (src_facility->Clone());
43 
44  EXPECT_EQ(outcommod(src_facility), outcommod(cloned_fac));
45  EXPECT_EQ(throughput(src_facility), throughput(cloned_fac));
46  EXPECT_EQ(outrecipe(src_facility), outrecipe(cloned_fac));
47 
48  delete cloned_fac;
49 }
50 
51 TEST_F(SourceTest, Print) {
52  EXPECT_NO_THROW(std::string s = src_facility->str());
53 }
54 
55 TEST_F(SourceTest, AddBids) {
56  using cyclus::Bid;
57  using cyclus::BidPortfolio;
58  using cyclus::CapacityConstraint;
59  using cyclus::ExchangeContext;
60  using cyclus::Material;
61 
62  int nreqs = 5;
63 
64  boost::shared_ptr< cyclus::ExchangeContext<Material> >
65  ec = GetContext(nreqs, commod);
66 
67  std::set<BidPortfolio<Material>::Ptr> ports =
68  src_facility->GetMatlBids(ec.get()->commod_requests);
69 
70  ASSERT_TRUE(ports.size() > 0);
71  EXPECT_EQ(ports.size(), 1);
72 
73  BidPortfolio<Material>::Ptr port = *ports.begin();
74  EXPECT_EQ(port->bidder(), src_facility);
75  EXPECT_EQ(port->bids().size(), nreqs);
76 
77  const std::set< CapacityConstraint<Material> >& constrs = port->constraints();
78  ASSERT_TRUE(constrs.size() > 0);
79  EXPECT_EQ(constrs.size(), 1);
80  EXPECT_EQ(*constrs.begin(), CapacityConstraint<Material>(capacity));
81 }
82 
83 TEST_F(SourceTest, Response) {
84  using cyclus::Bid;
85  using cyclus::Material;
86  using cyclus::Request;
87  using cyclus::Trade;
88  using test_helpers::get_mat;
89 
90  std::vector< cyclus::Trade<cyclus::Material> > trades;
91  std::vector<std::pair<cyclus::Trade<cyclus::Material>,
92  cyclus::Material::Ptr> > responses;
93 
94  // Null response
95  EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses));
96  EXPECT_EQ(responses.size(), 0);
97 
98  double qty = capacity / 3;
99  Request<Material>* request =
100  Request<Material>::Create(get_mat(), trader, commod);
101  Bid<Material>* bid =
102  Bid<Material>::Create(request, get_mat(), src_facility);
103 
104  Trade<Material> trade(request, bid, qty);
105  trades.push_back(trade);
106 
107  // 1 trade
108  src_facility->GetMatlTrades(trades, responses);
109  EXPECT_EQ(responses.size(), 1);
110  EXPECT_EQ(responses[0].second->quantity(), qty);
111  EXPECT_EQ(responses[0].second->comp(), recipe);
112 
113  // 2 trades, total qty = capacity
114  trades.push_back(trade);
115  responses.clear();
116  EXPECT_NO_THROW(src_facility->GetMatlTrades(trades, responses));
117  EXPECT_EQ(responses.size(), 2);
118 
119  // reset!
120  src_facility->Tick();
121 
122  delete request;
123  delete bid;
124 }
125 
126 boost::shared_ptr< cyclus::ExchangeContext<cyclus::Material> >
128  using cyclus::Material;
129  using cyclus::Request;
130  using cyclus::ExchangeContext;
131  using test_helpers::get_mat;
132 
133  double qty = 3;
134  boost::shared_ptr< ExchangeContext<Material> >
135  ec(new ExchangeContext<Material>());
136  for (int i = 0; i < nreqs; i++) {
137  ec->AddRequest(Request<Material>::Create(get_mat(), trader, commod));
138  }
139  return ec;
140 }
141 
142 } // namespace cycamore
143 
144 cyclus::Agent* SourceConstructor(cyclus::Context* ctx) {
145  return new cycamore::Source(ctx);
146 }
147 
148 // required to get functionality in cyclus agent unit tests library
149 #ifndef CYCLUS_AGENT_TESTS_CONNECTED
150 int ConnectAgentTests();
152 #define CYCLUS_AGENT_TESTS_CONNECTED cyclus_agent_tests_connected
153 #endif // CYCLUS_AGENT_TESTS_CONNECTED
154 
155 INSTANTIATE_TEST_CASE_P(SourceFac, FacilityTests, Values(&SourceConstructor));
156 INSTANTIATE_TEST_CASE_P(SourceFac, AgentTests, Values(&SourceConstructor));
157 
This facility acts as a source of material with a fixed throughput (per time step) capacity and a lif...
double throughput(cycamore::Source *s)
std::string outrecipe(cycamore::Source *s)
virtual std::set< cyclus::BidPortfolio< cyclus::Material >::Ptr > GetMatlBids(cyclus::CommodMap< cyclus::Material >::type &commod_requests)
static int cyclus_agent_tests_connected
cycamore::GrowthRegion string
std::string outcommod(cycamore::Source *s)
virtual std::string str()
cyclus::Agent * SourceConstructor(cyclus::Context *ctx)
virtual cyclus::Agent * Clone()
boost::shared_ptr< cyclus::ExchangeContext< cyclus::Material > > GetContext(int nreqs, std::string commodity)
INSTANTIATE_TEST_CASE_P(SourceFac, FacilityTests, Values(&SourceConstructor))
int ConnectAgentTests()
virtual void GetMatlTrades(const std::vector< cyclus::Trade< cyclus::Material > > &trades, std::vector< std::pair< cyclus::Trade< cyclus::Material >, cyclus::Material::Ptr > > &responses)
TEST_F(EnrichmentTest, RequestQty)