6
#include<dune/common/arraylist.hh>
7
#include<dune/common/test/iteratortest.hh>
16
Double(double d): val(d){}
17
Double& operator=(double d){
23
bool operator<(Double a, Double b){
27
template<class T, int size>
28
void randomizeList(Dune::ArrayList<T,size>& alist){
33
int lowest=0, highest=1000, range=(highest-lowest)+1;
35
for(int i=0; i < 250; i++)
36
alist.push_back(T(static_cast<int>(range*(rand()/(RAND_MAX+1.0)))));
41
ArrayList<double,10> alist;
44
std::sort(alist.begin(), alist.end());
47
for(ArrayList<double,10>::iterator iter=alist.begin(), end=alist.end();
52
std::cerr << last<<">"<<(*iter)<<" List is not sorted! "<<__FILE__ <<":"<<__LINE__<<std::endl;
61
void initConsecutive(Dune::ArrayList<double,size>& alist){
64
for(int i=0; i < 100; i++)
68
int testIteratorRemove(){
70
ArrayList<double,10> alist;
71
initConsecutive(alist);
72
ArrayList<double,10>::iterator iter=alist.begin();
80
std::cerr<<"Removing from iterator failed! "<<__FILE__<<":"<<__LINE__<<std::endl;
87
std::cerr<<"Removing from iterator failed! "<<__FILE__<<":"<<__LINE__<<std::endl;
96
std::cerr<<"Removing from iterator failed! "<<__FILE__<<":"<<__LINE__<<std::endl;
101
if(*(alist.begin())!=13){
102
std::cerr<<"Purging iterator failed! "<<__FILE__<<":"<<__LINE__<<std::endl;
107
int testRandomAccess(){
108
using namespace Dune;
109
ArrayList<double,10> alist;
110
initConsecutive(alist);
112
ArrayList<double,10>::iterator iter=alist.begin();
115
for(int i=0; i < 100; i++){
117
std::cerr << "Random Access failed: "<<iter[i]<<"!="<<i<<" "<< __FILE__ <<":"<<__LINE__<<std::endl;
122
std::cerr << "Random Access failed "<< __FILE__ <<":"<<__LINE__<<std::endl;
129
int testComparison(){
130
using namespace Dune;
131
ArrayList<double,10> alist;
132
initConsecutive(alist);
134
ArrayList<double,10>::iterator iter=alist.begin(), iter1=alist.begin();
141
std::cerr<<*iter<<">="<<*iter1<<" Operator< seems to be wrong! "<< __FILE__ <<__LINE__<<std::endl;
146
std::cerr<<"operator> seems to be wrong! "<< __FILE__ <<__LINE__<<std::endl;
151
std::cerr<<"operator<= seems to be wrong! "<< __FILE__ <<__LINE__<<std::endl;
156
std::cerr<<"operator>= seems to be wrong! "<< __FILE__ <<__LINE__<<std::endl;
160
if(!(iter1 != iter)){
161
std::cerr<<"operator!= seems to be wrong! "<< __FILE__ <<__LINE__<<std::endl;
165
if(!(iter1 == iter+5)){
166
std::cerr<<"operator== seems to be wrong! "<< __FILE__ <<__LINE__<<std::endl;
174
using namespace Dune;
176
ArrayList<double,100> alist;
178
randomizeList(alist);
180
int ret=testIterator(alist);
182
if(0!=testComparison()){
184
cerr<< "Comparison failed!"<<endl;
187
if(0!=testRandomAccess()){
189
cerr<< "Ransom Access failed!"<<endl;
192
if(0!=testSorting()){
194
cerr<< "Sorting failed!"<<endl;
197
if(0!=testIteratorRemove()){
199
cerr<< "Erasing failed!"<<endl;