test/dim_test.cc
changeset 195 aa45ff44fcf3
parent 39 0a01d811071f
child 209 765619b7cbb2
equal deleted inserted replaced
2:6baa1d035d08 3:581312b5a4f3
    23 using namespace std;
    23 using namespace std;
    24 using namespace lemon;
    24 using namespace lemon;
    25 
    25 
    26 int main()
    26 int main()
    27 {
    27 {
    28   cout << "Testing classes 'dim2::Point' and 'dim2::BoundingBox'." << endl;
       
    29 
       
    30   typedef dim2::Point<int> Point;
    28   typedef dim2::Point<int> Point;
    31 
    29 
    32   Point p;
    30   Point p;
    33   check(p.size()==2, "Wrong vector initialization.");
    31   check(p.size()==2, "Wrong dim2::Point initialization.");
    34 
    32 
    35   Point a(1,2);
    33   Point a(1,2);
    36   Point b(3,4);
    34   Point b(3,4);
    37   check(a[0]==1 && a[1]==2, "Wrong vector initialization.");
    35   check(a[0]==1 && a[1]==2, "Wrong dim2::Point initialization.");
    38 
    36 
    39   p = a+b;
    37   p = a+b;
    40   check(p.x==4 && p.y==6, "Wrong vector addition.");
    38   check(p.x==4 && p.y==6, "Wrong dim2::Point addition.");
    41 
    39 
    42   p = a-b;
    40   p = a-b;
    43   check(p.x==-2 && p.y==-2, "Wrong vector subtraction.");
    41   check(p.x==-2 && p.y==-2, "Wrong dim2::Point subtraction.");
    44 
    42 
    45   check(a.normSquare()==5,"Wrong vector norm calculation.");
    43   check(a.normSquare()==5,"Wrong dim2::Point norm calculation.");
    46   check(a*b==11, "Wrong vector scalar product.");
    44   check(a*b==11, "Wrong dim2::Point scalar product.");
    47 
    45 
    48   int l=2;
    46   int l=2;
    49   p = a*l;
    47   p = a*l;
    50   check(p.x==2 && p.y==4, "Wrong vector multiplication by a scalar.");
    48   check(p.x==2 && p.y==4, "Wrong dim2::Point multiplication by a scalar.");
    51 
    49 
    52   p = b/l;
    50   p = b/l;
    53   check(p.x==1 && p.y==2, "Wrong vector division by a scalar.");
    51   check(p.x==1 && p.y==2, "Wrong dim2::Point division by a scalar.");
    54 
    52 
    55   typedef dim2::BoundingBox<int> BB;
    53   typedef dim2::BoundingBox<int> BB;
    56   BB box1;
    54   BB box1;
    57   check(box1.empty(), "It should be empty.");
    55   check(box1.empty(), "Wrong empty() in dim2::BoundingBox.");
    58 
    56 
    59   box1.add(a);
    57   box1.add(a);
    60   check(!box1.empty(), "It should not be empty.");
    58   check(!box1.empty(), "Wrong empty() in dim2::BoundingBox.");
    61   box1.add(b);
    59   box1.add(b);
    62 
    60 
    63   check(box1.bottomLeft().x==1 &&
    61   check(box1.bottomLeft().x==1 &&
    64         box1.bottomLeft().y==2 &&
    62         box1.bottomLeft().y==2 &&
    65         box1.topRight().x==3 &&
    63         box1.topRight().x==3 &&
    66         box1.topRight().y==4,
    64         box1.topRight().y==4,
    67         "Wrong addition of points to box.");
    65         "Wrong addition of points to dim2::BoundingBox.");
    68 
    66 
    69   p.x=2; p.y=3;
    67   p.x=2; p.y=3;
    70   check(box1.inside(p), "It should be inside.");
    68   check(box1.inside(p), "Wrong inside() in dim2::BoundingBox.");
    71 
    69 
    72   p.x=1; p.y=3;
    70   p.x=1; p.y=3;
    73   check(box1.inside(p), "It should be inside.");
    71   check(box1.inside(p), "Wrong inside() in dim2::BoundingBox.");
    74 
    72 
    75   p.x=0; p.y=3;
    73   p.x=0; p.y=3;
    76   check(!box1.inside(p), "It should not be inside.");
    74   check(!box1.inside(p), "Wrong inside() in dim2::BoundingBox.");
    77 
    75 
    78   BB box2(p);
    76   BB box2(p);
    79   check(!box2.empty(),
    77   check(!box2.empty(), "Wrong empty() in dim2::BoundingBox.");
    80         "It should not be empty. Constructed from 1 point.");
       
    81 
    78 
    82   box2.add(box1);
    79   box2.add(box1);
    83   check(box2.inside(p),
    80   check(box2.inside(p), "Wrong inside() in dim2::BoundingBox.");
    84         "It should be inside. Incremented a box with another one.");
       
    85 
    81 
    86   return 0;
    82   return 0;
    87 }
    83 }