9 #include <fei_macros.hpp>
11 #include <test_utils/fei_test_utils.hpp>
13 #include <test_utils/test_misc.hpp>
15 #include <test_utils/test_Factory_helper.hpp>
17 #include <fei_FieldMask.hpp>
18 #include <snl_fei_RecordCollection.hpp>
20 #include <fei_VectorSpace.hpp>
21 #include <fei_Vector_Impl.hpp>
24 #define fei_file "test_misc.cpp"
25 #include <fei_ErrMacros.hpp>
27 test_misc::test_misc(MPI_Comm comm)
32 test_misc::~test_misc()
36 void test_misc_FieldMask()
38 FEI_COUT <<
"testing fei::FieldMask...";
42 unsigned numFields = 5;
43 std::vector<int> fieldIDs(numFields);
44 std::vector<int> fieldSizes(numFields);
45 int checkNumIndices = 0;
46 for(
unsigned i=0; i<numFields; ++i) {
54 for(
int i=fieldIDs.size()-1; i>= 0; --i) {
55 fieldMask.
addField(fieldIDs[i], fieldSizes[i]);
58 std::vector<int>& maskFields = fieldMask.
getFieldIDs();
61 if (maskFields != fieldIDs) {
62 throw std::runtime_error(
"FieldMask test failed.");
65 if (maskFieldSizes != fieldSizes) {
66 throw std::runtime_error(
"FieldMask size test failed.");
70 for(
unsigned j=0; j<fieldIDs.size(); ++j) {
73 if (offset != checkOffset) {
74 throw std::runtime_error(
"FieldMask offset test failed.");
80 if (numIndices != checkNumIndices) {
81 throw std::runtime_error(
"FieldMask numIndices test failed.");
84 bool exc_caught =
false;
93 throw std::runtime_error(
"FieldMask failed to throw on negative fieldID.");
99 throw std::runtime_error(
"FieldMask getNumFields test failed.");
112 fm12.addField(fieldid2, fieldsize);
115 fm123.addField(fieldid2, fieldsize);
116 fm123.addField(fieldid3, fieldsize);
118 if (fm1.getMaskID() == fm2.getMaskID()) {
119 throw std::runtime_error(
"FieldMask getMaskID test failed.");
122 if (fm2.getMaskID() == fm12.getMaskID()) {
123 throw std::runtime_error(
"FieldMask getMaskID2 test failed.");
126 if (fm12.getMaskID() !=
128 throw std::runtime_error(
"FieldMask getMaskID3 test failed.");
131 if (fm12.getMaskID() == fm3.getMaskID()) {
132 throw std::runtime_error(
"FieldMask getMaskID4 test failed.");
135 if (fm123.getMaskID() !=
137 throw std::runtime_error(
"FieldMask getMaskID5 test failed.");
140 if (fm3.getMaskID() == fm123.getMaskID()) {
141 throw std::runtime_error(
"FieldMask getMaskID6 test failed.");
144 FEI_COUT <<
"ok"<<FEI_ENDL;
147 void test_misc_RecordCollection()
149 FEI_COUT <<
"testing snl_fei::RecordCollection...";
158 std::vector<fei::FieldMask*> fieldMasks;
162 int* records =
new int[1];
164 recColl.initRecords(fieldID0, fieldSize, 1, &ID0,
165 fieldMasks, records);
167 recColl.initRecords(fieldID1, fieldSize, 1, &ID0,
168 fieldMasks, records);
170 recColl.initRecords(fieldID2, fieldSize, 1, &ID0,
171 fieldMasks, records);
173 recColl.initRecords(fieldID0, fieldSize, 1, &ID1,
174 fieldMasks, records);
176 recColl.initRecords(fieldID1, fieldSize, 1, &ID1,
177 fieldMasks, records);
179 recColl.initRecords(fieldID2, fieldSize, 1, &ID1,
180 fieldMasks, records);
182 if (fieldMasks.size() != 5) {
183 throw std::runtime_error(
"RecordCollection fieldMasks.length test failed.");
186 std::vector<fei::Record<int> >& rvec = recColl.getRecords();
188 std::vector<fei::Record<int> >::iterator
189 r_iter = rvec.begin(),
193 for(; r_iter != r_end; ++r_iter) {
194 numIndices += (*r_iter).getFieldMask()->getNumIndices();
197 if (numIndices != 6) {
198 throw std::runtime_error(
"RecordCollection numIndices test failed.");
202 for(
unsigned i=0; i<fieldMasks.size(); ++i)
delete fieldMasks[i];
204 FEI_COUT <<
"ok"<<FEI_ENDL;
207 int test_misc::runtests()
210 test_misc_FieldMask();
211 test_misc_RecordCollection();
213 CHK_ERR( serialtest1() );
214 CHK_ERR( serialtest2() );
215 CHK_ERR( serialtest3() );
225 int test_misc::serialtest1()
227 FEI_COUT <<
"testing fei_test_utils::within_percentage_margin...";
228 double value1 = 65000.0;
229 double value2 = 6500.0;
231 if (result ==
true) {
238 if (result !=
true) {
245 if (result ==
true) {
252 if (result !=
true) {
256 FEI_COUT <<
"ok"<<FEI_ENDL;
260 int test_misc::serialtest2()
262 FEI_COUT <<
"testing fei::lowerBound...";
263 std::vector<int> list(5);
272 int lowerbound = fei::lowerBound<int>(item, &list[0], list.size());
274 if (lowerbound != 0) {
275 throw std::runtime_error(
"failed test 1");
279 lowerbound = fei::lowerBound<int>(item, &list[0], list.size());
281 if (lowerbound != 0) {
282 throw std::runtime_error(
"failed test 2");
286 lowerbound = fei::lowerBound<int>(item, &list[0], list.size());
288 if (lowerbound != 1) {
289 throw std::runtime_error(
"failed test 3");
293 lowerbound = fei::lowerBound<int>(item, &list[0], list.size());
295 if (lowerbound != 3) {
296 throw std::runtime_error(
"failed test 4");
300 lowerbound = fei::lowerBound<int>(item, &list[0], list.size());
302 if (lowerbound != 4) {
303 throw std::runtime_error(
"failed test 5");
307 lowerbound = fei::lowerBound<int>(item, &list[0], list.size());
309 if (lowerbound != 4) {
310 throw std::runtime_error(
"failed test6");
314 lowerbound = fei::lowerBound<int>(item, &list[0], list.size());
316 if (lowerbound != 5) {
317 throw std::runtime_error(
"failed test 7");
320 lowerbound = fei::lowerBound<int>(item, (
int*)0, (
int)0);
322 if (lowerbound != 0) {
323 throw std::runtime_error(
"failed test 8");
326 std::vector<int> list2;
330 lowerbound = fei::lowerBound<int>(item, &list2[0], list2.size());
332 if (lowerbound != 0) {
333 throw std::runtime_error(
"failed test 9");
337 lowerbound = fei::lowerBound<int>(item, &list2[0], list2.size());
339 if (lowerbound != 1) {
340 throw std::runtime_error(
"failed test 10");
343 FEI_COUT <<
"ok"<<FEI_ENDL;
348 int test_misc::serialtest3()
350 FEI_COUT <<
"testing snl_fei::MapContig<fei::ctg_set<int>*>...";
357 for(
int i=1; i<6; ++i) {
359 pool_alloc.construct(newset,dummy);
362 for(
int j=0; j<3; ++j) {
366 std::pair<int,fei::ctg_set<int>*> newpair(i,newset);
372 if (m_copy.size() != mc.size()) {
373 throw std::runtime_error(
"failed test 1.");
377 mc_iter = mc.
begin(),
381 c_iter = m_copy.
begin(),
382 c_end = m_copy.end();
384 for(; mc_iter != mc_end; ++mc_iter) {
385 std::pair<int,fei::ctg_set<int>*> mc_pair = *mc_iter;
386 std::pair<int,fei::ctg_set<int>*> c_pair = *c_iter;
388 if (mc_pair.first != c_pair.first) {
389 throw std::runtime_error(
"failed test 2.");
392 if (*(mc_pair.second) != *(c_pair.second)) {
393 throw std::runtime_error(
"failed test 3.");
398 mc_iter = mc.
begin();
399 for(; mc_iter != mc_end; ++mc_iter) {
400 pool_alloc.destroy((*mc_iter).second);
403 FEI_COUT <<
"ok" << FEI_ENDL;
408 int test_misc::test1()
414 int test_misc::test2()
420 int test_misc::test3()
426 int test_misc::test4()
int getNumIndices() const
size_t getNumFields() const
static int calculateMaskID(int numFields, const int *fieldIDs)
std::vector< int > & getFieldSizes()
void insert2(const T &item)
std::vector< int > & getFieldIDs()
void addField(int fieldID, int fieldSize)
bool within_percentage_margin(double value1, double value2, unsigned margin)
int getFieldEqnOffset(int fieldID, int &offset) const