src/test/xy_test.cc
changeset 768 a5e9303a5511
parent 542 69bde1d90c04
child 774 4297098d9677
equal deleted inserted replaced
3:1bf1f0379601 4:461cebbcf7da
     1 #include <hugo/xy.h>
     1 #include <hugo/xy.h>
     2 #include <iostream>
     2 #include <iostream>
       
     3 #include "test_tools.h"
       
     4 
     3 using namespace std;
     5 using namespace std;
     4 using namespace hugo;
     6 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()
     7 int main()
    20 {
     8 {
    21 
     9 
    22   cout << "Testing classes xy and boundingbox." << endl;
    10   cout << "Testing classes xy and boundingbox." << endl;
    23 
    11 
    26 	XY seged;
    14 	XY seged;
    27 	XY a(1,2);
    15 	XY a(1,2);
    28 	XY b(3,4);
    16 	XY b(3,4);
    29 
    17 
    30 	seged = a+b;
    18 	seged = a+b;
    31 	check(seged.x==4 && seged.y==6);
    19 	check(seged.x==4 && seged.y==6, "Wrong vector addition");
    32 
    20 
    33 	seged = a-b;
    21 	seged = a-b;
    34 	check(seged.x==-2 && seged.y==-2, "a-b");
    22 	check(seged.x==-2 && seged.y==-2, "a-b");
    35 
    23 
    36 	check(a.normSquare()==5);
    24 	check(a.normSquare()==5,"Wrong norm calculation");
    37 	check(a*b==11, "a*b");
    25 	check(a*b==11, "a*b");
    38 
    26 
    39 	int l=2;
    27 	int l=2;
    40 	seged = a*l;
    28 	seged = a*l;
    41 	check(seged.x==2 && seged.y==4, "a*l");
    29 	check(seged.x==2 && seged.y==4, "a*l");
    56 	      doboz1.topRight().x==3 && 
    44 	      doboz1.topRight().x==3 && 
    57 	      doboz1.topRight().y==4,  
    45 	      doboz1.topRight().y==4,  
    58 	      "added points to box");
    46 	      "added points to box");
    59 
    47 
    60 	seged.x=2;seged.y=3;
    48 	seged.x=2;seged.y=3;
    61 	check(doboz1.inside(seged),"Inside? Should be.");
    49 	check(doboz1.inside(seged),"Inside? It should be.");
    62 
    50 
    63 	seged.x=1;seged.y=3;
    51 	seged.x=1;seged.y=3;
    64 	check(doboz1.inside(seged),"Inside? Should be.");
    52 	check(doboz1.inside(seged),"Inside? It should be.");
    65 
    53 
    66 	seged.x=0;seged.y=3;
    54 	seged.x=0;seged.y=3;
    67 	check(!doboz1.inside(seged),"Inside? Should not be.");
    55 	check(!doboz1.inside(seged),"Inside? It should not be.");
    68 
    56 
    69 	BB doboz2(seged);
    57 	BB doboz2(seged);
    70 	check(!doboz2.empty(), "empty? Should not be. Constructed from 1 point.");
    58 	check(!doboz2.empty(),
       
    59 	      "empty? Should not be. Constructed from 1 point.");
    71 
    60 
    72 	doboz2 += doboz1;
    61 	doboz2 += doboz1;
    73 	check(doboz2.inside(seged),"Inside? Should be. Incremented a box with an other.");
    62 	check(doboz2.inside(seged),
    74 
    63 	      "Not inside? It should be. Incremented a box with an other.");
    75 	cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
       
    76 	     << endl;
       
    77 
       
    78 	return passed ? 0 : 1;
       
    79 
       
    80 }
    64 }