src/test/xy_test.cc
changeset 1435 8e85e6bbefdf
parent 1164 80bb73097736
equal deleted inserted replaced
9:af33011912f1 -1:000000000000
     1 /* -*- C++ -*-
       
     2  * src/test/xy_test.cc - Part of LEMON, a generic C++ optimization library
       
     3  *
       
     4  * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
       
     5  * (Egervary Research Group on Combinatorial Optimization, EGRES).
       
     6  *
       
     7  * Permission to use, modify and distribute this software is granted
       
     8  * provided that this copyright notice appears in all copies. For
       
     9  * precise terms see the accompanying LICENSE file.
       
    10  *
       
    11  * This software is provided "AS IS" with no warranty of any kind,
       
    12  * express or implied, and with no claim as to its suitability for any
       
    13  * purpose.
       
    14  *
       
    15  */
       
    16 
       
    17 #include <lemon/xy.h>
       
    18 #include <iostream>
       
    19 #include "test_tools.h"
       
    20 
       
    21 using namespace std;
       
    22 using namespace lemon;
       
    23 int main()
       
    24 {
       
    25 
       
    26   cout << "Testing classes `xy' and `boundingbox'." << endl;
       
    27 
       
    28 	typedef xy<int> XY;
       
    29 	
       
    30 	XY seged;
       
    31 	XY a(1,2);
       
    32 	XY b(3,4);
       
    33 
       
    34 	seged = a+b;
       
    35 	check(seged.x==4 && seged.y==6, "Wrong vector addition");
       
    36 
       
    37 	seged = a-b;
       
    38 	check(seged.x==-2 && seged.y==-2, "a-b");
       
    39 
       
    40 	check(a.normSquare()==5,"Wrong norm calculation");
       
    41 	check(a*b==11, "a*b");
       
    42 
       
    43 	int l=2;
       
    44 	seged = a*l;
       
    45 	check(seged.x==2 && seged.y==4, "a*l");
       
    46 
       
    47 	seged = b/l;
       
    48 	check(seged.x==1 && seged.y==2, "b/l");
       
    49 
       
    50 	typedef BoundingBox<int> BB;
       
    51 	BB doboz1;
       
    52 	check(doboz1.empty(), "It should be empty.");
       
    53 	
       
    54 	doboz1 += a;
       
    55 	check(!doboz1.empty(), "It should not be empty.");
       
    56 	doboz1 += b;
       
    57 
       
    58 	check(doboz1.bottomLeft().x==1 && 
       
    59 	      doboz1.bottomLeft().y==2 &&
       
    60 	      doboz1.topRight().x==3 && 
       
    61 	      doboz1.topRight().y==4,  
       
    62 	      "added points to box");
       
    63 
       
    64 	seged.x=2;seged.y=3;
       
    65 	check(doboz1.inside(seged),"It should be inside.");
       
    66 
       
    67 	seged.x=1;seged.y=3;
       
    68 	check(doboz1.inside(seged),"It should be inside.");
       
    69 
       
    70 	seged.x=0;seged.y=3;
       
    71 	check(!doboz1.inside(seged),"It should not be inside.");
       
    72 
       
    73 	BB doboz2(seged);
       
    74 	check(!doboz2.empty(),
       
    75 	      "It should not be empty. Constructed from 1 point.");
       
    76 
       
    77 	doboz2 += doboz1;
       
    78 	check(doboz2.inside(seged),
       
    79 	      "It should be inside. Incremented a box with an other.");
       
    80 }