test/dim_test.cc
changeset 2637 bafe730864da
parent 2553 bfced05fa852
equal deleted inserted replaced
3:db39feac3c13 4:a34543da391e
    20 #include <iostream>
    20 #include <iostream>
    21 #include "test_tools.h"
    21 #include "test_tools.h"
    22 
    22 
    23 using namespace std;
    23 using namespace std;
    24 using namespace lemon;
    24 using namespace lemon;
       
    25 
    25 int main()
    26 int main()
    26 {
    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 p;
    33   check(seged.size()==2, "Wrong vector addition");
    33   check(p.size()==2, "Wrong vector initialization.");
    34 
    34 
    35   Point a(1,2);
    35   Point a(1,2);
    36   Point b(3,4);
    36   Point b(3,4);
       
    37   check(a[0]==1 && a[1]==2, "Wrong vector initialization.");
    37 
    38 
    38   check(a[0]==1 && a[1]==2, "Wrong vector addition");
    39   p = a+b;
       
    40   check(p.x==4 && p.y==6, "Wrong vector addition.");
    39 
    41 
    40   seged = a+b;
    42   p = a-b;
    41   check(seged.x==4 && seged.y==6, "Wrong vector addition");
    43   check(p.x==-2 && p.y==-2, "Wrong vector subtraction.");
    42 
    44 
    43   seged = a-b;
    45   check(a.normSquare()==5,"Wrong vector norm calculation.");
    44   check(seged.x==-2 && seged.y==-2, "a-b");
    46   check(a*b==11, "Wrong vector scalar product.");
    45 
       
    46   check(a.normSquare()==5,"Wrong norm calculation");
       
    47   check(a*b==11, "a*b");
       
    48 
    47 
    49   int l=2;
    48   int l=2;
    50   seged = a*l;
    49   p = a*l;
    51   check(seged.x==2 && seged.y==4, "a*l");
    50   check(p.x==2 && p.y==4, "Wrong vector multiplication by a scalar.");
    52 
    51 
    53   seged = b/l;
    52   p = b/l;
    54   check(seged.x==1 && seged.y==2, "b/l");
    53   check(p.x==1 && p.y==2, "Wrong vector division by a scalar.");
    55 
    54 
    56   typedef dim2::BoundingBox<int> BB;
    55   typedef dim2::BoundingBox<int> BB;
    57   BB doboz1;
    56   BB box1;
    58   check(doboz1.empty(), "It should be empty.");
    57   check(box1.empty(), "It should be empty.");
    59 	
       
    60   doboz1.add(a);
       
    61   check(!doboz1.empty(), "It should not be empty.");
       
    62   doboz1.add(b);
       
    63 
    58 
    64   check(doboz1.bottomLeft().x==1 && 
    59   box1.add(a);
    65         doboz1.bottomLeft().y==2 &&
    60   check(!box1.empty(), "It should not be empty.");
    66         doboz1.topRight().x==3 && 
    61   box1.add(b);
    67         doboz1.topRight().y==4,  
       
    68         "added points to box");
       
    69 
    62 
    70   seged.x=2;seged.y=3;
    63   check(box1.bottomLeft().x==1 &&
    71   check(doboz1.inside(seged),"It should be inside.");
    64         box1.bottomLeft().y==2 &&
       
    65         box1.topRight().x==3 &&
       
    66         box1.topRight().y==4,
       
    67         "Wrong addition of points to box.");
    72 
    68 
    73   seged.x=1;seged.y=3;
    69   p.x=2; p.y=3;
    74   check(doboz1.inside(seged),"It should be inside.");
    70   check(box1.inside(p), "It should be inside.");
    75 
    71 
    76   seged.x=0;seged.y=3;
    72   p.x=1; p.y=3;
    77   check(!doboz1.inside(seged),"It should not be inside.");
    73   check(box1.inside(p), "It should be inside.");
    78 
    74 
    79   BB doboz2(seged);
    75   p.x=0; p.y=3;
    80   check(!doboz2.empty(),
    76   check(!box1.inside(p), "It should not be inside.");
       
    77 
       
    78   BB box2(p);
       
    79   check(!box2.empty(),
    81         "It should not be empty. Constructed from 1 point.");
    80         "It should not be empty. Constructed from 1 point.");
    82 
    81 
    83   doboz2.add(doboz1);
    82   box2.add(box1);
    84   check(doboz2.inside(seged),
    83   check(box2.inside(p),
    85         "It should be inside. Incremented a box with another one.");
    84         "It should be inside. Incremented a box with another one.");
       
    85 
       
    86   return 0;
    86 }
    87 }