COIN-OR::LEMON - Graph Library

source: lemon-main/test/dim_test.cc @ 232:e39056157d24

Last change on this file since 232:e39056157d24 was 209:765619b7cbb2, checked in by Alpar Juttner <alpar@…>, 16 years ago

Apply unify-sources.sh to the source tree

File size: 2.2 KB
Line 
1/* -*- mode: C++; indent-tabs-mode: nil; -*-
2 *
3 * This file is a part of LEMON, a generic C++ optimization library.
4 *
5 * Copyright (C) 2003-2008
6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
8 *
9 * Permission to use, modify and distribute this software is granted
10 * provided that this copyright notice appears in all copies. For
11 * precise terms see the accompanying LICENSE file.
12 *
13 * This software is provided "AS IS" with no warranty of any kind,
14 * express or implied, and with no claim as to its suitability for any
15 * purpose.
16 *
17 */
18
19#include <lemon/dim2.h>
20#include <iostream>
21#include "test_tools.h"
22
23using namespace std;
24using namespace lemon;
25
26int main()
27{
28  typedef dim2::Point<int> Point;
29
30  Point p;
31  check(p.size()==2, "Wrong dim2::Point initialization.");
32
33  Point a(1,2);
34  Point b(3,4);
35  check(a[0]==1 && a[1]==2, "Wrong dim2::Point initialization.");
36
37  p = a+b;
38  check(p.x==4 && p.y==6, "Wrong dim2::Point addition.");
39
40  p = a-b;
41  check(p.x==-2 && p.y==-2, "Wrong dim2::Point subtraction.");
42
43  check(a.normSquare()==5,"Wrong dim2::Point norm calculation.");
44  check(a*b==11, "Wrong dim2::Point scalar product.");
45
46  int l=2;
47  p = a*l;
48  check(p.x==2 && p.y==4, "Wrong dim2::Point multiplication by a scalar.");
49
50  p = b/l;
51  check(p.x==1 && p.y==2, "Wrong dim2::Point division by a scalar.");
52
53  typedef dim2::BoundingBox<int> BB;
54  BB box1;
55  check(box1.empty(), "Wrong empty() in dim2::BoundingBox.");
56
57  box1.add(a);
58  check(!box1.empty(), "Wrong empty() in dim2::BoundingBox.");
59  box1.add(b);
60
61  check(box1.bottomLeft().x==1 &&
62        box1.bottomLeft().y==2 &&
63        box1.topRight().x==3 &&
64        box1.topRight().y==4,
65        "Wrong addition of points to dim2::BoundingBox.");
66
67  p.x=2; p.y=3;
68  check(box1.inside(p), "Wrong inside() in dim2::BoundingBox.");
69
70  p.x=1; p.y=3;
71  check(box1.inside(p), "Wrong inside() in dim2::BoundingBox.");
72
73  p.x=0; p.y=3;
74  check(!box1.inside(p), "Wrong inside() in dim2::BoundingBox.");
75
76  BB box2(p);
77  check(!box2.empty(), "Wrong empty() in dim2::BoundingBox.");
78
79  box2.add(box1);
80  check(box2.inside(p), "Wrong inside() in dim2::BoundingBox.");
81
82  return 0;
83}
Note: See TracBrowser for help on using the repository browser.