test/dim_test.cc
changeset 2359 97a5cd10ca16
parent 2207 75a29ac69c19
child 2391 14a343be7a5a
equal deleted inserted replaced
0:3d73cb4dd801 1:9a27c6c80a16
    27 
    27 
    28   cout << "Testing classes `dim2::Point' and `dim2::BoundingBox'." << endl;
    28   cout << "Testing classes `dim2::Point' and `dim2::BoundingBox'." << endl;
    29 
    29 
    30   typedef dim2::Point<int> Point;
    30   typedef dim2::Point<int> Point;
    31 	
    31 	
    32 	Point seged;
    32   Point seged;
    33 	Point a(1,2);
    33   check(seged.size()==2, "Wrong vector addition");
    34 	Point b(3,4);
       
    35 
    34 
    36 	seged = a+b;
    35   Point a(1,2);
    37 	check(seged.x==4 && seged.y==6, "Wrong vector addition");
    36   Point b(3,4);
    38 
    37 
    39 	seged = a-b;
    38   check(a[0]==1 && a[1]==2, "Wrong vector addition");
    40 	check(seged.x==-2 && seged.y==-2, "a-b");
       
    41 
    39 
    42 	check(a.normSquare()==5,"Wrong norm calculation");
    40   seged = a+b;
    43 	check(a*b==11, "a*b");
    41   check(seged.x==4 && seged.y==6, "Wrong vector addition");
    44 
    42 
    45 	int l=2;
    43   seged = a-b;
    46 	seged = a*l;
    44   check(seged.x==-2 && seged.y==-2, "a-b");
    47 	check(seged.x==2 && seged.y==4, "a*l");
       
    48 
    45 
    49 	seged = b/l;
    46   check(a.normSquare()==5,"Wrong norm calculation");
    50 	check(seged.x==1 && seged.y==2, "b/l");
    47   check(a*b==11, "a*b");
    51 
    48 
    52 	typedef dim2::BoundingBox<int> BB;
    49   int l=2;
    53 	BB doboz1;
    50   seged = a*l;
    54 	check(doboz1.empty(), "It should be empty.");
    51   check(seged.x==2 && seged.y==4, "a*l");
       
    52 
       
    53   seged = b/l;
       
    54   check(seged.x==1 && seged.y==2, "b/l");
       
    55 
       
    56   typedef dim2::BoundingBox<int> BB;
       
    57   BB doboz1;
       
    58   check(doboz1.empty(), "It should be empty.");
    55 	
    59 	
    56 	doboz1.add(a);
    60   doboz1.add(a);
    57 	check(!doboz1.empty(), "It should not be empty.");
    61   check(!doboz1.empty(), "It should not be empty.");
    58 	doboz1.add(b);
    62   doboz1.add(b);
    59 
    63 
    60 	check(doboz1.bottomLeft().x==1 && 
    64   check(doboz1.bottomLeft().x==1 && 
    61 	      doboz1.bottomLeft().y==2 &&
    65         doboz1.bottomLeft().y==2 &&
    62 	      doboz1.topRight().x==3 && 
    66         doboz1.topRight().x==3 && 
    63 	      doboz1.topRight().y==4,  
    67         doboz1.topRight().y==4,  
    64 	      "added points to box");
    68         "added points to box");
    65 
    69 
    66 	seged.x=2;seged.y=3;
    70   seged.x=2;seged.y=3;
    67 	check(doboz1.inside(seged),"It should be inside.");
    71   check(doboz1.inside(seged),"It should be inside.");
    68 
    72 
    69 	seged.x=1;seged.y=3;
    73   seged.x=1;seged.y=3;
    70 	check(doboz1.inside(seged),"It should be inside.");
    74   check(doboz1.inside(seged),"It should be inside.");
    71 
    75 
    72 	seged.x=0;seged.y=3;
    76   seged.x=0;seged.y=3;
    73 	check(!doboz1.inside(seged),"It should not be inside.");
    77   check(!doboz1.inside(seged),"It should not be inside.");
    74 
    78 
    75 	BB doboz2(seged);
    79   BB doboz2(seged);
    76 	check(!doboz2.empty(),
    80   check(!doboz2.empty(),
    77 	      "It should not be empty. Constructed from 1 point.");
    81         "It should not be empty. Constructed from 1 point.");
    78 
    82 
    79 	doboz2.add(doboz1);
    83   doboz2.add(doboz1);
    80 	check(doboz2.inside(seged),
    84   check(doboz2.inside(seged),
    81 	      "It should be inside. Incremented a box with another one.");
    85         "It should be inside. Incremented a box with another one.");
    82 }
    86 }