00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
00058
00059 int main()
00060 {
00061 using namespace mln;
00062 using value::int_s16;
00063
00064 int_s16 i = 3, j;
00065
00066
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
00086
00087
00088
00089
00090 }
00091
00092
00093
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
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
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
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
00174
00175
00176
00177
00178 }
00179
00180
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
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 }