test/dim_test.cc
author Alpar Juttner <alpar@cs.elte.hu>
Tue, 15 Jul 2008 18:49:30 +0100
changeset 221 64613d8fae28
parent 171 02f4d5d9bfd7
child 242 dbe3fc9c875d
permissions -rw-r--r--
Merge
alpar@209
     1
/* -*- mode: C++; indent-tabs-mode: nil; -*-
alpar@8
     2
 *
alpar@209
     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
{
alpar@8
    28
  typedef dim2::Point<int> Point;
kpeter@14
    29
kpeter@14
    30
  Point p;
kpeter@171
    31
  check(p.size()==2, "Wrong dim2::Point initialization.");
alpar@8
    32
alpar@8
    33
  Point a(1,2);
alpar@8
    34
  Point b(3,4);
kpeter@171
    35
  check(a[0]==1 && a[1]==2, "Wrong dim2::Point initialization.");
alpar@8
    36
kpeter@14
    37
  p = a+b;
kpeter@171
    38
  check(p.x==4 && p.y==6, "Wrong dim2::Point addition.");
alpar@8
    39
kpeter@14
    40
  p = a-b;
kpeter@171
    41
  check(p.x==-2 && p.y==-2, "Wrong dim2::Point subtraction.");
alpar@8
    42
kpeter@171
    43
  check(a.normSquare()==5,"Wrong dim2::Point norm calculation.");
kpeter@171
    44
  check(a*b==11, "Wrong dim2::Point scalar product.");
alpar@8
    45
alpar@8
    46
  int l=2;
kpeter@14
    47
  p = a*l;
kpeter@171
    48
  check(p.x==2 && p.y==4, "Wrong dim2::Point multiplication by a scalar.");
alpar@8
    49
kpeter@14
    50
  p = b/l;
kpeter@171
    51
  check(p.x==1 && p.y==2, "Wrong dim2::Point division by a scalar.");
alpar@8
    52
alpar@8
    53
  typedef dim2::BoundingBox<int> BB;
kpeter@14
    54
  BB box1;
kpeter@171
    55
  check(box1.empty(), "Wrong empty() in dim2::BoundingBox.");
alpar@8
    56
kpeter@14
    57
  box1.add(a);
kpeter@171
    58
  check(!box1.empty(), "Wrong empty() in dim2::BoundingBox.");
kpeter@14
    59
  box1.add(b);
alpar@8
    60
kpeter@14
    61
  check(box1.bottomLeft().x==1 &&
kpeter@14
    62
        box1.bottomLeft().y==2 &&
kpeter@14
    63
        box1.topRight().x==3 &&
kpeter@14
    64
        box1.topRight().y==4,
kpeter@171
    65
        "Wrong addition of points to dim2::BoundingBox.");
alpar@8
    66
kpeter@14
    67
  p.x=2; p.y=3;
kpeter@171
    68
  check(box1.inside(p), "Wrong inside() in dim2::BoundingBox.");
alpar@8
    69
kpeter@14
    70
  p.x=1; p.y=3;
kpeter@171
    71
  check(box1.inside(p), "Wrong inside() in dim2::BoundingBox.");
alpar@8
    72
kpeter@14
    73
  p.x=0; p.y=3;
kpeter@171
    74
  check(!box1.inside(p), "Wrong inside() in dim2::BoundingBox.");
kpeter@14
    75
kpeter@14
    76
  BB box2(p);
kpeter@171
    77
  check(!box2.empty(), "Wrong empty() in dim2::BoundingBox.");
alpar@8
    78
kpeter@14
    79
  box2.add(box1);
kpeter@171
    80
  check(box2.inside(p), "Wrong inside() in dim2::BoundingBox.");
kpeter@14
    81
kpeter@14
    82
  return 0;
alpar@8
    83
}