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