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 #if defined(BOOST_CLANG)
9 #pragma clang diagnostic push
10 #pragma clang diagnostic ignored "-Wconversion"
11 #pragma clang diagnostic ignored "-Wfloat-equal"
12 #pragma clang diagnostic ignored "-Wsign-conversion"
13 #elif BOOST_GCC >= 40700
14 #pragma GCC diagnostic push
15 #pragma GCC diagnostic ignored "-Wconversion"
16 #pragma GCC diagnostic ignored "-Wfloat-equal"
17 #pragma GCC diagnostic ignored "-Wsign-conversion"
18 #endif
19
20 #include <boost/gil.hpp>
21
22 #include <boost/core/lightweight_test.hpp>
23
24 #include <algorithm>
25 #include <cstdint>
26 #include <vector>
27
28 #include "test_fixture.hpp"
29
30 namespace gil = boost::gil;
31 namespace fixture = boost::gil::test::fixture;
32
test_consecutive_value()33 void test_consecutive_value()
34 {
35 fixture::consecutive_value<std::uint8_t> v(10);
36 BOOST_TEST_EQ(v(), std::uint8_t{11});
37 BOOST_TEST_EQ(v(), std::uint8_t{12});
38 BOOST_TEST_EQ(v(), std::uint8_t{13});
39 }
40
test_reverse_consecutive_value()41 void test_reverse_consecutive_value()
42 {
43 fixture::reverse_consecutive_value<std::uint8_t> v(10);
44 BOOST_TEST_EQ(v(), std::uint8_t{9});
45 BOOST_TEST_EQ(v(), std::uint8_t{8});
46 BOOST_TEST_EQ(v(), std::uint8_t{7});
47 }
48
test_random_value()49 void test_random_value()
50 {
51 // Generate N pseudo-random values
52 fixture::random_value<std::uint8_t> random;
53 std::vector<std::uint8_t> v(10, 0);
54 for (auto& i : v) i = random();
55
56 // Require not all of N values are equal (duplicates are possible!)
57 std::sort(v.begin(), v.end());
58 auto last = std::unique(v.begin(), v.end());
59 v.erase(last, v.end());
60 BOOST_TEST_GT(v.size(), 0);
61 BOOST_TEST_LE(v.size(), 10);
62 }
63
main()64 int main()
65 {
66 test_consecutive_value();
67 test_reverse_consecutive_value();
68 test_random_value();
69
70 return boost::report_errors();
71 }
72