alpar@209: /* -*- mode: C++; indent-tabs-mode: nil; -*- alpar@8: * alpar@209: * 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: { alpar@8: typedef dim2::Point Point; kpeter@14: kpeter@14: Point p; kpeter@171: check(p.size()==2, "Wrong dim2::Point initialization."); alpar@8: alpar@8: Point a(1,2); alpar@8: Point b(3,4); kpeter@171: check(a[0]==1 && a[1]==2, "Wrong dim2::Point initialization."); alpar@8: kpeter@14: p = a+b; kpeter@171: check(p.x==4 && p.y==6, "Wrong dim2::Point addition."); alpar@8: kpeter@14: p = a-b; kpeter@171: check(p.x==-2 && p.y==-2, "Wrong dim2::Point subtraction."); alpar@8: kpeter@171: check(a.normSquare()==5,"Wrong dim2::Point norm calculation."); kpeter@171: check(a*b==11, "Wrong dim2::Point scalar product."); alpar@8: alpar@8: int l=2; kpeter@14: p = a*l; kpeter@171: check(p.x==2 && p.y==4, "Wrong dim2::Point multiplication by a scalar."); alpar@8: kpeter@14: p = b/l; kpeter@171: check(p.x==1 && p.y==2, "Wrong dim2::Point division by a scalar."); alpar@8: kpeter@253: typedef dim2::Box Box; kpeter@253: Box box1; kpeter@253: check(box1.empty(), "Wrong empty() in dim2::Box."); alpar@8: kpeter@14: box1.add(a); kpeter@253: check(!box1.empty(), "Wrong empty() in dim2::Box."); kpeter@14: box1.add(b); alpar@8: kpeter@242: check(box1.left()==1 && box1.bottom()==2 && kpeter@242: box1.right()==3 && box1.top()==4, kpeter@253: "Wrong addition of points to dim2::Box."); alpar@8: kpeter@253: check(box1.inside(Point(2,3)), "Wrong inside() in dim2::Box."); kpeter@253: check(box1.inside(Point(1,3)), "Wrong inside() in dim2::Box."); kpeter@253: check(!box1.inside(Point(0,3)), "Wrong inside() in dim2::Box."); alpar@8: kpeter@253: Box box2(Point(2,2)); kpeter@253: check(!box2.empty(), "Wrong empty() in dim2::Box."); kpeter@253: kpeter@242: box2.bottomLeft(Point(2,0)); kpeter@242: box2.topRight(Point(5,3)); kpeter@253: Box box3 = box1 & box2; kpeter@242: check(!box3.empty() && kpeter@253: box3.left()==2 && box3.bottom()==2 && kpeter@242: box3.right()==3 && box3.top()==3, kpeter@253: "Wrong intersection of two dim2::Box objects."); kpeter@253: kpeter@242: box1.add(box2); kpeter@242: check(!box1.empty() && kpeter@242: box1.left()==1 && box1.bottom()==0 && kpeter@242: box1.right()==5 && box1.top()==4, kpeter@253: "Wrong addition of two dim2::Box objects."); kpeter@14: kpeter@14: return 0; alpar@8: }