test/dim_test.cc
changeset 8 a1b1d672f37a
child 14 8685efdef52f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/dim_test.cc	Thu Dec 20 16:11:56 2007 +0000
     1.3 @@ -0,0 +1,86 @@
     1.4 +/* -*- C++ -*-
     1.5 + *
     1.6 + * This file is a part of LEMON, a generic C++ optimization library
     1.7 + *
     1.8 + * Copyright (C) 2003-2007
     1.9 + * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
    1.10 + * (Egervary Research Group on Combinatorial Optimization, EGRES).
    1.11 + *
    1.12 + * Permission to use, modify and distribute this software is granted
    1.13 + * provided that this copyright notice appears in all copies. For
    1.14 + * precise terms see the accompanying LICENSE file.
    1.15 + *
    1.16 + * This software is provided "AS IS" with no warranty of any kind,
    1.17 + * express or implied, and with no claim as to its suitability for any
    1.18 + * purpose.
    1.19 + *
    1.20 + */
    1.21 +
    1.22 +#include <lemon/dim2.h>
    1.23 +#include <iostream>
    1.24 +#include "test_tools.h"
    1.25 +
    1.26 +using namespace std;
    1.27 +using namespace lemon;
    1.28 +int main()
    1.29 +{
    1.30 +
    1.31 +  cout << "Testing classes `dim2::Point' and `dim2::BoundingBox'." << endl;
    1.32 +
    1.33 +  typedef dim2::Point<int> Point;
    1.34 +	
    1.35 +  Point seged;
    1.36 +  check(seged.size()==2, "Wrong vector addition");
    1.37 +
    1.38 +  Point a(1,2);
    1.39 +  Point b(3,4);
    1.40 +
    1.41 +  check(a[0]==1 && a[1]==2, "Wrong vector addition");
    1.42 +
    1.43 +  seged = a+b;
    1.44 +  check(seged.x==4 && seged.y==6, "Wrong vector addition");
    1.45 +
    1.46 +  seged = a-b;
    1.47 +  check(seged.x==-2 && seged.y==-2, "a-b");
    1.48 +
    1.49 +  check(a.normSquare()==5,"Wrong norm calculation");
    1.50 +  check(a*b==11, "a*b");
    1.51 +
    1.52 +  int l=2;
    1.53 +  seged = a*l;
    1.54 +  check(seged.x==2 && seged.y==4, "a*l");
    1.55 +
    1.56 +  seged = b/l;
    1.57 +  check(seged.x==1 && seged.y==2, "b/l");
    1.58 +
    1.59 +  typedef dim2::BoundingBox<int> BB;
    1.60 +  BB doboz1;
    1.61 +  check(doboz1.empty(), "It should be empty.");
    1.62 +	
    1.63 +  doboz1.add(a);
    1.64 +  check(!doboz1.empty(), "It should not be empty.");
    1.65 +  doboz1.add(b);
    1.66 +
    1.67 +  check(doboz1.bottomLeft().x==1 && 
    1.68 +        doboz1.bottomLeft().y==2 &&
    1.69 +        doboz1.topRight().x==3 && 
    1.70 +        doboz1.topRight().y==4,  
    1.71 +        "added points to box");
    1.72 +
    1.73 +  seged.x=2;seged.y=3;
    1.74 +  check(doboz1.inside(seged),"It should be inside.");
    1.75 +
    1.76 +  seged.x=1;seged.y=3;
    1.77 +  check(doboz1.inside(seged),"It should be inside.");
    1.78 +
    1.79 +  seged.x=0;seged.y=3;
    1.80 +  check(!doboz1.inside(seged),"It should not be inside.");
    1.81 +
    1.82 +  BB doboz2(seged);
    1.83 +  check(!doboz2.empty(),
    1.84 +        "It should not be empty. Constructed from 1 point.");
    1.85 +
    1.86 +  doboz2.add(doboz1);
    1.87 +  check(doboz2.inside(seged),
    1.88 +        "It should be inside. Incremented a box with another one.");
    1.89 +}