test/dim_test.cc
author deba
Sat, 29 Dec 2007 15:11:41 +0000
changeset 2549 88b81ec599ed
parent 2212 0ad3835449f8
child 2553 bfced05fa852
permissions -rw-r--r--
Test program for max weighted matchings
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@2391
     5
 * Copyright (C) 2003-2007
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@2207
    19
#include <lemon/dim2.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@2207
    28
  cout << "Testing classes `dim2::Point' and `dim2::BoundingBox'." << endl;
athos@201
    29
alpar@2207
    30
  typedef dim2::Point<int> Point;
athos@513
    31
	
deba@2212
    32
  Point seged;
deba@2212
    33
  check(seged.size()==2, "Wrong vector addition");
athos@201
    34
deba@2212
    35
  Point a(1,2);
deba@2212
    36
  Point b(3,4);
athos@201
    37
deba@2212
    38
  check(a[0]==1 && a[1]==2, "Wrong vector addition");
athos@513
    39
deba@2212
    40
  seged = a+b;
deba@2212
    41
  check(seged.x==4 && seged.y==6, "Wrong vector addition");
athos@513
    42
deba@2212
    43
  seged = a-b;
deba@2212
    44
  check(seged.x==-2 && seged.y==-2, "a-b");
athos@513
    45
deba@2212
    46
  check(a.normSquare()==5,"Wrong norm calculation");
deba@2212
    47
  check(a*b==11, "a*b");
athos@513
    48
deba@2212
    49
  int l=2;
deba@2212
    50
  seged = a*l;
deba@2212
    51
  check(seged.x==2 && seged.y==4, "a*l");
deba@2212
    52
deba@2212
    53
  seged = b/l;
deba@2212
    54
  check(seged.x==1 && seged.y==2, "b/l");
deba@2212
    55
deba@2212
    56
  typedef dim2::BoundingBox<int> BB;
deba@2212
    57
  BB doboz1;
deba@2212
    58
  check(doboz1.empty(), "It should be empty.");
athos@516
    59
	
deba@2212
    60
  doboz1.add(a);
deba@2212
    61
  check(!doboz1.empty(), "It should not be empty.");
deba@2212
    62
  doboz1.add(b);
athos@513
    63
deba@2212
    64
  check(doboz1.bottomLeft().x==1 && 
deba@2212
    65
        doboz1.bottomLeft().y==2 &&
deba@2212
    66
        doboz1.topRight().x==3 && 
deba@2212
    67
        doboz1.topRight().y==4,  
deba@2212
    68
        "added points to box");
athos@516
    69
deba@2212
    70
  seged.x=2;seged.y=3;
deba@2212
    71
  check(doboz1.inside(seged),"It should be inside.");
athos@516
    72
deba@2212
    73
  seged.x=1;seged.y=3;
deba@2212
    74
  check(doboz1.inside(seged),"It should be inside.");
athos@516
    75
deba@2212
    76
  seged.x=0;seged.y=3;
deba@2212
    77
  check(!doboz1.inside(seged),"It should not be inside.");
athos@516
    78
deba@2212
    79
  BB doboz2(seged);
deba@2212
    80
  check(!doboz2.empty(),
deba@2212
    81
        "It should not be empty. Constructed from 1 point.");
athos@516
    82
deba@2212
    83
  doboz2.add(doboz1);
deba@2212
    84
  check(doboz2.inside(seged),
deba@2212
    85
        "It should be inside. Incremented a box with another one.");
athos@201
    86
}