Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 35df00e

Browse files
committedMar 10, 2024·
some first tests
1 parent f2d6723 commit 35df00e

File tree

2 files changed

+96
-32
lines changed

2 files changed

+96
-32
lines changed
 

‎tests/toolkit/res_buf_tests.cc

+46-31
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ namespace toolkit {
1212
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1313
// - - - - - - Getters, Setters, and Property changers - - - - - - - - - - - -
1414
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
15-
TEST_F(ResBufTest, set_capacity_ExceptionsEmpty) {
15+
TEST_F(ProductBufTest, set_capacity_ExceptionsEmpty) {
1616
EXPECT_THROW(store_.capacity(neg_cap), ValueError);
1717
EXPECT_NO_THROW(store_.capacity(zero_cap));
1818
EXPECT_NO_THROW(store_.capacity(cap));
1919
}
2020

2121
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
22-
TEST_F(ResBufTest, set_capacity_ExceptionsFilled) {
22+
TEST_F(ProductBufTest, set_capacity_ExceptionsFilled) {
2323
EXPECT_THROW(filled_store_.capacity(low_cap), ValueError);
2424
EXPECT_NO_THROW(filled_store_.capacity(cap));
2525
}
2626

2727
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
28-
TEST_F(ResBufTest, GetCapacity_ExceptionsEmpty) {
28+
TEST_F(ProductBufTest, GetCapacity_ExceptionsEmpty) {
2929
ASSERT_NO_THROW(store_.capacity());
3030
store_.capacity(zero_cap);
3131
ASSERT_NO_THROW(store_.capacity());
@@ -34,12 +34,12 @@ TEST_F(ResBufTest, GetCapacity_ExceptionsEmpty) {
3434
}
3535

3636
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
37-
TEST_F(ResBufTest, GetCapacity_InitialEmpty) {
37+
TEST_F(ProductBufTest, GetCapacity_InitialEmpty) {
3838
EXPECT_DOUBLE_EQ(store_.capacity(), INFINITY);
3939
}
4040

4141
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
42-
TEST_F(ResBufTest, Getset_capacityEmpty) {
42+
TEST_F(ProductBufTest, Getset_capacityEmpty) {
4343
store_.capacity(zero_cap);
4444
EXPECT_DOUBLE_EQ(store_.capacity(), zero_cap);
4545

@@ -48,7 +48,7 @@ TEST_F(ResBufTest, Getset_capacityEmpty) {
4848
}
4949

5050
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
51-
TEST_F(ResBufTest, GetSpace_Empty) {
51+
TEST_F(ProductBufTest, GetSpace_Empty) {
5252
ASSERT_NO_THROW(store_.space());
5353
EXPECT_DOUBLE_EQ(store_.space(), INFINITY);
5454

@@ -62,55 +62,55 @@ TEST_F(ResBufTest, GetSpace_Empty) {
6262
}
6363

6464
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
65-
TEST_F(ResBufTest, GetSpace_Filled) {
65+
TEST_F(ProductBufTest, GetSpace_Filled) {
6666
double space = cap - (mat1_->quantity() + mat2_->quantity());
6767
ASSERT_NO_THROW(filled_store_.space());
6868
EXPECT_DOUBLE_EQ(filled_store_.space(), space);
6969
}
7070

7171
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
72-
TEST_F(ResBufTest, GetQuantity_Empty) {
72+
TEST_F(ProductBufTest, GetQuantity_Empty) {
7373
ASSERT_NO_THROW(store_.quantity());
7474
EXPECT_DOUBLE_EQ(store_.quantity(), 0.0);
7575
}
7676

7777
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
78-
TEST_F(ResBufTest, GetQuantity_Filled) {
78+
TEST_F(ProductBufTest, GetQuantity_Filled) {
7979
ASSERT_NO_THROW(filled_store_.quantity());
8080
double quantity = mat1_->quantity() + mat2_->quantity();
8181
EXPECT_DOUBLE_EQ(filled_store_.quantity(), quantity);
8282
}
8383

8484
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
85-
TEST_F(ResBufTest, GetCount_Empty) {
85+
TEST_F(ProductBufTest, GetCount_Empty) {
8686
ASSERT_NO_THROW(store_.count());
8787
EXPECT_EQ(store_.count(), 0);
8888
}
8989

9090
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
91-
TEST_F(ResBufTest, GetCount_Filled) {
91+
TEST_F(ProductBufTest, GetCount_Filled) {
9292
ASSERT_NO_THROW(filled_store_.count());
9393
EXPECT_DOUBLE_EQ(filled_store_.count(), 2);
9494
}
9595

9696
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
9797
// - - - - - Removing from buffer - - - - - - - - - - - - - - - - - - - - - -
9898
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
99-
TEST_F(ResBufTest, RemoveQty_ExceptionsEmpty) {
99+
TEST_F(ProductBufTest, RemoveQty_ExceptionsEmpty) {
100100
Product::Ptr p;
101101
double qty = cap + overeps;
102102
ASSERT_THROW(p = filled_store_.Pop(qty), ValueError);
103103
}
104104

105105
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
106-
TEST_F(ResBufTest, RemoveQty_ExceptionsFilled) {
106+
TEST_F(ProductBufTest, RemoveQty_ExceptionsFilled) {
107107
Product::Ptr p;
108108
double qty = cap + overeps;
109109
ASSERT_THROW(p = store_.Pop(qty), ValueError);
110110
}
111111

112112
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
113-
TEST_F(ResBufTest, RemoveQty_SingleNoSplit) {
113+
TEST_F(ProductBufTest, RemoveQty_SingleNoSplit) {
114114
// pop one no splitting leaving one mat in the store
115115
Product::Ptr p;
116116

@@ -121,7 +121,7 @@ TEST_F(ResBufTest, RemoveQty_SingleNoSplit) {
121121
}
122122

123123
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
124-
TEST_F(ResBufTest, RemoveQty_SingleWithSplit) {
124+
TEST_F(ProductBufTest, RemoveQty_SingleWithSplit) {
125125
// pop one no splitting leaving one mat in the store
126126

127127
Product::Ptr p;
@@ -134,7 +134,7 @@ TEST_F(ResBufTest, RemoveQty_SingleWithSplit) {
134134
}
135135

136136
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
137-
TEST_F(ResBufTest, RemoveQty_DoubleWithSplit) {
137+
TEST_F(ProductBufTest, RemoveQty_DoubleWithSplit) {
138138
// pop one no splitting leaving one mat in the store
139139

140140
Product::Ptr p;
@@ -147,14 +147,14 @@ TEST_F(ResBufTest, RemoveQty_DoubleWithSplit) {
147147
}
148148

149149
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
150-
TEST_F(ResBufTest, RemoveNum_ExceptionsFilled) {
150+
TEST_F(ProductBufTest, RemoveNum_ExceptionsFilled) {
151151
ProdVec manifest;
152152
ASSERT_THROW(manifest = filled_store_.PopN(3), ValueError);
153153
ASSERT_THROW(manifest = filled_store_.PopN(-1), ValueError);
154154
}
155155

156156
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
157-
TEST_F(ResBufTest, RemoveNum_ZeroFilled) {
157+
TEST_F(ProductBufTest, RemoveNum_ZeroFilled) {
158158
ProdVec manifest;
159159
double tot_qty = filled_store_.quantity();
160160

@@ -165,7 +165,7 @@ TEST_F(ResBufTest, RemoveNum_ZeroFilled) {
165165
}
166166

167167
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
168-
TEST_F(ResBufTest, RemoveNum_OneFilled) {
168+
TEST_F(ProductBufTest, RemoveNum_OneFilled) {
169169
ProdVec manifest;
170170

171171
ASSERT_NO_THROW(manifest = filled_store_.PopN(1));
@@ -177,7 +177,7 @@ TEST_F(ResBufTest, RemoveNum_OneFilled) {
177177
}
178178

179179
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
180-
TEST_F(ResBufTest, RemoveNum_TwoFilled) {
180+
TEST_F(ProductBufTest, RemoveNum_TwoFilled) {
181181
ProdVec manifest;
182182

183183
ASSERT_NO_THROW(manifest = filled_store_.PopN(2));
@@ -191,7 +191,7 @@ TEST_F(ResBufTest, RemoveNum_TwoFilled) {
191191
}
192192

193193
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
194-
TEST_F(ResBufTest, RemoveOne_Filled) {
194+
TEST_F(ProductBufTest, RemoveOne_Filled) {
195195
Product::Ptr mat;
196196

197197
ASSERT_NO_THROW(mat = filled_store_.Pop());
@@ -210,7 +210,7 @@ TEST_F(ResBufTest, RemoveOne_Filled) {
210210
}
211211

212212
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
213-
TEST_F(ResBufTest, PopBack) {
213+
TEST_F(ProductBufTest, PopBack) {
214214
Product::Ptr mat;
215215

216216
ASSERT_NO_THROW(mat = filled_store_.PopBack());
@@ -231,7 +231,7 @@ TEST_F(ResBufTest, PopBack) {
231231
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
232232
// - - - - - Pushing into buffer - - - - - - - - - - - - - - - - - - - - - - -
233233
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
234-
TEST_F(ResBufTest, Push_Empty) {
234+
TEST_F(ProductBufTest, Push_Empty) {
235235
ASSERT_NO_THROW(store_.capacity(cap));
236236

237237
ASSERT_NO_THROW(store_.Push(mat1_));
@@ -244,7 +244,7 @@ TEST_F(ResBufTest, Push_Empty) {
244244
}
245245

246246
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
247-
TEST_F(ResBufTest, Push_OverCapacityEmpty) {
247+
TEST_F(ProductBufTest, Push_OverCapacityEmpty) {
248248
ASSERT_NO_THROW(store_.capacity(cap));
249249

250250
ASSERT_NO_THROW(store_.Push(mat1_));
@@ -266,7 +266,7 @@ TEST_F(ResBufTest, Push_OverCapacityEmpty) {
266266
}
267267

268268
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
269-
TEST_F(ResBufTest, Push_DuplicateEmpty) {
269+
TEST_F(ProductBufTest, Push_DuplicateEmpty) {
270270
ASSERT_NO_THROW(store_.capacity(cap));
271271

272272
ASSERT_NO_THROW(store_.Push(mat1_));
@@ -277,15 +277,15 @@ TEST_F(ResBufTest, Push_DuplicateEmpty) {
277277
}
278278

279279
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
280-
TEST_F(ResBufTest, PushAll_Empty) {
280+
TEST_F(ProductBufTest, PushAll_Empty) {
281281
ASSERT_NO_THROW(store_.capacity(cap));
282282
ASSERT_NO_THROW(store_.Push(mats));
283283
ASSERT_EQ(store_.count(), 2);
284284
EXPECT_DOUBLE_EQ(store_.quantity(), mat1_->quantity() + mat2_->quantity());
285285
}
286286

287287
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
288-
TEST_F(ResBufTest, PushAll_ResCast) {
288+
TEST_F(ProductBufTest, PushAll_ResCast) {
289289
ResVec rs;
290290
for (int i = 0; i < mats.size(); ++i) {
291291
rs.push_back(mats[i]);
@@ -297,7 +297,7 @@ TEST_F(ResBufTest, PushAll_ResCast) {
297297
}
298298

299299
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
300-
TEST_F(ResBufTest, PushAll_NoneEmpty) {
300+
TEST_F(ProductBufTest, PushAll_NoneEmpty) {
301301
ProdVec manifest;
302302
ASSERT_NO_THROW(store_.capacity(cap));
303303
ASSERT_NO_THROW(store_.Push(manifest));
@@ -306,7 +306,7 @@ TEST_F(ResBufTest, PushAll_NoneEmpty) {
306306
}
307307

308308
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
309-
TEST_F(ResBufTest, PushAll_RetrieveOrderEmpty) {
309+
TEST_F(ProductBufTest, PushAll_RetrieveOrderEmpty) {
310310
Product::Ptr mat;
311311

312312
ASSERT_NO_THROW(store_.capacity(cap));
@@ -318,7 +318,7 @@ TEST_F(ResBufTest, PushAll_RetrieveOrderEmpty) {
318318
}
319319

320320
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
321-
TEST_F(ResBufTest, PushAll_OverCapacityEmpty) {
321+
TEST_F(ProductBufTest, PushAll_OverCapacityEmpty) {
322322
ASSERT_NO_THROW(store_.capacity(cap));
323323
ASSERT_NO_THROW(store_.Push(mats));
324324

@@ -343,7 +343,7 @@ TEST_F(ResBufTest, PushAll_OverCapacityEmpty) {
343343
}
344344

345345
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
346-
TEST_F(ResBufTest, PushAll_DuplicateEmpty) {
346+
TEST_F(ProductBufTest, PushAll_DuplicateEmpty) {
347347
ASSERT_NO_THROW(store_.capacity(2 * cap));
348348

349349
ASSERT_NO_THROW(store_.Push(mats));
@@ -355,5 +355,20 @@ TEST_F(ResBufTest, PushAll_DuplicateEmpty) {
355355
EXPECT_DOUBLE_EQ(store_.quantity(), mat1_->quantity() + mat2_->quantity());
356356
}
357357

358+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
359+
// Special tests for material buffers
360+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
361+
362+
TEST_F(MaterialBufTest, NonBulkTest) {
363+
364+
ASSERT_EQ(mat_store_.count(), 2);
365+
ASSERT_EQ(mat_store_.capacity(), cap_);
366+
double qty_exp = 2 * mat1_->quantity();
367+
double space_exp = cap_ - qty_exp;
368+
ASSERT_EQ(mat_store_.space(), space_exp);
369+
ASSERT_EQ(mat_store_.quantity(), qty_exp);
370+
371+
}
372+
358373
} // namespace toolkit
359374
} // namespace cyclus

‎tests/toolkit/res_buf_tests.h

+50-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
#include "error.h"
88
#include "logger.h"
99
#include "product.h"
10+
#include "composition.h"
11+
#include "material.h"
1012
#include "toolkit/res_buf.h"
1113

1214
namespace cyclus {
1315
namespace toolkit {
1416

1517
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
16-
class ResBufTest : public ::testing::Test {
18+
class ProductBufTest : public ::testing::Test {
1719
protected:
1820
Product::Ptr mat1_, mat2_;
1921
double mass1, mass2;
@@ -63,6 +65,53 @@ class ResBufTest : public ::testing::Test {
6365
}
6466
};
6567

68+
class MaterialBufTest : public ::testing::Test {
69+
protected:
70+
71+
ResBuf<Material> mat_store_; // default constructed mat store
72+
ResBuf<Material> bulk_store_ = ResBuf<Material>(true);
73+
74+
Nuc sr89_, fe59_;
75+
Material::Ptr mat1_, mat2_, mat3_;
76+
Composition::Ptr test_comp1_, test_comp2_;
77+
78+
double cap_;
79+
80+
virtual void SetUp() {
81+
try {
82+
83+
sr89_ = 380890000;
84+
fe59_ = 260590000;
85+
86+
CompMap v, w;
87+
v[sr89_] = 1;
88+
test_comp1_ = Composition::CreateFromMass(v);
89+
90+
w[fe59_] = 2;
91+
test_comp2_ = Composition::CreateFromMass(w);
92+
93+
mat1_ = Material::CreateUntracked(5 * units::g, test_comp1_);
94+
mat2_ = Material::CreateUntracked(5 * units::g, test_comp2_);
95+
mat3_ = Material::CreateUntracked(5 * units::g, test_comp1_);
96+
97+
cap_ = 10 * mat1_->quantity();
98+
99+
mat_store_.capacity(cap_);
100+
bulk_store_.capacity(cap_);
101+
102+
mat_store_.Push(mat1_);
103+
mat_store_.Push(mat2_);
104+
105+
bulk_store_.Push(mat3_);
106+
bulk_store_.Push(mat2_);
107+
108+
} catch (std::exception err) {
109+
FAIL() << "An exception was thrown in the fixture SetUp.";
110+
}
111+
}
112+
};
113+
114+
66115
} // namespace toolkit
67116
} // namespace cyclus
68117

0 commit comments

Comments
 (0)
Please sign in to comment.