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