Testcasts.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * NICE-Core - efficient algebra and computer vision methods
  3. * - libfbasics - An core/basics/template for new NICE libraries
  4. * See file License for license information.
  5. */
  6. #ifdef NICE_USELIB_CPPUNIT
  7. #include "Testcasts.h"
  8. #include <string>
  9. #include <exception>
  10. #include <core/basics/types.h>
  11. using namespace NICE;
  12. CPPUNIT_TEST_SUITE_REGISTRATION( Testcasts );
  13. void Testcasts::setUp() {
  14. }
  15. void Testcasts::tearDown() {
  16. }
  17. void Testcasts::testConstructor() {
  18. }
  19. void Testcasts::testCasts() {
  20. {
  21. float x=1.56;
  22. float y=1.34;
  23. CPPUNIT_ASSERT_EQUAL(2, round_to_nearest_cast<int>(x));
  24. CPPUNIT_ASSERT_EQUAL(1, round_to_nearest_cast<int>(y));
  25. CPPUNIT_ASSERT_EQUAL(-2, round_to_nearest_cast<int>(-x));
  26. CPPUNIT_ASSERT_EQUAL(-1, round_to_nearest_cast<int>(-y));
  27. }
  28. {
  29. double x=1.56;
  30. double y=1.34;
  31. CPPUNIT_ASSERT_EQUAL(static_cast<unsigned char>(2), round_to_nearest_cast<unsigned char>(x));
  32. CPPUNIT_ASSERT_EQUAL(static_cast<char>(1), round_to_nearest_cast<char>(y));
  33. CPPUNIT_ASSERT_EQUAL(static_cast<char>(-2), round_to_nearest_cast<char>(-x));
  34. CPPUNIT_ASSERT_EQUAL(static_cast<char>(-1), round_to_nearest_cast<char>(-y));
  35. }
  36. {
  37. float x=1.56;
  38. float y=1.34;
  39. CPPUNIT_ASSERT_EQUAL(2l, round_to_nearest_cast<long>(x));
  40. CPPUNIT_ASSERT_EQUAL(1ul, round_to_nearest_cast<unsigned long>(y));
  41. CPPUNIT_ASSERT_EQUAL(-2l, round_to_nearest_cast<long>(-x));
  42. CPPUNIT_ASSERT_EQUAL(-1l, round_to_nearest_cast<long>(-y));
  43. }
  44. }
  45. #endif