ladanyi@542: #include athos@201: #include athos@201: using namespace std; athos@207: using namespace hugo; athos@513: athos@513: bool passed = true; athos@513: athos@516: void check(bool rc, char *msg="") { athos@513: passed = passed && rc; athos@513: if(!rc) { athos@516: std::cerr << "Test failed! ("<< msg << ")" << std::endl; \ athos@516: athos@516: athos@513: } athos@513: } athos@513: athos@513: athos@513: athos@201: int main() athos@201: { athos@207: athos@518: cout << "Testing classes xy and boundingbox." << endl; athos@201: athos@513: typedef xy XY; athos@513: athos@513: XY seged; athos@513: XY a(1,2); athos@513: XY b(3,4); athos@201: athos@513: seged = a+b; athos@513: check(seged.x==4 && seged.y==6); athos@201: athos@513: seged = a-b; athos@516: check(seged.x==-2 && seged.y==-2, "a-b"); athos@513: athos@513: check(a.normSquare()==5); athos@516: check(a*b==11, "a*b"); athos@513: athos@513: int l=2; athos@513: seged = a*l; athos@516: check(seged.x==2 && seged.y==4, "a*l"); athos@513: athos@513: seged = b/l; athos@516: check(seged.x==1 && seged.y==2, "b/l"); athos@513: athos@513: typedef BoundingBox BB; athos@513: BB doboz1; athos@516: check(doboz1.empty(), "empty? Should be."); athos@516: athos@513: doboz1 += a; athos@516: check(!doboz1.empty(), "empty? Should not be."); athos@513: doboz1 += b; athos@513: athos@516: check(doboz1.bottomLeft().x==1 && athos@516: doboz1.bottomLeft().y==2 && athos@516: doboz1.topRight().x==3 && athos@516: doboz1.topRight().y==4, athos@516: "added points to box"); athos@516: athos@516: seged.x=2;seged.y=3; athos@516: check(doboz1.inside(seged),"Inside? Should be."); athos@516: athos@516: seged.x=1;seged.y=3; athos@516: check(doboz1.inside(seged),"Inside? Should be."); athos@516: athos@516: seged.x=0;seged.y=3; athos@516: check(!doboz1.inside(seged),"Inside? Should not be."); athos@516: athos@516: BB doboz2(seged); athos@517: check(!doboz2.empty(), "empty? Should not be. Constructed from 1 point."); athos@516: athos@516: doboz2 += doboz1; athos@517: check(doboz2.inside(seged),"Inside? Should be. Incremented a box with an other."); athos@516: athos@513: cout << (passed ? "All tests passed." : "Some of the tests failed!!!") athos@513: << endl; athos@513: athos@513: return passed ? 0 : 1; athos@513: athos@201: }