• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2019 Mateusz Loskot <mateusz at loskot dot net>
3 // Copyright 2019 Miral Shah <miralshah2211@gmail.com>
4 //
5 // Distributed under the Boost Software License, Version 1.0
6 // See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt
8 //
9 #define BOOST_DISABLE_ASSERTS 1 // kernel_1d_adaptor assertions are too strict
10 #include <boost/gil.hpp>
11 #include <boost/gil/extension/numeric/kernel.hpp>
12 
13 #include <boost/core/lightweight_test.hpp>
14 
15 #include <vector>
16 
17 namespace gil = boost::gil;
18 
test_kernel_1d_fixed_default_constructor()19 void test_kernel_1d_fixed_default_constructor()
20 {
21     gil::kernel_1d_fixed<int, 9> k;
22     BOOST_TEST_EQ(k.center(), 0);
23     BOOST_TEST_EQ(k.left_size(), 0);
24     BOOST_TEST_EQ(k.right_size(), 8); // TODO: Why not 0 or -1 if not set?
25     // std::array interface
26     BOOST_TEST_EQ(k.size(), 9);
27 }
28 
test_kernel_2d_fixed_default_constructor()29 void test_kernel_2d_fixed_default_constructor()
30 {
31     gil::detail::kernel_2d_fixed<int, 9> k;
32     BOOST_TEST_EQ(k.center_x(), 0);
33     BOOST_TEST_EQ(k.center_y(), 0);
34     BOOST_TEST_EQ(k.left_size(), 0);
35     BOOST_TEST_EQ(k.right_size(), 8); // TODO: Why not 0 or -1 if not set?
36     BOOST_TEST_EQ(k.upper_size(), 0);
37     BOOST_TEST_EQ(k.lower_size(), 8);
38     // std::array interface
39     BOOST_TEST_EQ(k.size(), 9);
40 }
41 
test_kernel_1d_fixed_parameterized_constructor()42 void test_kernel_1d_fixed_parameterized_constructor()
43 {
44     gil::kernel_1d_fixed<int, 9> k(4);
45     BOOST_TEST_EQ(k.center(), 4);
46     BOOST_TEST_EQ(k.left_size(), 4);
47     BOOST_TEST_EQ(k.right_size(), 4);
48     // std::vector interface
49     BOOST_TEST_EQ(k.size(), 9);
50 }
51 
test_kernel_2d_fixed_parameterized_constructor()52 void test_kernel_2d_fixed_parameterized_constructor()
53 {
54     gil::detail::kernel_2d_fixed<int, 9> k(4, 4);
55     BOOST_TEST_EQ(k.center_x(), 4);
56     BOOST_TEST_EQ(k.center_y(), 4);
57     BOOST_TEST_EQ(k.left_size(), 4);
58     BOOST_TEST_EQ(k.right_size(), 4);
59     BOOST_TEST_EQ(k.upper_size(), 4);
60     BOOST_TEST_EQ(k.lower_size(), 4);
61     // std::vector interface
62     BOOST_TEST_EQ(k.size(), 9);
63 }
64 
test_kernel_1d_fixed_parameterized_constructor_with_iterator()65 void test_kernel_1d_fixed_parameterized_constructor_with_iterator()
66 {
67     // FIXME: The constructor should throw if v.size() < k.size()
68     std::vector<int> v(9);
69     gil::kernel_1d_fixed<int, 9> k(v.cbegin(), 4);
70     BOOST_TEST_EQ((gil::kernel_1d_fixed<int, 9>::static_size), 9);
71     BOOST_TEST_EQ(k.center(), 4);
72     BOOST_TEST_EQ(k.left_size(), 4);
73     BOOST_TEST_EQ(k.right_size(), 4);
74     // std::vector interface
75     BOOST_TEST_EQ(k.size(), 9);
76 }
77 
test_kernel_2d_fixed_parameterized_constructor_with_iterator()78 void test_kernel_2d_fixed_parameterized_constructor_with_iterator()
79 {
80 //    // FIXME: The constructor should throw if v.size() < k.size()
81     std::array<int, 81> v;
82     gil::detail::kernel_2d_fixed<int, 9> k(v.cbegin(), 4, 4);
83     BOOST_TEST_EQ((gil::detail::kernel_2d_fixed<int, 9>::static_size), 9);
84     BOOST_TEST_EQ(k.center_y(), 4);
85     BOOST_TEST_EQ(k.center_x(), 4);
86     BOOST_TEST_EQ(k.left_size(), 4);
87     BOOST_TEST_EQ(k.right_size(), 4);
88     BOOST_TEST_EQ(k.upper_size(), 4);
89     BOOST_TEST_EQ(k.lower_size(), 4);
90     // std::vector interface
91     BOOST_TEST_EQ(k.size(), 9);
92 }
93 
test_kernel_1d_fixed_copy_constructor()94 void test_kernel_1d_fixed_copy_constructor()
95 {
96     gil::kernel_1d_fixed<int, 9> d(4);
97     gil::kernel_1d_fixed<int, 9> k(d);
98     BOOST_TEST_EQ((gil::kernel_1d_fixed<int, 9>::static_size), 9);
99     BOOST_TEST_EQ(k.center(), 4);
100     BOOST_TEST_EQ(k.center(), d.center());
101     BOOST_TEST_EQ(k.left_size(), d.left_size());
102     BOOST_TEST_EQ(k.right_size(), d.right_size());
103     // std::vector interface
104     BOOST_TEST_EQ(k.size(), d.size());
105 }
106 
test_kernel_2d_fixed_copy_constructor()107 void test_kernel_2d_fixed_copy_constructor()
108 {
109     gil::detail::kernel_2d_fixed<int, 9> d(4, 4);
110     gil::detail::kernel_2d_fixed<int, 9> k(d);
111     BOOST_TEST_EQ((gil::detail::kernel_2d_fixed<int, 9>::static_size), 9);
112     BOOST_TEST_EQ(k.center_x(), 4);
113     BOOST_TEST_EQ(k.center_y(), 4);
114     BOOST_TEST_EQ(k.center_x(), d.center_x());
115     BOOST_TEST_EQ(k.center_y(), d.center_y());
116     BOOST_TEST_EQ(k.left_size(), d.left_size());
117     BOOST_TEST_EQ(k.right_size(), d.right_size());
118     BOOST_TEST_EQ(k.lower_size(), d.lower_size());
119     BOOST_TEST_EQ(k.upper_size(), d.upper_size());
120     // std::vector interface
121     BOOST_TEST_EQ(k.size(), d.size());
122 }
123 
test_kernel_1d_fixed_assignment_operator()124 void test_kernel_1d_fixed_assignment_operator()
125 {
126     gil::kernel_1d_fixed<int, 9> d(4);
127     gil::kernel_1d_fixed<int, 9> k;
128     k = d;
129     BOOST_TEST_EQ((gil::kernel_1d_fixed<int, 9>::static_size), 9);
130     BOOST_TEST_EQ(k.center(), 4);
131     BOOST_TEST_EQ(k.center(), d.center());
132     BOOST_TEST_EQ(k.left_size(), d.left_size());
133     BOOST_TEST_EQ(k.right_size(), d.right_size());
134     // std::vector interface
135     BOOST_TEST_EQ(k.size(), d.size());
136 }
137 
test_kernel_2d_fixed_assignment_operator()138 void test_kernel_2d_fixed_assignment_operator()
139 {
140     gil::detail::kernel_2d_fixed<int, 9> d(4, 4);
141     gil::detail::kernel_2d_fixed<int, 9> k;
142     k = d;
143     BOOST_TEST_EQ((gil::detail::kernel_2d_fixed<int, 9>::static_size), 9);
144     BOOST_TEST_EQ(k.center_x(), 4);
145     BOOST_TEST_EQ(k.center_y(), 4);
146     BOOST_TEST_EQ(k.center_x(), d.center_x());
147     BOOST_TEST_EQ(k.center_y(), d.center_y());
148     BOOST_TEST_EQ(k.left_size(), d.left_size());
149     BOOST_TEST_EQ(k.right_size(), d.right_size());
150     BOOST_TEST_EQ(k.lower_size(), d.lower_size());
151     BOOST_TEST_EQ(k.upper_size(), d.upper_size());
152     // std::vector interface
153     BOOST_TEST_EQ(k.size(), d.size());
154 }
155 
test_kernel_1d_fixed_reverse_kernel()156 void test_kernel_1d_fixed_reverse_kernel()
157 {
158     std::array<int, 3> values = {{1, 2, 3}};
159     gil::kernel_1d_fixed<int, 3> k(values.begin(), 1);
160     BOOST_TEST_EQ((gil::kernel_1d_fixed<int, 3>::static_size), 3);
161     BOOST_TEST_ALL_EQ(k.begin(), k.end(), values.begin(), values.end());
162 
163     std::array<int, 3> values_rev = {{3, 2, 1}};
164     auto const k_rev              = gil::reverse_kernel(k);
165     BOOST_TEST_ALL_EQ(k_rev.begin(), k_rev.end(), values_rev.begin(), values_rev.end());
166 }
167 
main()168 int main()
169 {
170     test_kernel_1d_fixed_default_constructor();
171     test_kernel_2d_fixed_default_constructor();
172     test_kernel_1d_fixed_parameterized_constructor();
173     test_kernel_2d_fixed_parameterized_constructor();
174     test_kernel_1d_fixed_parameterized_constructor_with_iterator();
175     test_kernel_2d_fixed_parameterized_constructor_with_iterator();
176     test_kernel_1d_fixed_copy_constructor();
177     test_kernel_2d_fixed_copy_constructor();
178     test_kernel_1d_fixed_assignment_operator();
179     test_kernel_2d_fixed_assignment_operator();
180     test_kernel_1d_fixed_reverse_kernel();
181 
182     return ::boost::report_errors();
183 }
184