$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
int_u8.cc
1 // Copyright (C) 2007, 2008, 2009, 2013 EPITA Research and Development
2 // Laboratory (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #include <mln/value/int_u8.hh>
28 #include <tests/value/macros.hh>
29 
30 
31 int main()
32 {
33  using namespace mln;
34  using value::int_u8;
35 
36  int_u8 i = 3, j;
37 
38  {
39  int k = 0;
40  k += value::scalar(k);
41  }
42 
43  // Assignment.
44  {
45  i = 51;
46  mln_assertion(i == 51u);
47  mln_assertion(-i == -51);
48 
49  i = 51u;
50  mln_assertion(i == 51u);
51 
52  signed char c = 51;
53  i = c;
54  mln_assertion(i == 51u);
55 
56  j = i;
57  mln_assertion(j == 51u);
58 
59  i = 3;
60  sym_compare_assert(3.0f, ==, i);
61  sym_compare_assert(i, !=, 2.99f);
62 
63  // FIXME: Is this an incorrect behavior or what?
64  // Error at run-time as expected :-)
65  // i = 256;
66  // i = -1;
67  // i = 255, ++i;
68  }
69 
70 
71  // Comparaison
72  {
73  int_u8 i = 42;
74  int_u8 j = 51;
75 
76  asym_compare_assert(i, <, j);
77  asym_compare_assert(j, >, i);
78  asym_compare_assert(i, <, 12345.f);
79  asym_compare_assert(12345.f, >, i);
80 
81  sym_compare_assert(i, !=, j);
82  sym_compare_assert(i, ==, 42.f);
83  sym_compare_assert(42.f, ==, i);
84  sym_compare_assert(i, !=, 69.f);
85  sym_compare_assert(69.f, !=, i);
86 
87  }
88 
89  // Addition.
90  {
91  test_operator(int_u8, +, 5, 1);
92  test_interop(int_u8, int, +, 5, -1);
93  test_interop(int_u8, char, +, 4, 2);
94  test_interop(int_u8, unsigned char, +, 4, 2);
95 
96  int_u8 i = 234;
97 
98  i++;
99  sym_compare_assert(i, ==, 235.f);
100 
101  ++i;
102  sym_compare_assert(i, ==, 236.f);
103 
104  i = +i;
105  sym_compare_assert(i, ==, 236.f);
106 
107  }
108 
109  // Soustraction
110  {
111  test_operator(int_u8, -, 100, 5);
112  test_interop(int_u8, int, -, 100, 5);
113  test_interop(int_u8, char, -, 100, 5);
114  test_interop(int_u8, unsigned char, -, 5, 5);
115 
116  int_u8 c = 255;
117  c -= c;
118 
119  sym_compare_assert(c, ==, 0.f);
120 
121  int_u8 i = 236;
122 
123  i--;
124  sym_compare_assert(i, ==, 235.f);
125 
126  --i;
127  sym_compare_assert(i, ==, 234.f);
128 
129  sym_compare_assert(-i, ==, -234.f);
130 
131  sym_compare_assert(i * -2, !=, 0.f);
132  std::cout << (i) << " * -2 = "
133  << (i * -2) << ' '
134  << (-2 * i) << ' '
135  << (-2 * int(i))
136  << std::endl;
137  }
138 
139  // Multiplication
140  {
141  test_operator(int_u8, *, 5, 1);
142  test_interop(int_u8, int, *, 5, 1);
143  test_interop(int_u8, char, *, 4, 2);
144  test_interop(int_u8, unsigned char, *, 4, 2);
145 
146  int_u8 c = 255;
147 
148  c *= 0;
149  sym_compare_assert(c, ==, 0.f);
150 
151  i *= 2;
152  int k; k *= i;
153 
154  unsigned char d = 0;
155  i *= d;
156  sym_compare_assert(i, ==, 0.f);
157 
158  // FIXME: Is this an incorrect behavior or what?
159  // Error at run-time as expected :-)
160  // i = 128;
161  // i *= 2;
162 
163  }
164 
165  // Division
166  {
167  test_operator(int_u8, /, 5, 1);
168  test_interop(int_u8, int, /, 5, 1);
169  test_interop(int_u8, char, /, 4, 2);
170  test_interop(int_u8, unsigned char, /, 4, 2);
171 
172  int_u8 c = 200;
173 
174  c /= 1;
175  sym_compare_assert(c, ==, 200.f);
176  c /= 2;
177  sym_compare_assert(c, ==, 100.f);
178 
179  int_u8 d = 2;
180  c /= d;
181  sym_compare_assert(c, ==, 50.f);
182 
183  // FIXME: Triggers a warning about signed vs unsigned comparison.
184  // Read the todo and the remark in mln/core/routine/ops.hh.
185  //
186  // d /= 2.4f;
187  }
188 
189 
190  // Modulo
191  {
192  test_operator(int_u8, %, 5, 10);
193  test_interop(int_u8, int, %, 5, 10);
194  test_interop(int_u8, char, %, 4, 20);
195  test_interop(int_u8, unsigned char, %, 4, 20);
196  }
197 
198 }