Skip to content

Commit

Permalink
fix bad merge
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearkatie committed Jan 24, 2024
1 parent 89fc812 commit 810840c
Showing 1 changed file with 170 additions and 3 deletions.
173 changes: 170 additions & 3 deletions src/sink_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@ TEST_F(SinkTest, PositionInitialize2) {

}

TEST_F(SinkTest, RandomUniform) {
// A random number pulled from a uniform integer distribution can be
// implemented as the request size
TEST_F(SinkTest, RandomUniformSize) {
using cyclus::QueryResult;
using cyclus::Cond;

Expand All @@ -361,10 +363,13 @@ TEST_F(SinkTest, RandomUniform) {

QueryResult qr = sim.db().Query("Resources", NULL);
EXPECT_EQ(qr.rows.size(), 1);
// Given the PRNG with default seed, the resource should have mass 9.41273
EXPECT_NEAR(qr.GetVal<double>("Quantity"), 9.41273, 0.0001);
}

TEST_F(SinkTest, RandomNormal) {
// A random number pulled from a normal int distribution with default mean and
// stddev can be implemented as the request size
TEST_F(SinkTest, RandomNormalSize) {
using cyclus::QueryResult;
using cyclus::Cond;

Expand All @@ -383,10 +388,13 @@ TEST_F(SinkTest, RandomNormal) {

QueryResult qr = sim.db().Query("Resources", NULL);
EXPECT_EQ(qr.rows.size(), 1);
// Given the PRNG with default seed, the resource should have mass 9.60929
EXPECT_NEAR(qr.GetVal<double>("Quantity"), 9.60929, 0.0001);
}

TEST_F(SinkTest, RandomNormalWithMeanSttdev) {
// A random number pulled from a normal int distribution with user-defined mean
// and stddev can be implemented as the request size
TEST_F(SinkTest, RandomNormalSizeWithMeanSttdev) {
using cyclus::QueryResult;
using cyclus::Cond;

Expand All @@ -407,9 +415,168 @@ TEST_F(SinkTest, RandomNormalWithMeanSttdev) {

QueryResult qr = sim.db().Query("Resources", NULL);
EXPECT_EQ(qr.rows.size(), 1);
// Given the PRNG with default seed, the resource should have mass 1.52979
EXPECT_NEAR(qr.GetVal<double>("Quantity"), 1.52979, 0.0001);
}

// A random number pulled from a uniform integer distribution can be
// implemented as the buying frequency
TEST_F(SinkTest, RandomUniformFreq) {
using cyclus::QueryResult;
using cyclus::Cond;

std::string config =
" <in_commods>"
" <val>commods_1</val>"
" </in_commods>"
" <capacity>10</capacity>"
" <random_frequency_type>UniformInt</random_frequency_type> "
" <random_frequency_min>2</random_frequency_min> "
" <random_frequency_max>4</random_frequency_max> ";

int simdur = 3;
cyclus::MockSim sim(cyclus::AgentSpec
(":cycamore:Sink"), config, simdur);
sim.AddSource("commods_1").capacity(10).Finalize();
int id = sim.Run();

QueryResult qr = sim.db().Query("Transactions", NULL);
// only one transaction has occurred
EXPECT_EQ(qr.rows.size(), 1);
// Get the time from the first transaction in the database (0th entry)
int trans_time = qr.GetVal<int>("Time", 0);
// Given the PRNG with default seed , this time should be time step 2
EXPECT_EQ(trans_time, 2);
}

// A random number pulled from a normal int distribution with default mean and
// stddev can be implemented as the buying frequency
TEST_F(SinkTest, RandomNormalFreq) {
using cyclus::QueryResult;
using cyclus::Cond;

std::string config =
" <in_commods>"
" <val>commods_1</val>"
" </in_commods>"
" <capacity>10</capacity>"
" <random_frequency_type>NormalInt</random_frequency_type> ";

int simdur = 3;
cyclus::MockSim sim(cyclus::AgentSpec
(":cycamore:Sink"), config, simdur);
sim.AddSource("commods_1").capacity(10).Finalize();
int id = sim.Run();

QueryResult qr = sim.db().Query("Transactions", NULL);
// only one transaction has occurred
EXPECT_EQ(qr.rows.size(), 1);
// Get the time from the first transaction in the database (0th entry)
int trans_time = qr.GetVal<int>("Time", 0);
// Given the PRNG with default seed , this time should be time step 2
EXPECT_EQ(trans_time, 2);
}

// A random number pulled from a normal int distribution with user-defined mean
// and stddev can be implemented as the buying frequency
TEST_F(SinkTest, RandomNormalFreqWithMeanSttdev) {
using cyclus::QueryResult;
using cyclus::Cond;

std::string config =
" <in_commods>"
" <val>commods_1</val>"
" </in_commods>"
" <capacity>10</capacity>"
" <random_frequency_type>NormalInt</random_frequency_type> "
" <random_frequency_mean>2</random_frequency_mean> "
" <random_frequency_stddev>0.2</random_frequency_stddev> ";

int simdur = 3;
cyclus::MockSim sim(cyclus::AgentSpec
(":cycamore:Sink"), config, simdur);
sim.AddSource("commods_1").capacity(10).Finalize();
int id = sim.Run();

QueryResult qr = sim.db().Query("Transactions", NULL);
// only one transaction has occurred
EXPECT_EQ(qr.rows.size(), 1);
// Get the time from the first transaction in the database (0th entry)
int trans_time = qr.GetVal<int>("Time", 0);
// Given the PRNG with default seed, this time should be time step 2
EXPECT_EQ(trans_time, 2);
}

// Check that multiple buying cycles set by random number execute as expected
TEST_F(SinkTest, RandomNormalFreqMultipleCycles) {
using cyclus::QueryResult;
using cyclus::Cond;

std::string config =
" <in_commods>"
" <val>commods_1</val>"
" </in_commods>"
" <capacity>10</capacity>"
" <random_frequency_type>NormalInt</random_frequency_type> "
" <random_frequency_mean>4</random_frequency_mean> "
" <random_frequency_stddev>1</random_frequency_stddev> ";

int simdur = 12;
cyclus::MockSim sim(cyclus::AgentSpec
(":cycamore:Sink"), config, simdur);
sim.AddSource("commods_1").capacity(10).Finalize();
int id = sim.Run();

QueryResult qr = sim.db().Query("Transactions", NULL);
// three transaction should have occurred
EXPECT_EQ(3, qr.rows.size());
// check multiple cycles execute at the expected time
// Get the time from the first, second, and third transactions in the
// database (0th, 1st, and 2nd entry)
// Given the PRNG with default seed, buy times on time step 5, 7, and 10
int first_trans_time = qr.GetVal<int>("Time", 0);
EXPECT_EQ(5, first_trans_time);
int second_trans_time = qr.GetVal<int>("Time", 1);
EXPECT_EQ(7, second_trans_time);
int third_trans_time = qr.GetVal<int>("Time", 2);
EXPECT_EQ(11, third_trans_time);
}

// Check that randomness can be implemented in both size of request and
// request frequency at the same time
TEST_F(SinkTest, RandomNormalSizeUniformFreq) {
using cyclus::QueryResult;
using cyclus::Cond;

std::string config =
" <in_commods>"
" <val>commods_1</val>"
" </in_commods>"
" <capacity>10</capacity>"
" <random_size_type>NormalReal</random_size_type>"
" <random_size_mean>0.8</random_size_mean>"
" <random_size_stddev>0.2</random_size_stddev>"
" <random_frequency_type>UniformInt</random_frequency_type> "
" <random_frequency_min>2</random_frequency_min> "
" <random_frequency_max>4</random_frequency_max> ";

int simdur = 6;
cyclus::MockSim sim(cyclus::AgentSpec
(":cycamore:Sink"), config, simdur);
sim.AddSource("commods_1").capacity(20).Finalize();
int id = sim.Run();

QueryResult tqr = sim.db().Query("Transactions", NULL);
// two transactions should have occurred
EXPECT_EQ(2, tqr.rows.size());
// check multiple cycles execute at the expected time
int trans_time = tqr.GetVal<int>("Time", 0);
EXPECT_EQ(3, trans_time);
int res_id = tqr.GetVal<int>("ResourceId", 0);
QueryResult rqr = sim.db().Query("Resources", NULL);
double quantity = rqr.GetVal<double>("Quantity", 0);
EXPECT_NEAR(6.54143, quantity, 0.00001);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
cyclus::Agent* SinkConstructor(cyclus::Context* ctx) {
return new cycamore::Sink(ctx);
Expand Down

0 comments on commit 810840c

Please sign in to comment.