iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tests/test-Point.C
/*! @file
@author Unknown
@copyright GNU Public License (GPL v3)
@section License
@verbatim
// ////////////////////////////////////////////////////////////////////////
// The iLab Neuromorphic Robotics Toolkit (NRT) //
// Copyright 2010-2012 by the University of Southern California (USC) //
// and the iLab at USC. //
// //
// iLab - University of Southern California //
// Hedco Neurociences Building, Room HNB-10 //
// Los Angeles, Ca 90089-2520 - USA //
// //
// See http://ilab.usc.edu for information about this project. //
// ////////////////////////////////////////////////////////////////////////
// This file is part of The iLab Neuromorphic Robotics Toolkit. //
// //
// The iLab Neuromorphic Robotics Toolkit is free software: you can //
// redistribute it and/or modify it under the terms of the GNU General //
// Public License as published by the Free Software Foundation, either //
// version 3 of the License, or (at your option) any later version. //
// //
// The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
// that it will be useful, but WITHOUT ANY WARRANTY; without even the //
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
// PURPOSE. See the GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with The iLab Neuromorphic Robotics Toolkit. If not, see //
// <http://www.gnu.org/licenses/>. //
// ////////////////////////////////////////////////////////////////////////
@endverbatim */
#include <nrt/config.h>
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE PointTest
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(PointTest)
{
// *** test int-based binary-operator arithmetic
nrt::Point2D<int> x(100, 199);
BOOST_CHECK_EQUAL(x+y, nrt::Point2D<int>(102, 203));
BOOST_CHECK_EQUAL(x-y, nrt::Point2D<int>(98, 195));
BOOST_CHECK_EQUAL(x*2, nrt::Point2D<int>(200, 398));
BOOST_CHECK_EQUAL(2*x, nrt::Point2D<int>(200, 398));
BOOST_CHECK_EQUAL(x/2, nrt::Point2D<int>(50, 100));
// *** test int-based unary operators
a = x; a += y; BOOST_CHECK_EQUAL(a, nrt::Point2D<int>(102, 203));
a = x; a -= y; BOOST_CHECK_EQUAL(a, nrt::Point2D<int>(98, 195));
a = x; a *= 2; BOOST_CHECK_EQUAL(a, nrt::Point2D<int>(200, 398));
a = x; a /= 2; BOOST_CHECK_EQUAL(a, nrt::Point2D<int>(50, 100));
// *** test conversion and clamping/rounding:
nrt::Point2D<float> pfl(12.34F, 567.89F);
nrt::Point2D<int> pin(pfl); BOOST_CHECK_EQUAL(pin, nrt::Point2D<int>(12, 568)); // rounded
nrt::Point2D<nrt::byte> pby(pfl); BOOST_CHECK_EQUAL(pby, nrt::Point2D<nrt::byte>(12, 255)); // rounded + clamped
nrt::Point2D<double> pdo(pfl); BOOST_CHECK_EQUAL(pdo, nrt::Point2D<double>(12.34F, 567.89F)); // no round or clamp
nrt::Point2D<double> pdo2(-12.34, -567.89);
nrt::Point2D<int> pin2(pdo2); BOOST_CHECK_EQUAL(pin2, nrt::Point2D<int>(-12, -568)); // rounded
nrt::Point2D<nrt::byte> pby2(pdo2); BOOST_CHECK_EQUAL(pby2, nrt::Point2D<nrt::byte>(0, 0)); // rounded + clamped
nrt::Point2D<float> pfl2(pdo2); BOOST_CHECK_EQUAL(pfl2, nrt::Point2D<float>(-12.34F, -567.89F)); // no round,clamp
}