COIN-OR::LEMON - Graph Library

source: lemon-0.x/test/dim_test.cc @ 2391:14a343be7a5a

Last change on this file since 2391:14a343be7a5a was 2391:14a343be7a5a, checked in by Alpar Juttner, 17 years ago

Happy New Year to all source files!

File size: 2.1 KB
RevLine 
[906]1/* -*- C++ -*-
2 *
[1956]3 * This file is a part of LEMON, a generic C++ optimization library
4 *
[2391]5 * Copyright (C) 2003-2007
[1956]6 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
[1359]7 * (Egervary Research Group on Combinatorial Optimization, EGRES).
[906]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
[2207]19#include <lemon/dim2.h>
[201]20#include <iostream>
[727]21#include "test_tools.h"
22
[201]23using namespace std;
[921]24using namespace lemon;
[201]25int main()
26{
[207]27
[2207]28  cout << "Testing classes `dim2::Point' and `dim2::BoundingBox'." << endl;
[201]29
[2207]30  typedef dim2::Point<int> Point;
[513]31       
[2212]32  Point seged;
33  check(seged.size()==2, "Wrong vector addition");
[201]34
[2212]35  Point a(1,2);
36  Point b(3,4);
[201]37
[2212]38  check(a[0]==1 && a[1]==2, "Wrong vector addition");
[513]39
[2212]40  seged = a+b;
41  check(seged.x==4 && seged.y==6, "Wrong vector addition");
[513]42
[2212]43  seged = a-b;
44  check(seged.x==-2 && seged.y==-2, "a-b");
[513]45
[2212]46  check(a.normSquare()==5,"Wrong norm calculation");
47  check(a*b==11, "a*b");
[513]48
[2212]49  int l=2;
50  seged = a*l;
51  check(seged.x==2 && seged.y==4, "a*l");
52
53  seged = b/l;
54  check(seged.x==1 && seged.y==2, "b/l");
55
56  typedef dim2::BoundingBox<int> BB;
57  BB doboz1;
58  check(doboz1.empty(), "It should be empty.");
[516]59       
[2212]60  doboz1.add(a);
61  check(!doboz1.empty(), "It should not be empty.");
62  doboz1.add(b);
[513]63
[2212]64  check(doboz1.bottomLeft().x==1 &&
65        doboz1.bottomLeft().y==2 &&
66        doboz1.topRight().x==3 &&
67        doboz1.topRight().y==4, 
68        "added points to box");
[516]69
[2212]70  seged.x=2;seged.y=3;
71  check(doboz1.inside(seged),"It should be inside.");
[516]72
[2212]73  seged.x=1;seged.y=3;
74  check(doboz1.inside(seged),"It should be inside.");
[516]75
[2212]76  seged.x=0;seged.y=3;
77  check(!doboz1.inside(seged),"It should not be inside.");
[516]78
[2212]79  BB doboz2(seged);
80  check(!doboz2.empty(),
81        "It should not be empty. Constructed from 1 point.");
[516]82
[2212]83  doboz2.add(doboz1);
84  check(doboz2.inside(seged),
85        "It should be inside. Incremented a box with another one.");
[201]86}
Note: See TracBrowser for help on using the repository browser.