Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 00025 00026 #include <mln/value/int_u8.hh> 00027 #include <tests/value/macros.hh> 00028 00029 00030 int main() 00031 { 00032 using namespace mln; 00033 using value::int_u8; 00034 00035 int_u8 i = 3, j; 00036 00037 { 00038 int k = 0; 00039 k += value::scalar(k); 00040 } 00041 00042 // Assignment. 00043 { 00044 i = 51; 00045 mln_assertion(i == 51u); 00046 mln_assertion(-i == -51); 00047 00048 i = 51u; 00049 mln_assertion(i == 51u); 00050 00051 signed char c = 51; 00052 i = c; 00053 mln_assertion(i == 51u); 00054 00055 j = i; 00056 mln_assertion(j == 51u); 00057 00058 i = 3; 00059 sym_compare_assert(3.0f, ==, i); 00060 sym_compare_assert(i, !=, 2.99f); 00061 00062 // FIXME: Is this an incorrect behavior or what? 00063 // Error at run-time as expected :-) 00064 // i = 256; 00065 // i = -1; 00066 // i = 255, ++i; 00067 } 00068 00069 00070 // Comparaison 00071 { 00072 int_u8 i = 42; 00073 int_u8 j = 51; 00074 00075 asym_compare_assert(i, <, j); 00076 asym_compare_assert(j, >, i); 00077 asym_compare_assert(i, <, 12345.f); 00078 asym_compare_assert(12345.f, >, i); 00079 00080 sym_compare_assert(i, !=, j); 00081 sym_compare_assert(i, ==, 42.f); 00082 sym_compare_assert(42.f, ==, i); 00083 sym_compare_assert(i, !=, 69.f); 00084 sym_compare_assert(69.f, !=, i); 00085 00086 } 00087 00088 // Addition. 00089 { 00090 test_operator(int_u8, +, 5, 1); 00091 test_interop(int_u8, int, +, 5, -1); 00092 test_interop(int_u8, char, +, 4, 2); 00093 test_interop(int_u8, unsigned char, +, 4, 2); 00094 00095 int_u8 i = 234; 00096 00097 i++; 00098 sym_compare_assert(i, ==, 235.f); 00099 00100 ++i; 00101 sym_compare_assert(i, ==, 236.f); 00102 00103 i = +i; 00104 sym_compare_assert(i, ==, 236.f); 00105 00106 } 00107 00108 // Soustraction 00109 { 00110 test_operator(int_u8, -, 100, 5); 00111 test_interop(int_u8, int, -, 100, 5); 00112 test_interop(int_u8, char, -, 100, 5); 00113 test_interop(int_u8, unsigned char, -, 5, 5); 00114 00115 int_u8 c = 255; 00116 c -= c; 00117 00118 sym_compare_assert(c, ==, 0.f); 00119 00120 int_u8 i = 236; 00121 00122 i--; 00123 sym_compare_assert(i, ==, 235.f); 00124 00125 --i; 00126 sym_compare_assert(i, ==, 234.f); 00127 00128 sym_compare_assert(-i, ==, -234.f); 00129 00130 sym_compare_assert(i * -2, !=, 0.f); 00131 std::cout << (i) << " * -2 = " 00132 << (i * -2) << ' ' 00133 << (-2 * i) << ' ' 00134 << (-2 * int(i)) 00135 << std::endl; 00136 } 00137 00138 // Multiplication 00139 { 00140 test_operator(int_u8, *, 5, 1); 00141 test_interop(int_u8, int, *, 5, 1); 00142 test_interop(int_u8, char, *, 4, 2); 00143 test_interop(int_u8, unsigned char, *, 4, 2); 00144 00145 int_u8 c = 255; 00146 00147 c *= 0; 00148 sym_compare_assert(c, ==, 0.f); 00149 00150 i *= 2; 00151 int k; k *= i; 00152 00153 unsigned char d = 0; 00154 i *= d; 00155 sym_compare_assert(i, ==, 0.f); 00156 00157 // FIXME: Is this an incorrect behavior or what? 00158 // Error at run-time as expected :-) 00159 // i = 128; 00160 // i *= 2; 00161 00162 } 00163 00164 // Division 00165 { 00166 test_operator(int_u8, /, 5, 1); 00167 test_interop(int_u8, int, /, 5, 1); 00168 test_interop(int_u8, char, /, 4, 2); 00169 test_interop(int_u8, unsigned char, /, 4, 2); 00170 00171 int_u8 c = 200; 00172 00173 c /= 1; 00174 sym_compare_assert(c, ==, 200.f); 00175 c /= 2; 00176 sym_compare_assert(c, ==, 100.f); 00177 00178 int_u8 d = 2; 00179 c /= 2; 00180 sym_compare_assert(c, ==, 50.f); 00181 00182 // FIXME: Triggers a warning about signed vs unsigned comparison. 00183 // Read the todo and the remark in mln/core/routine/ops.hh. 00184 // 00185 // d /= 2.4f; 00186 } 00187 00188 00189 // Modulo 00190 { 00191 test_operator(int_u8, %, 5, 10); 00192 test_interop(int_u8, int, %, 5, 10); 00193 test_interop(int_u8, char, %, 4, 20); 00194 test_interop(int_u8, unsigned char, %, 4, 20); 00195 } 00196 00197 }