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