#include <Imagine/Common.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <utility>
using namespace std;
void base() {
cout <<
"Imagine++ version is " <<
VERSION << endl;
cout <<
"File named xxx in source path is replaced by: " <<
srcPath(
"xxx") << endl;
string name="xxx";
cout <<
"File named string xxx in source path is replaced by: " <<
stringSrcPath(name) << endl;
}
void fArrays() {
cout << "Testing FArray functions!" << endl;
char tt[]={'a','b','c'};
dd=b;
di=a;
cout << a.
size() << endl;
char x,y;
x=a[0];
c[0]=x;
x=y;
cout << *cit << endl;
*it='x';
if (a==b) cout << "a equals b" << endl;
if (a!=b) cout << "a is different from b" << endl;
range(a);
ofstream out("tmp.bin",ios::binary);
write(out,a);
out.close();
ifstream in("tmp.bin",ios::binary);
read(in,a);
in.close();
out.open("tmp.txt");
out << a << endl;
out.close();
in.open("tmp.txt");
in >> a;
in.close();
}
void fVectors() {
cout << "Testing FVector functions!" << endl;
double tt[]={1,2,3};
dd=c;
di=c;
double x,y,z;
c=a+b;
c=a-b;
c+=a;
c-=a;
c=a+3.;
c=a-3.;
c+=3.;
c-=3.;
b=-a;
x=a*b;
c=a^b;
c=a*2;
c=a/2;
c*=2;
c/=2;
c=2.*a;
c=2.+a;
c=2.-a;
x=norm2(a);
x=norm(a);
c=normalized(dd);
x=maxNorm(a);
int i=intNorm2(di);
i=intNorm1(di);
(void)i;
x=doubleNorm2(di);
x=doubleNorm(di);
x=doubleNorm1(di);
x=sum(a);
c=mult(a,b);
c=div(a,b);
c=sqrt(a);
c=log(a);
c=exp(a);
c=pmin(a,b);
c=pmax(a,b);
x=squaredDist(di,di);
x=dist(di,di);
x=intL1Dist(di,di);
x=L1Dist(di,di);
}
void fMatrices() {
cout << "Testing FMatrix functions!" << endl;
double t1[6]={1,2,3,4,5,6};
double t2[2][3]={{1,2,3},{4,5,6}};
Ed=B;
Ei=B;
double x;
x=A(1,2);
A(1,2)=x;
x=A[4];
A[4]=x;
if (A==B) cout << "A equals B" << endl;
if (A!=B) cout << "A is different from B" << endl;
C=A+B;
C=A-B;
C+=A;
C-=A;
C=A+3.;
C=A-3.;
C+=3.;
C-=3.;
B=-A;
C=A*2;
C=A/2;
C*=2;
C/=2;
C=2.*A;
C=2.+A;
C=2.-A;
A34=A32*A24;
v3=A32*v2;
double t9[]={1,2,9,3,4,6,5,7,2};
x=norm2(A);
x=norm(A);
ofstream out("tmp.bin",ios::binary);
write(out,A);
out.close();
ifstream in("tmp.bin",ios::binary);
read(in,A);
in.close();
out.open("tmp.txt");
out << A << endl;
out.close();
in.open("tmp.txt");
in >> A;
in.close();
}
void colors() {
cout << "Testing Color functions!" << endl;
double t1[]={.2,1.,.23};
double x;
(void)grey;
x = (byte)123;
double t2[]={.2,1.,.23,.3};
grey=float(o);
col=YUV2RGB<byte>(yuv);
}
void arrays() {
cout << "Testing Array functions!" << endl;
char t[4]={'a','b','c','d'};
char* t2=new char[3];
list<char>l;
l.push_front('a');
a=b;
di=b;
cout<< "a is empty" << endl;
char x;
x=b[2];
b[2]=x;
cout << *cit << endl;
*it='x';
if (a==b) cout << "a equals b" << endl;
if (a!=b) cout << "a is different from b" << endl;
range(a);
prange(f);
ofstream out("tmp.bin",ios::binary);
write(out,a);
out.close();
ifstream in("tmp.bin",ios::binary);
read(in,a);
in.close();
out.open("tmp.txt");
out << a << endl;
out.close();
in.open("tmp.txt");
in >> a;
in.close();
}
void coords() {
cout << "Testing coords functions!" << endl;
int t[]={1,2,3};
(void)d; (void)e;
it1=it2;
if (it1==it2) cout << "it1 equals it2" << endl;
if (it1!=it2) cout << "it1 is different from it2" << endl;
cout << *it << endl;
cout << it++->x() << endl;
}
void multiArrays() {
cout << "Testing multi Array functions!" << endl;
char t[6]={'a','b','c','d','e','f'};
char *t2=new char[6];
a=b;
ji=jc;
char x;
x=a(0,1);
a(0,1)=x;
x=c3(1,0,1);
c3(1,0,1)=x;
cout << "[" << *it << "]=" << i(*it) << endl;
ofstream out("tmp.bin",ios::binary);
write(out,i);
out.close();
ifstream in("tmp.bin",ios::binary);
read(in,i);
in.close();
out.open("tmp.txt");
out << i << endl;
out.close();
in.open("tmp.txt");
in >> i;
in.close();
}
void rands() {
cout << "Testing random functions!"<<endl;
}
void timers() {
cout << "Testing Timer functions!"<<endl;
(void)x;
}
void io() {
cout << "Testing IO functions!"<<endl;
}
int main(int argc, char* argv[]) {
typedef void (*FUNC)();
vector< pair<string,FUNC> > tests;
#define ADD_TEST(func) \
tests.push_back(make_pair(string(#func), func));
ADD_TEST(base);
ADD_TEST(fArrays);
ADD_TEST(fVectors);
ADD_TEST(fMatrices);
ADD_TEST(colors);
ADD_TEST(arrays);
ADD_TEST(coords);
ADD_TEST(multiArrays);
ADD_TEST(rands);
ADD_TEST(timers);
ADD_TEST(io);
std::vector< pair<string,FUNC> >::const_iterator it;
if(argc<=1)
for(it=tests.begin(); it!=tests.end(); ++it) {
cout << "---" << it->first << "---" << std::endl;
it->second();
}
else {
bool fail=false;
for(int i=1; i<argc; i++) {
for(it=tests.begin(); it!=tests.end(); ++it) {
if(it->first == argv[i]) {
cout << "---" << it->first << "---" << std::endl;
it->second();
break;
}
}
if(it==tests.end()) {
std::cout << "Unknown test " << argv[i] << endl;
fail = true;
}
}
if(fail) {
cout << "--- Available tests:" << endl;
for(it=tests.begin(); it!=tests.end(); ++it)
cout << it->first << ' ';
cout << endl;
return 0;
}
}
return 0;
}