src/test/xy_test.cc
changeset 516 c37949721c61
parent 513 60afd11e6cb3
child 517 1380377682ab
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/test/xy_test.cc	Tue May 04 08:31:48 2004 +0000
     1.3 @@ -0,0 +1,80 @@
     1.4 +#include <xy.h>
     1.5 +#include <iostream>
     1.6 +using namespace std;
     1.7 +using namespace hugo;
     1.8 +
     1.9 +bool passed = true;
    1.10 +
    1.11 +void check(bool rc, char *msg="") {
    1.12 +  passed = passed && rc;
    1.13 +  if(!rc) {
    1.14 +    std::cerr << "Test failed! ("<< msg << ")" << std::endl; \
    1.15 + 
    1.16 +
    1.17 +  }
    1.18 +}
    1.19 +
    1.20 +
    1.21 +
    1.22 +int main()
    1.23 +{
    1.24 +
    1.25 +
    1.26 +
    1.27 +	typedef xy<int> XY;
    1.28 +	
    1.29 +	XY seged;
    1.30 +	XY a(1,2);
    1.31 +	XY b(3,4);
    1.32 +
    1.33 +	seged = a+b;
    1.34 +	check(seged.x==4 && seged.y==6);
    1.35 +
    1.36 +	seged = a-b;
    1.37 +	check(seged.x==-2 && seged.y==-2, "a-b");
    1.38 +
    1.39 +	check(a.normSquare()==5);
    1.40 +	check(a*b==11, "a*b");
    1.41 +
    1.42 +	int l=2;
    1.43 +	seged = a*l;
    1.44 +	check(seged.x==2 && seged.y==4, "a*l");
    1.45 +
    1.46 +	seged = b/l;
    1.47 +	check(seged.x==1 && seged.y==2, "b/l");
    1.48 +
    1.49 +	typedef BoundingBox<int> BB;
    1.50 +	BB doboz1;
    1.51 +	check(doboz1.empty(), "empty? Should be.");
    1.52 +	
    1.53 +	doboz1 += a;
    1.54 +	check(!doboz1.empty(), "empty? Should not be.");
    1.55 +	doboz1 += b;
    1.56 +
    1.57 +	check(doboz1.bottomLeft().x==1 && 
    1.58 +	      doboz1.bottomLeft().y==2 &&
    1.59 +	      doboz1.topRight().x==3 && 
    1.60 +	      doboz1.topRight().y==4,  
    1.61 +	      "added points to box");
    1.62 +
    1.63 +	seged.x=2;seged.y=3;
    1.64 +	check(doboz1.inside(seged),"Inside? Should be.");
    1.65 +
    1.66 +	seged.x=1;seged.y=3;
    1.67 +	check(doboz1.inside(seged),"Inside? Should be.");
    1.68 +
    1.69 +	seged.x=0;seged.y=3;
    1.70 +	check(!doboz1.inside(seged),"Inside? Should not be.");
    1.71 +
    1.72 +	BB doboz2(seged);
    1.73 +	check(!doboz2.empty(), "empty? Should not be.");
    1.74 +
    1.75 +	doboz2 += doboz1;
    1.76 +	check(doboz2.inside(seged),"Inside? Should be.");
    1.77 +
    1.78 +	cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
    1.79 +	     << endl;
    1.80 +
    1.81 +	return passed ? 0 : 1;
    1.82 +
    1.83 +}