Skip to content

Commit

Permalink
cannot assume order of packaged trades
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearkatie committed Jun 12, 2024
1 parent 718bcd7 commit 9885a35
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/storage_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -984,10 +984,22 @@ TEST_F(StorageTest, PackageSplitFirst) {
cyclus::QueryResult qr_res = sim.db().Query("Resources", &res_conds);
// because package does split-first, resources are size 2 and 1
EXPECT_EQ(qr_res.rows.size(), 4);
EXPECT_EQ(2, qr_res.GetVal<double>("Quantity", 0));
EXPECT_EQ(1, qr_res.GetVal<double>("Quantity", 1));
EXPECT_EQ(2, qr_res.GetVal<double>("Quantity", 2));
EXPECT_EQ(1, qr_res.GetVal<double>("Quantity", 3));

// order of trade execution is not guaranteed. Therefore, create vector,
// sort by size, and then check values
std::vector<double> pkgd_t0 = {qr_res.GetVal<double>("Quantity", 0),
qr_res.GetVal<double>("Quantity", 1)};
std::sort(pkgd_t0.begin(), pkgd_t0.end(), std::greater<double>());
std::vector<double> exp_t0 = {2, 1};

EXPECT_EQ(exp_t0, pkgd_t0);

std::vector<double> pkgd_t1 = {qr_res.GetVal<double>("Quantity", 2),
qr_res.GetVal<double>("Quantity", 3)};
std::sort(pkgd_t1.begin(), pkgd_t1.end(), std::greater<double>());
std::vector<double> exp_t1 = {2, 1};

EXPECT_EQ(exp_t1, pkgd_t1);
}

TEST_F(StorageTest, PackageMerge) {
Expand Down

0 comments on commit 9885a35

Please sign in to comment.