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_s16.hh> 00027 00028 #define test_operator(T, OP, V1, V2) \ 00029 \ 00030 { \ 00031 T i = V1; \ 00032 T j = V2; \ 00033 \ 00034 i = i OP j; \ 00035 mln_assertion(i == (V1 OP V2)); \ 00036 mln_assertion(j == V2); \ 00037 \ 00038 i OP##= i; \ 00039 mln_assertion(i == (((V1 OP V2) OP (V1 OP V2)))); \ 00040 } 00041 00042 #define test_interop(T1, T2, OP, V1, V2) \ 00043 \ 00044 { \ 00045 T1 i = V1; \ 00046 T2 j = V2; \ 00047 \ 00048 i = i OP j; \ 00049 mln_assertion(i == (V1 OP V2)); \ 00050 mln_assertion(j == V2); \ 00051 \ 00052 i OP##= i; \ 00053 mln_assertion(i == (((V1 OP V2) OP (V1 OP V2)))); \ 00054 } 00055 00056 00057 // test_operator 00058 00059 int main() 00060 { 00061 using namespace mln; 00062 using value::int_s16; 00063 00064 int_s16 i = 3, j; 00065 00066 // Assignment. 00067 { 00068 i = 51; 00069 mln_assertion(i == 51); 00070 00071 i = 51u; 00072 mln_assertion(i == 51); 00073 00074 signed char c = 51; 00075 i = c; 00076 mln_assertion(i == 51); 00077 00078 j = i; 00079 mln_assertion(j == 51); 00080 00081 i = 3; 00082 mln_assertion(3.0f == i); 00083 mln_assertion(i != 2.99f); 00084 00085 // FIXME: Is this an incorrect behavior or what? 00086 // Error at run-time as expected :-) 00087 // i = 256; 00088 // i = -1; 00089 // i = 255, ++i; 00090 } 00091 00092 00093 // Comparaison 00094 { 00095 int_s16 i = 42; 00096 int_s16 j = 51; 00097 00098 mln_assertion(i < j); 00099 mln_assertion(j > i); 00100 mln_assertion(i < 12345); 00101 mln_assertion(12345 > i); 00102 00103 mln_assertion(i != j); 00104 mln_assertion(i == 42); 00105 mln_assertion(42 == i); 00106 mln_assertion(i != 69); 00107 mln_assertion(69 != i); 00108 00109 } 00110 00111 // Addition. 00112 { 00113 test_operator(int_s16, +, -5, 1); 00114 test_interop(int_s16, int, +, 5, -1); 00115 test_interop(int_s16, char, +, -4, 2); 00116 test_interop(int_s16, unsigned char, +, 4, 2); 00117 00118 int_s16 i = 234; 00119 00120 i++; 00121 mln_assertion(i == 235); 00122 00123 ++i; 00124 mln_assertion(i == 236); 00125 00126 i = +i; 00127 mln_assertion(i == 236); 00128 00129 } 00130 00131 // Soustraction 00132 { 00133 test_operator(int_s16, -, 100, 5); 00134 test_interop(int_s16, int, -, 100, 5); 00135 test_interop(int_s16, char, -, 100, 5); 00136 test_interop(int_s16, unsigned char, -, 100, 5); 00137 00138 int_s16 c = 255; 00139 c -= c; 00140 00141 mln_assertion(c == 0); 00142 00143 int_s16 i = 236; 00144 00145 i--; 00146 mln_assertion(i == 235); 00147 00148 --i; 00149 mln_assertion(i == 234); 00150 00151 mln_assertion(-i == -234); 00152 } 00153 00154 // Multiplication 00155 { 00156 test_operator(int_s16, *, 5, 1); 00157 test_interop(int_s16, int, *, 5, 1); 00158 test_interop(int_s16, char, *, 4, 2); 00159 test_interop(int_s16, unsigned char, *, 4, 2); 00160 00161 int_s16 c = 255; 00162 00163 c *= 0; 00164 mln_assertion(c == 0); 00165 00166 i *= 2; 00167 int k; k *= i; 00168 00169 unsigned char d = 0; 00170 i *= d; 00171 mln_assertion(i == 0); 00172 00173 // FIXME: Is this an incorrect behavior or what? 00174 // Error at run-time as expected :-) 00175 // i = 128; 00176 // i *= 2; 00177 00178 } 00179 00180 // Division 00181 { 00182 test_operator(int_s16, /, 5, 1); 00183 test_interop(int_s16, int, /, 5, 1); 00184 test_interop(int_s16, char, /, 4, 2); 00185 test_interop(int_s16, unsigned char, /, 4, 2); 00186 00187 int_s16 c = 200; 00188 00189 c /= 1; 00190 mln_assertion(c == 200); 00191 c /= 2; 00192 mln_assertion(c == 100); 00193 00194 int_s16 d = 2; 00195 c /= 2; 00196 mln_assertion(c == 50); 00197 00198 } 00199 00200 00201 // Modulo 00202 { 00203 test_operator(int_s16, %, 5, 10); 00204 test_interop(int_s16, int, %, 5, 10); 00205 test_interop(int_s16, char, %, 4, 20); 00206 test_interop(int_s16, unsigned char, %, 4, 20); 00207 } 00208 }