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 #ifndef BOOST_GIL_TEST_CORE_TEST_FIXTURE_HPP 9 #define BOOST_GIL_TEST_CORE_TEST_FIXTURE_HPP 10 11 #include <boost/gil/promote_integral.hpp> 12 #include <boost/assert.hpp> 13 14 #include <cstdint> 15 #include <initializer_list> 16 #include <limits> 17 #include <random> 18 #include <tuple> 19 #include <type_traits> 20 21 namespace boost { namespace gil { namespace test { namespace fixture { 22 23 template <typename T> 24 struct consecutive_value 25 { consecutive_valueboost::gil::test::fixture::consecutive_value26 consecutive_value(T start) : current_(start) 27 { 28 BOOST_ASSERT(static_cast<int>(current_) >= 0); 29 } 30 operator ()boost::gil::test::fixture::consecutive_value31 T operator()() 32 { 33 BOOST_ASSERT(static_cast<int>(current_) + 1 > 0); 34 current_++; 35 return current_; 36 } 37 38 T current_; 39 }; 40 41 template <typename T> 42 struct reverse_consecutive_value 43 { reverse_consecutive_valueboost::gil::test::fixture::reverse_consecutive_value44 reverse_consecutive_value(T start) : current_(start) 45 { 46 BOOST_ASSERT(static_cast<int>(current_) > 0); 47 } 48 operator ()boost::gil::test::fixture::reverse_consecutive_value49 T operator()() 50 { 51 BOOST_ASSERT(static_cast<int>(current_) + 1 >= 0); 52 current_--; 53 return current_; 54 } 55 56 T current_; 57 }; 58 59 template <typename T> 60 struct random_value 61 { 62 static_assert(std::is_integral<T>::value, "T must be integral type"); 63 static constexpr auto range_min = std::numeric_limits<T>::min(); 64 static constexpr auto range_max = std::numeric_limits<T>::max(); 65 random_valueboost::gil::test::fixture::random_value66 random_value() : rng_(rd_()), uid_(range_min, range_max) {} 67 operator ()boost::gil::test::fixture::random_value68 T operator()() 69 { 70 auto value = uid_(rng_); 71 BOOST_ASSERT(range_min <= value && value <= range_max); 72 return static_cast<T>(value); 73 } 74 75 std::random_device rd_; 76 std::mt19937 rng_; 77 std::uniform_int_distribution<typename gil::promote_integral<T>::type> uid_; 78 }; 79 80 }}}} // namespace boost::gil::test::fixture 81 82 #endif 83