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