9 #include <fei_macros.hpp>
12 #include <test_utils/test_Set.hpp>
14 #include <snl_fei_Utils.hpp>
15 #include <fei_ctg_set.hpp>
18 #define fei_file "test_Set.cpp"
19 #include <fei_ErrMacros.hpp>
21 test_Set::test_Set(MPI_Comm comm)
30 template<
typename SET_TYPE>
31 void set_test1(SET_TYPE& set_obj)
33 if (set_obj.size() < 1) {
34 typename SET_TYPE::const_iterator
35 s_beg = set_obj.begin(),
36 s_end = set_obj.end();
39 throw std::runtime_error(
"failed test 1");
44 std::pair<typename SET_TYPE::const_iterator,bool> result = set_obj.insert(5);
47 throw std::runtime_error(
"failed test 2");
50 result = set_obj.insert(4);
53 throw std::runtime_error(
"failed test 3");
56 result = set_obj.insert(7);
59 if (result.first != set_obj.end()) {
60 throw std::runtime_error(
"failed test 4");
63 result = set_obj.insert(6);
66 throw std::runtime_error(
"failed test 5");
71 if (*(result.first) != 7) {
72 throw std::runtime_error(
"failed test 6");
76 if (result.first != set_obj.end()) {
77 throw std::runtime_error(
"failed test 7");
80 result = set_obj.insert(2);
81 result = set_obj.insert(3);
84 if (*(result.first) != 4) {
85 throw std::runtime_error(
"failed test 8");
88 SET_TYPE set_copy(set_obj);
90 if (set_copy.size() != set_obj.size()) {
91 throw std::runtime_error(
"failed test 9");
94 typename SET_TYPE::const_iterator
95 s_iter = set_obj.begin(),
96 s_end = set_obj.end();
98 typename SET_TYPE::const_iterator
99 c_iter = set_copy.begin(),
100 c_end = set_copy.end();
102 for(; s_iter != s_end; ++s_iter) {
103 if (*s_iter != *c_iter) {
104 throw std::runtime_error(
"failed test 10");
109 if (c_iter != c_end) {
110 throw std::runtime_error(
"failed test 11");
114 template<
typename SET_TYPE>
115 void set_test2(SET_TYPE& set_obj)
117 if (set_obj.size() < 1) {
118 typename SET_TYPE::const_iterator
119 s_beg = set_obj.begin(),
120 s_end = set_obj.end();
122 if (s_beg != s_end) {
123 throw std::runtime_error(
"failed test2 1");
126 else set_obj.clear();
135 SET_TYPE set_copy(set_obj);
137 if (set_copy.size() != set_obj.size()) {
138 throw std::runtime_error(
"failed test2 2");
141 typename SET_TYPE::const_iterator
142 s_iter = set_obj.begin(),
143 s_end = set_obj.end();
145 typename SET_TYPE::const_iterator
146 c_iter = set_copy.begin(),
147 c_end = set_copy.end();
149 for(; s_iter != s_end; ++s_iter) {
150 if (*s_iter != *c_iter) {
151 throw std::runtime_error(
"failed test2 3");
156 if (c_iter != c_end) {
157 throw std::runtime_error(
"failed test2 4");
161 int test_Set::runtests()
163 if (numProcs_ > 1)
return(0);
178 int test_Set::test1()
183 int test_Set::test2()
185 FEI_COUT <<
"testing fei::ctg_set<int> insert,insert2,find,iterate...";
197 ss2_iter = sset2.
begin(),
198 ss2_end = sset2.
end();
201 for(; ss2_iter != ss2_end; ++ss2_iter) {
202 if (*ss2_iter != i && *ss2_iter != 8) {
208 int size2 = sset2.
size();
243 int size3 = sset3.
size();
249 if (*ss3_iter4 != 4) {
254 if (*ss3_iter4 != 6) {
259 if (*ss3_iter8 != 8) {
263 FEI_COUT <<
"ok"<<FEI_ENDL;
267 int test_Set::test3()
272 int test_Set::test4()
278 int test_Set::test5()
280 FEI_COUT <<
"testing fei::binarySearch(...,start,end,...)...";
282 std::vector<int> array;
283 for(
int i=0; i<10; ++i) array.push_back(i);
287 int insertPoint = -1;
289 start, end, insertPoint);
295 start, end, insertPoint);
309 if (sset.
size() != 6) {
313 if (sset.
find(0) == sset.
end()) {
317 FEI_COUT <<
"ok"<<FEI_ENDL;
322 int test_Set::test6()
327 int test_Set::test7()
333 int test_Set::test8()
338 int test_Set::test9()
const_iterator find(const T &item)
int binarySearch(const T &item, const T *list, int len)
const_iterator begin() const
void insert2(const T &item)
static const_iterator end()
std::pair< const_iterator, bool > insert(const T &item)