COIN-OR::LEMON - Graph Library

source: lemon-1.0/test/dim_test.cc @ 54:ff9bac2351bf

Last change on this file since 54:ff9bac2351bf was 39:0a01d811071f, checked in by Alpar Juttner <alpar@…>, 17 years ago

Happy New Year (update the copyright headers)

File size: 2.1 KB
RevLine 
[8]1/* -*- C++ -*-
2 *
3 * This file is a part of LEMON, a generic C++ optimization library
4 *
[39]5 * Copyright (C) 2003-2008
[8]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;
[14]25
[8]26int main()
27{
[14]28  cout << "Testing classes 'dim2::Point' and 'dim2::BoundingBox'." << endl;
[8]29
30  typedef dim2::Point<int> Point;
[14]31
32  Point p;
33  check(p.size()==2, "Wrong vector initialization.");
[8]34
35  Point a(1,2);
36  Point b(3,4);
[14]37  check(a[0]==1 && a[1]==2, "Wrong vector initialization.");
[8]38
[14]39  p = a+b;
40  check(p.x==4 && p.y==6, "Wrong vector addition.");
[8]41
[14]42  p = a-b;
43  check(p.x==-2 && p.y==-2, "Wrong vector subtraction.");
[8]44
[14]45  check(a.normSquare()==5,"Wrong vector norm calculation.");
46  check(a*b==11, "Wrong vector scalar product.");
[8]47
48  int l=2;
[14]49  p = a*l;
50  check(p.x==2 && p.y==4, "Wrong vector multiplication by a scalar.");
[8]51
[14]52  p = b/l;
53  check(p.x==1 && p.y==2, "Wrong vector division by a scalar.");
[8]54
55  typedef dim2::BoundingBox<int> BB;
[14]56  BB box1;
57  check(box1.empty(), "It should be empty.");
[8]58
[14]59  box1.add(a);
60  check(!box1.empty(), "It should not be empty.");
61  box1.add(b);
[8]62
[14]63  check(box1.bottomLeft().x==1 &&
64        box1.bottomLeft().y==2 &&
65        box1.topRight().x==3 &&
66        box1.topRight().y==4,
67        "Wrong addition of points to box.");
[8]68
[14]69  p.x=2; p.y=3;
70  check(box1.inside(p), "It should be inside.");
[8]71
[14]72  p.x=1; p.y=3;
73  check(box1.inside(p), "It should be inside.");
[8]74
[14]75  p.x=0; p.y=3;
76  check(!box1.inside(p), "It should not be inside.");
77
78  BB box2(p);
79  check(!box2.empty(),
[8]80        "It should not be empty. Constructed from 1 point.");
81
[14]82  box2.add(box1);
83  check(box2.inside(p),
[8]84        "It should be inside. Incremented a box with another one.");
[14]85
86  return 0;
[8]87}
Note: See TracBrowser for help on using the repository browser.