src/test/xy_test.cc
author alpar
Wed, 16 Jun 2004 09:44:30 +0000
changeset 686 fc8a3393e0d9
parent 518 fcdb561b8c78
child 727 aada518af30f
permissions -rw-r--r--
src/work/alpar/path.h (docs) is merged into src/work/klao/path.h
(and removed)
     1 #include <hugo/xy.h>
     2 #include <iostream>
     3 using namespace std;
     4 using namespace hugo;
     5 
     6 bool passed = true;
     7 
     8 void check(bool rc, char *msg="") {
     9   passed = passed && rc;
    10   if(!rc) {
    11     std::cerr << "Test failed! ("<< msg << ")" << std::endl; \
    12  
    13 
    14   }
    15 }
    16 
    17 
    18 
    19 int main()
    20 {
    21 
    22   cout << "Testing classes xy and boundingbox." << endl;
    23 
    24 	typedef xy<int> XY;
    25 	
    26 	XY seged;
    27 	XY a(1,2);
    28 	XY b(3,4);
    29 
    30 	seged = a+b;
    31 	check(seged.x==4 && seged.y==6);
    32 
    33 	seged = a-b;
    34 	check(seged.x==-2 && seged.y==-2, "a-b");
    35 
    36 	check(a.normSquare()==5);
    37 	check(a*b==11, "a*b");
    38 
    39 	int l=2;
    40 	seged = a*l;
    41 	check(seged.x==2 && seged.y==4, "a*l");
    42 
    43 	seged = b/l;
    44 	check(seged.x==1 && seged.y==2, "b/l");
    45 
    46 	typedef BoundingBox<int> BB;
    47 	BB doboz1;
    48 	check(doboz1.empty(), "empty? Should be.");
    49 	
    50 	doboz1 += a;
    51 	check(!doboz1.empty(), "empty? Should not be.");
    52 	doboz1 += b;
    53 
    54 	check(doboz1.bottomLeft().x==1 && 
    55 	      doboz1.bottomLeft().y==2 &&
    56 	      doboz1.topRight().x==3 && 
    57 	      doboz1.topRight().y==4,  
    58 	      "added points to box");
    59 
    60 	seged.x=2;seged.y=3;
    61 	check(doboz1.inside(seged),"Inside? Should be.");
    62 
    63 	seged.x=1;seged.y=3;
    64 	check(doboz1.inside(seged),"Inside? Should be.");
    65 
    66 	seged.x=0;seged.y=3;
    67 	check(!doboz1.inside(seged),"Inside? Should not be.");
    68 
    69 	BB doboz2(seged);
    70 	check(!doboz2.empty(), "empty? Should not be. Constructed from 1 point.");
    71 
    72 	doboz2 += doboz1;
    73 	check(doboz2.inside(seged),"Inside? Should be. Incremented a box with an other.");
    74 
    75 	cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
    76 	     << endl;
    77 
    78 	return passed ? 0 : 1;
    79 
    80 }