Skip to content

Commit

Permalink
fix and extend tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gonuke committed Mar 14, 2024
1 parent 4afa042 commit cea8e94
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 22 deletions.
65 changes: 54 additions & 11 deletions tests/toolkit/res_buf_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,18 @@ TEST_F(ProductBufTest, PushAll_DuplicateEmpty) {

TEST_F(MaterialBufTest, NonBulkTest) {

ASSERT_EQ(mat_store_.count(), 0);
EXPECT_DOUBLE_EQ(mat_store_.capacity(), cap_);

mat_store_.Push(mat1a_);
mat_store_.Push(mat2a_);

ASSERT_EQ(mat_store_.count(), 2);
ASSERT_EQ(mat_store_.capacity(), cap_);
double qty_exp = 2 * mat1_->quantity();
EXPECT_DOUBLE_EQ(mat_store_.capacity(), cap_);
double qty_exp = mat1a_->quantity() + mat2a_->quantity();
double space_exp = cap_ - qty_exp;
ASSERT_EQ(mat_store_.space(), space_exp);
ASSERT_EQ(mat_store_.quantity(), qty_exp);
EXPECT_DOUBLE_EQ(mat_store_.space(), space_exp);
EXPECT_DOUBLE_EQ(mat_store_.quantity(), qty_exp);

Material::Ptr pop1_ = mat_store_.Pop();
ASSERT_EQ(pop1_->comp(), test_comp1_);
Expand All @@ -378,21 +384,58 @@ TEST_F(MaterialBufTest, NonBulkTest) {

TEST_F(MaterialBufTest, BulkTest) {

ASSERT_EQ(bulk_store_.count(), 0);
EXPECT_DOUBLE_EQ(bulk_store_.capacity(), cap_);

bulk_store_.Push(mat1b_);
bulk_store_.Push(mat2b_);

ASSERT_EQ(bulk_store_.count(), 1);
ASSERT_EQ(bulk_store_.capacity(), cap_);
double qty_exp = 2 * mat1_->quantity();
EXPECT_DOUBLE_EQ(bulk_store_.capacity(), cap_);
double qty_exp = mat1b_->quantity() + mat2b_->quantity();
double space_exp = cap_ - qty_exp;
ASSERT_EQ(bulk_store_.space(), space_exp);
ASSERT_EQ(bulk_store_.quantity(), qty_exp);
EXPECT_DOUBLE_EQ(bulk_store_.space(), space_exp);
EXPECT_DOUBLE_EQ(bulk_store_.quantity(), qty_exp);

Material::Ptr pop1_ = mat_store_.Pop();
Material::Ptr pop1_ = bulk_store_.Pop();
cyclus::toolkit::MatQuery mq1(pop1_);
double sr89_qty = mq1.mass(sr89_);
double fe59_qty = mq1.mass(fe59_);

ASSERT_EQ(sr89_qty, 5.0 * units::g);
ASSERT_EQ(fe59_qty, 5.0 * units::g);
double sr89_qty_exp = 5.0 * units::g;
double fe59_qty_exp = 5.0 * units::g;

EXPECT_DOUBLE_EQ(sr89_qty_exp, sr89_qty);
EXPECT_DOUBLE_EQ(fe59_qty_exp, fe59_qty);

ASSERT_EQ(bulk_store_.count(), 0);
EXPECT_DOUBLE_EQ(bulk_store_.capacity(), cap_);
EXPECT_DOUBLE_EQ(bulk_store_.space(), cap_);
EXPECT_DOUBLE_EQ(bulk_store_.quantity(), 0);

EXPECT_DOUBLE_EQ(pop1_->quantity(), qty_exp);

bulk_store_.Push(pop1_);
// need to capture this now because mat3_ is about to disappear
qty_exp += mat3_->quantity();
space_exp -= mat3_->quantity();
sr89_qty_exp += mat3_->quantity()/3;
fe59_qty_exp += mat3_->quantity()*2/3;

bulk_store_.Push(mat3_);

ASSERT_EQ(bulk_store_.count(), 1);
EXPECT_DOUBLE_EQ(bulk_store_.capacity(), cap_);
EXPECT_DOUBLE_EQ(qty_exp, bulk_store_.quantity());
EXPECT_DOUBLE_EQ(space_exp, bulk_store_.space());

pop1_ = bulk_store_.Pop();

sr89_qty = mq1.mass(sr89_);
fe59_qty = mq1.mass(fe59_);

EXPECT_DOUBLE_EQ(sr89_qty_exp, sr89_qty);
EXPECT_DOUBLE_EQ(fe59_qty_exp, fe59_qty);

}

Expand Down
20 changes: 9 additions & 11 deletions tests/toolkit/res_buf_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class MaterialBufTest : public ::testing::Test {
ResBuf<Material> bulk_store_ = ResBuf<Material>(true);

Nuc sr89_, fe59_;
Material::Ptr mat1_, mat2_, mat3_;
Material::Ptr mat1a_, mat1b_, mat2a_, mat2b_, mat3_;
Composition::Ptr test_comp1_, test_comp2_, test_comp3_;

double cap_;
Expand All @@ -93,21 +93,19 @@ class MaterialBufTest : public ::testing::Test {
w[sr89_] = 1;
test_comp3_ = Composition::CreateFromMass(w);

mat1_ = Material::CreateUntracked(5 * units::g, test_comp1_);
mat2_ = Material::CreateUntracked(5 * units::g, test_comp2_);
mat3_ = Material::CreateUntracked(5 * units::g, test_comp1_);
double mat_size = 5 * units::g;

cap_ = 10 * mat1_->quantity();
mat1a_ = Material::CreateUntracked(mat_size, test_comp1_);
mat1b_ = Material::CreateUntracked(mat_size, test_comp1_);
mat2a_ = Material::CreateUntracked(mat_size, test_comp2_);
mat2b_ = Material::CreateUntracked(mat_size, test_comp2_);
mat3_ = Material::CreateUntracked(mat_size, test_comp3_);

cap_ = 10 * mat_size;

mat_store_.capacity(cap_);
bulk_store_.capacity(cap_);

mat_store_.Push(mat1_);
mat_store_.Push(mat2_);

bulk_store_.Push(mat3_);
bulk_store_.Push(mat2_);

} catch (std::exception err) {
FAIL() << "An exception was thrown in the fixture SetUp.";
}
Expand Down

0 comments on commit cea8e94

Please sign in to comment.