alpar@8: /* -*- C++ -*- alpar@8: * alpar@8: * This file is a part of LEMON, a generic C++ optimization library alpar@8: * alpar@39: * Copyright (C) 2003-2008 alpar@8: * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport alpar@8: * (Egervary Research Group on Combinatorial Optimization, EGRES). alpar@8: * alpar@8: * Permission to use, modify and distribute this software is granted alpar@8: * provided that this copyright notice appears in all copies. For alpar@8: * precise terms see the accompanying LICENSE file. alpar@8: * alpar@8: * This software is provided "AS IS" with no warranty of any kind, alpar@8: * express or implied, and with no claim as to its suitability for any alpar@8: * purpose. alpar@8: * alpar@8: */ alpar@8: alpar@8: #include alpar@8: #include alpar@8: #include "test_tools.h" alpar@8: alpar@8: using namespace std; alpar@8: using namespace lemon; kpeter@14: alpar@8: int main() alpar@8: { kpeter@14: cout << "Testing classes 'dim2::Point' and 'dim2::BoundingBox'." << endl; alpar@8: alpar@8: typedef dim2::Point Point; kpeter@14: kpeter@14: Point p; kpeter@14: check(p.size()==2, "Wrong vector initialization."); alpar@8: alpar@8: Point a(1,2); alpar@8: Point b(3,4); kpeter@14: check(a[0]==1 && a[1]==2, "Wrong vector initialization."); alpar@8: kpeter@14: p = a+b; kpeter@14: check(p.x==4 && p.y==6, "Wrong vector addition."); alpar@8: kpeter@14: p = a-b; kpeter@14: check(p.x==-2 && p.y==-2, "Wrong vector subtraction."); alpar@8: kpeter@14: check(a.normSquare()==5,"Wrong vector norm calculation."); kpeter@14: check(a*b==11, "Wrong vector scalar product."); alpar@8: alpar@8: int l=2; kpeter@14: p = a*l; kpeter@14: check(p.x==2 && p.y==4, "Wrong vector multiplication by a scalar."); alpar@8: kpeter@14: p = b/l; kpeter@14: check(p.x==1 && p.y==2, "Wrong vector division by a scalar."); alpar@8: alpar@8: typedef dim2::BoundingBox BB; kpeter@14: BB box1; kpeter@14: check(box1.empty(), "It should be empty."); alpar@8: kpeter@14: box1.add(a); kpeter@14: check(!box1.empty(), "It should not be empty."); kpeter@14: box1.add(b); alpar@8: kpeter@14: check(box1.bottomLeft().x==1 && kpeter@14: box1.bottomLeft().y==2 && kpeter@14: box1.topRight().x==3 && kpeter@14: box1.topRight().y==4, kpeter@14: "Wrong addition of points to box."); alpar@8: kpeter@14: p.x=2; p.y=3; kpeter@14: check(box1.inside(p), "It should be inside."); alpar@8: kpeter@14: p.x=1; p.y=3; kpeter@14: check(box1.inside(p), "It should be inside."); alpar@8: kpeter@14: p.x=0; p.y=3; kpeter@14: check(!box1.inside(p), "It should not be inside."); kpeter@14: kpeter@14: BB box2(p); kpeter@14: check(!box2.empty(), alpar@8: "It should not be empty. Constructed from 1 point."); alpar@8: kpeter@14: box2.add(box1); kpeter@14: check(box2.inside(p), alpar@8: "It should be inside. Incremented a box with another one."); kpeter@14: kpeter@14: return 0; alpar@8: }