test/dim_test.cc
author Akos Ladanyi <ladanyi@tmit.bme.hu>
Sun, 13 Apr 2008 20:15:45 +0200
changeset 142 8b703d177341
parent 14 8685efdef52f
child 171 02f4d5d9bfd7
permissions -rw-r--r--
Improved LEMON_FUNCTION_NAME macro.
It should work fine with GCC and the MS C++ compilers. Otherwise it reverts to
using the __func__ variable which is C99, but I couldn't find a better
alternative.
alpar@8
     1
/* -*- C++ -*-
alpar@8
     2
 *
alpar@8
     3
 * This file is a part of LEMON, a generic C++ optimization library
alpar@8
     4
 *
alpar@39
     5
 * Copyright (C) 2003-2008
alpar@8
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
alpar@8
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
alpar@8
     8
 *
alpar@8
     9
 * Permission to use, modify and distribute this software is granted
alpar@8
    10
 * provided that this copyright notice appears in all copies. For
alpar@8
    11
 * precise terms see the accompanying LICENSE file.
alpar@8
    12
 *
alpar@8
    13
 * This software is provided "AS IS" with no warranty of any kind,
alpar@8
    14
 * express or implied, and with no claim as to its suitability for any
alpar@8
    15
 * purpose.
alpar@8
    16
 *
alpar@8
    17
 */
alpar@8
    18
alpar@8
    19
#include <lemon/dim2.h>
alpar@8
    20
#include <iostream>
alpar@8
    21
#include "test_tools.h"
alpar@8
    22
alpar@8
    23
using namespace std;
alpar@8
    24
using namespace lemon;
kpeter@14
    25
alpar@8
    26
int main()
alpar@8
    27
{
kpeter@14
    28
  cout << "Testing classes 'dim2::Point' and 'dim2::BoundingBox'." << endl;
alpar@8
    29
alpar@8
    30
  typedef dim2::Point<int> Point;
kpeter@14
    31
kpeter@14
    32
  Point p;
kpeter@14
    33
  check(p.size()==2, "Wrong vector initialization.");
alpar@8
    34
alpar@8
    35
  Point a(1,2);
alpar@8
    36
  Point b(3,4);
kpeter@14
    37
  check(a[0]==1 && a[1]==2, "Wrong vector initialization.");
alpar@8
    38
kpeter@14
    39
  p = a+b;
kpeter@14
    40
  check(p.x==4 && p.y==6, "Wrong vector addition.");
alpar@8
    41
kpeter@14
    42
  p = a-b;
kpeter@14
    43
  check(p.x==-2 && p.y==-2, "Wrong vector subtraction.");
alpar@8
    44
kpeter@14
    45
  check(a.normSquare()==5,"Wrong vector norm calculation.");
kpeter@14
    46
  check(a*b==11, "Wrong vector scalar product.");
alpar@8
    47
alpar@8
    48
  int l=2;
kpeter@14
    49
  p = a*l;
kpeter@14
    50
  check(p.x==2 && p.y==4, "Wrong vector multiplication by a scalar.");
alpar@8
    51
kpeter@14
    52
  p = b/l;
kpeter@14
    53
  check(p.x==1 && p.y==2, "Wrong vector division by a scalar.");
alpar@8
    54
alpar@8
    55
  typedef dim2::BoundingBox<int> BB;
kpeter@14
    56
  BB box1;
kpeter@14
    57
  check(box1.empty(), "It should be empty.");
alpar@8
    58
kpeter@14
    59
  box1.add(a);
kpeter@14
    60
  check(!box1.empty(), "It should not be empty.");
kpeter@14
    61
  box1.add(b);
alpar@8
    62
kpeter@14
    63
  check(box1.bottomLeft().x==1 &&
kpeter@14
    64
        box1.bottomLeft().y==2 &&
kpeter@14
    65
        box1.topRight().x==3 &&
kpeter@14
    66
        box1.topRight().y==4,
kpeter@14
    67
        "Wrong addition of points to box.");
alpar@8
    68
kpeter@14
    69
  p.x=2; p.y=3;
kpeter@14
    70
  check(box1.inside(p), "It should be inside.");
alpar@8
    71
kpeter@14
    72
  p.x=1; p.y=3;
kpeter@14
    73
  check(box1.inside(p), "It should be inside.");
alpar@8
    74
kpeter@14
    75
  p.x=0; p.y=3;
kpeter@14
    76
  check(!box1.inside(p), "It should not be inside.");
kpeter@14
    77
kpeter@14
    78
  BB box2(p);
kpeter@14
    79
  check(!box2.empty(),
alpar@8
    80
        "It should not be empty. Constructed from 1 point.");
alpar@8
    81
kpeter@14
    82
  box2.add(box1);
kpeter@14
    83
  check(box2.inside(p),
alpar@8
    84
        "It should be inside. Incremented a box with another one.");
kpeter@14
    85
kpeter@14
    86
  return 0;
alpar@8
    87
}