iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tests/test-Clamp.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 <boost/numeric/conversion/bounds.hpp>
#include <boost/numeric/conversion/is_subranged.hpp>
#include <boost/numeric/conversion/conversion_traits.hpp>
#include <type_traits>
#include <iostream>
#include <boost/type_traits.hpp>
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE ClampTest
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(ClampTest)
{
const short int sintmin = boost::numeric::bounds<short int>::lowest();
const short int sintmax = boost::numeric::bounds<short int>::highest();
const unsigned int uintmin = boost::numeric::bounds<unsigned int>::lowest();
const unsigned int uintmax = boost::numeric::bounds<unsigned int>::highest();
const int intmin = boost::numeric::bounds<int>::lowest();
const int intmax = boost::numeric::bounds<int>::highest();
const float floatmin = boost::numeric::bounds<float>::lowest();
const float floatmax = boost::numeric::bounds<float>::highest();
const double doublemin = boost::numeric::bounds<double>::lowest();
const double doublemax = boost::numeric::bounds<double>::highest();
BOOST_CHECK_EQUAL(nrt::clamped_convert<short int>(intmin), sintmin);
BOOST_CHECK_EQUAL(nrt::clamped_convert<short int>(intmax), sintmax);
BOOST_CHECK_EQUAL(nrt::clamped_convert<int>(uintmin), uintmin);
BOOST_CHECK_EQUAL(nrt::clamped_convert<int>(uintmax), intmax);
BOOST_CHECK_EQUAL(nrt::clamped_convert<int>(uintmin), uintmin);
BOOST_CHECK_EQUAL(nrt::clamped_convert<int>(uintmax), intmax);
BOOST_CHECK_EQUAL(nrt::clamped_convert<unsigned int>(intmin), uintmin);
BOOST_CHECK_EQUAL(nrt::clamped_convert<unsigned int>(intmax), intmax);
BOOST_CHECK_EQUAL(nrt::clamped_convert<float>(uintmin), uintmin);
BOOST_CHECK_EQUAL(nrt::clamped_convert<float>(uintmax), uintmax);
BOOST_CHECK_EQUAL(nrt::clamped_convert<float>(intmin), intmin);
BOOST_CHECK_EQUAL(nrt::clamped_convert<float>(intmax), intmax);
BOOST_CHECK_EQUAL(nrt::clamped_convert<unsigned int>(floatmin), uintmin);
BOOST_CHECK_EQUAL(nrt::clamped_convert<unsigned int>(floatmax), uintmax);
BOOST_CHECK_EQUAL(nrt::clamped_convert<int>(floatmin), intmin);
BOOST_CHECK_EQUAL(nrt::clamped_convert<int>(floatmax), intmax);
BOOST_CHECK_EQUAL(nrt::clamped_convert<double>(floatmin), floatmin);
BOOST_CHECK_EQUAL(nrt::clamped_convert<double>(floatmax), floatmax);
BOOST_CHECK_EQUAL(nrt::clamped_convert<float>(doublemin), floatmin);
BOOST_CHECK_EQUAL(nrt::clamped_convert<float>(doublemax), floatmax);
BOOST_CHECK_EQUAL(nrt::clamped_convert<int>(0.9F), 1);
BOOST_CHECK_EQUAL(nrt::clamped_convert<int>(0.501F), 1);
BOOST_CHECK_EQUAL(nrt::clamped_convert<int>(0.5F), 1);
BOOST_CHECK_EQUAL(nrt::clamped_convert<int>(0.499F), 0);
BOOST_CHECK_EQUAL(nrt::clamped_convert<int>(0.1F), 0);
BOOST_CHECK_EQUAL(nrt::clamped_convert<int>(-0.9F), -1);
BOOST_CHECK_EQUAL(nrt::clamped_convert<int>(-0.5F), -1);
BOOST_CHECK_EQUAL(nrt::clamped_convert<int>(-0.1F), 0);
BOOST_CHECK_EQUAL(nrt::clamped_convert<int>(-1.0), -1);
BOOST_CHECK_EQUAL(nrt::clamped_convert<int>(-1.499), -1);
BOOST_CHECK_EQUAL(nrt::clamped_convert<int>(-1.5), -2);
BOOST_CHECK_EQUAL(nrt::clamped_convert<int>(-1.501), -2);
BOOST_CHECK_EQUAL(nrt::clamped_convert<nrt::byte>(254.6F), 255);
BOOST_CHECK_EQUAL(nrt::clamped_convert<nrt::byte>(0.1F), 0);
BOOST_CHECK_EQUAL(nrt::clamped_convert<nrt::byte>(255.1F), 255);
BOOST_CHECK_EQUAL(nrt::clamped_convert<nrt::byte>(256.0F), 255);
BOOST_CHECK_EQUAL(nrt::clamped_convert<nrt::byte>(500.0F), 255);
BOOST_CHECK_EQUAL(nrt::clamped_convert<nrt::byte>(-0.1F), 0);
BOOST_CHECK_EQUAL(nrt::clamped_convert<nrt::byte>(-0.5F), 0);
BOOST_CHECK_EQUAL(nrt::clamped_convert<nrt::byte>(-0.9F), 0);
BOOST_CHECK_EQUAL(nrt::clamped_convert<nrt::byte>(-1.0F), 0);
}