test_fixture.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // Copyright 2019 Mateusz Loskot <mateusz at loskot dot net>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. #include <boost/config.hpp>
  9. #include <boost/core/ignore_unused.hpp>
  10. #if defined(BOOST_CLANG)
  11. #pragma clang diagnostic push
  12. #pragma clang diagnostic ignored "-Wconversion"
  13. #pragma clang diagnostic ignored "-Wfloat-equal"
  14. #pragma clang diagnostic ignored "-Wsign-conversion"
  15. #elif BOOST_GCC >= 40700
  16. #pragma GCC diagnostic push
  17. #pragma GCC diagnostic ignored "-Wconversion"
  18. #pragma GCC diagnostic ignored "-Wfloat-equal"
  19. #pragma GCC diagnostic ignored "-Wsign-conversion"
  20. #endif
  21. #include <boost/gil.hpp>
  22. #include <algorithm>
  23. #include <cstdint>
  24. #include <vector>
  25. #define BOOST_TEST_MODULE test_ext_numeric_test_fixture
  26. #include "unit_test.hpp"
  27. #include "test_fixture.hpp"
  28. namespace gil = boost::gil;
  29. namespace fixture = boost::gil::test::fixture;
  30. BOOST_AUTO_TEST_CASE(consecutive_value)
  31. {
  32. fixture::consecutive_value<std::uint8_t> v(10);
  33. BOOST_TEST(v() = std::uint8_t{11});
  34. BOOST_TEST(v() = std::uint8_t{12});
  35. BOOST_TEST(v() = std::uint8_t{13});
  36. }
  37. BOOST_AUTO_TEST_CASE(reverse_consecutive_value)
  38. {
  39. fixture::reverse_consecutive_value<std::uint8_t> v(10);
  40. BOOST_TEST(v() = std::uint8_t{9});
  41. BOOST_TEST(v() = std::uint8_t{8});
  42. BOOST_TEST(v() = std::uint8_t{7});
  43. }
  44. BOOST_AUTO_TEST_CASE(random_value)
  45. {
  46. // Generate N pseudo-random values
  47. fixture::random_value<std::uint8_t> random;
  48. std::vector<std::uint8_t> v(10, 0);
  49. for (auto& i : v) i = random();
  50. // Require not all of N values are equal (duplicates are possible!)
  51. std::sort(v.begin(), v.end());
  52. auto last = std::unique(v.begin(), v.end());
  53. v.erase(last, v.end());
  54. BOOST_TEST(v.size() > 0);
  55. BOOST_TEST(v.size() <= 10);
  56. }