src/test/xy_test.cc
author alpar
Mon, 19 Jul 2004 13:31:47 +0000
changeset 708 429dfcbbf47d
parent 518 fcdb561b8c78
child 727 aada518af30f
permissions -rw-r--r--
A new benchmark (hcube)
and other minor changes
ladanyi@542
     1
#include <hugo/xy.h>
athos@201
     2
#include <iostream>
athos@201
     3
using namespace std;
athos@207
     4
using namespace hugo;
athos@513
     5
athos@513
     6
bool passed = true;
athos@513
     7
athos@516
     8
void check(bool rc, char *msg="") {
athos@513
     9
  passed = passed && rc;
athos@513
    10
  if(!rc) {
athos@516
    11
    std::cerr << "Test failed! ("<< msg << ")" << std::endl; \
athos@516
    12
 
athos@516
    13
athos@513
    14
  }
athos@513
    15
}
athos@513
    16
athos@513
    17
athos@513
    18
athos@201
    19
int main()
athos@201
    20
{
athos@207
    21
athos@518
    22
  cout << "Testing classes xy and boundingbox." << endl;
athos@201
    23
athos@513
    24
	typedef xy<int> XY;
athos@513
    25
	
athos@513
    26
	XY seged;
athos@513
    27
	XY a(1,2);
athos@513
    28
	XY b(3,4);
athos@201
    29
athos@513
    30
	seged = a+b;
athos@513
    31
	check(seged.x==4 && seged.y==6);
athos@201
    32
athos@513
    33
	seged = a-b;
athos@516
    34
	check(seged.x==-2 && seged.y==-2, "a-b");
athos@513
    35
athos@513
    36
	check(a.normSquare()==5);
athos@516
    37
	check(a*b==11, "a*b");
athos@513
    38
athos@513
    39
	int l=2;
athos@513
    40
	seged = a*l;
athos@516
    41
	check(seged.x==2 && seged.y==4, "a*l");
athos@513
    42
athos@513
    43
	seged = b/l;
athos@516
    44
	check(seged.x==1 && seged.y==2, "b/l");
athos@513
    45
athos@513
    46
	typedef BoundingBox<int> BB;
athos@513
    47
	BB doboz1;
athos@516
    48
	check(doboz1.empty(), "empty? Should be.");
athos@516
    49
	
athos@513
    50
	doboz1 += a;
athos@516
    51
	check(!doboz1.empty(), "empty? Should not be.");
athos@513
    52
	doboz1 += b;
athos@513
    53
athos@516
    54
	check(doboz1.bottomLeft().x==1 && 
athos@516
    55
	      doboz1.bottomLeft().y==2 &&
athos@516
    56
	      doboz1.topRight().x==3 && 
athos@516
    57
	      doboz1.topRight().y==4,  
athos@516
    58
	      "added points to box");
athos@516
    59
athos@516
    60
	seged.x=2;seged.y=3;
athos@516
    61
	check(doboz1.inside(seged),"Inside? Should be.");
athos@516
    62
athos@516
    63
	seged.x=1;seged.y=3;
athos@516
    64
	check(doboz1.inside(seged),"Inside? Should be.");
athos@516
    65
athos@516
    66
	seged.x=0;seged.y=3;
athos@516
    67
	check(!doboz1.inside(seged),"Inside? Should not be.");
athos@516
    68
athos@516
    69
	BB doboz2(seged);
athos@517
    70
	check(!doboz2.empty(), "empty? Should not be. Constructed from 1 point.");
athos@516
    71
athos@516
    72
	doboz2 += doboz1;
athos@517
    73
	check(doboz2.inside(seged),"Inside? Should be. Incremented a box with an other.");
athos@516
    74
athos@513
    75
	cout << (passed ? "All tests passed." : "Some of the tests failed!!!")
athos@513
    76
	     << endl;
athos@513
    77
athos@513
    78
	return passed ? 0 : 1;
athos@513
    79
athos@201
    80
}