test/dim_test.cc
changeset 2207 75a29ac69c19
parent 2006 00d59f733817
child 2212 0ad3835449f8
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/dim_test.cc	Thu Sep 07 13:27:16 2006 +0000
     1.3 @@ -0,0 +1,82 @@
     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-2006
     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 +	Point a(1,2);
    1.37 +	Point b(3,4);
    1.38 +
    1.39 +	seged = a+b;
    1.40 +	check(seged.x==4 && seged.y==6, "Wrong vector addition");
    1.41 +
    1.42 +	seged = a-b;
    1.43 +	check(seged.x==-2 && seged.y==-2, "a-b");
    1.44 +
    1.45 +	check(a.normSquare()==5,"Wrong norm calculation");
    1.46 +	check(a*b==11, "a*b");
    1.47 +
    1.48 +	int l=2;
    1.49 +	seged = a*l;
    1.50 +	check(seged.x==2 && seged.y==4, "a*l");
    1.51 +
    1.52 +	seged = b/l;
    1.53 +	check(seged.x==1 && seged.y==2, "b/l");
    1.54 +
    1.55 +	typedef dim2::BoundingBox<int> BB;
    1.56 +	BB doboz1;
    1.57 +	check(doboz1.empty(), "It should be empty.");
    1.58 +	
    1.59 +	doboz1.add(a);
    1.60 +	check(!doboz1.empty(), "It should not be empty.");
    1.61 +	doboz1.add(b);
    1.62 +
    1.63 +	check(doboz1.bottomLeft().x==1 && 
    1.64 +	      doboz1.bottomLeft().y==2 &&
    1.65 +	      doboz1.topRight().x==3 && 
    1.66 +	      doboz1.topRight().y==4,  
    1.67 +	      "added points to box");
    1.68 +
    1.69 +	seged.x=2;seged.y=3;
    1.70 +	check(doboz1.inside(seged),"It should be inside.");
    1.71 +
    1.72 +	seged.x=1;seged.y=3;
    1.73 +	check(doboz1.inside(seged),"It should be inside.");
    1.74 +
    1.75 +	seged.x=0;seged.y=3;
    1.76 +	check(!doboz1.inside(seged),"It should not be inside.");
    1.77 +
    1.78 +	BB doboz2(seged);
    1.79 +	check(!doboz2.empty(),
    1.80 +	      "It should not be empty. Constructed from 1 point.");
    1.81 +
    1.82 +	doboz2.add(doboz1);
    1.83 +	check(doboz2.inside(seged),
    1.84 +	      "It should be inside. Incremented a box with another one.");
    1.85 +}