Encapsulation. Moving shared code into TestVM instance.
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program 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
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.vm4brwsr;
20 import static org.testng.Assert.*;
21 import org.testng.annotations.BeforeClass;
22 import org.testng.annotations.Test;
26 * @author Jaroslav Tulach <jtulach@netbeans.org>
28 public class NumberTest {
29 @Test public void integerFromString() throws Exception {
30 assertExec("Can convert string to integer", Integer.class, "parseInt__ILjava_lang_String_2",
31 Double.valueOf(333), "333"
35 @Test public void doubleFromString() throws Exception {
36 assertExec("Can convert string to double", Double.class, "parseDouble__DLjava_lang_String_2",
37 Double.valueOf(33.3), "33.3"
41 @Test public void autoboxDouble() throws Exception {
42 assertExec("Autoboxing of doubles is OK", Numbers.class, "autoboxDblToString__Ljava_lang_String_2",
47 @Test public void javalog1000() throws Exception {
48 assertEquals(3.0, Math.log10(1000.0), 0.00003, "log_10(1000) == 3");
51 @Test public void jslog1000() throws Exception {
52 assertExec("log_10(1000) == 3", Math.class, "log10__DD",
53 Double.valueOf(3.0), 1000.0
57 @Test public void javaRem() {
58 assertEquals(3, Numbers.rem(303, 10));
60 @Test public void jsRem() throws Exception {
61 assertExec("Should be three", Numbers.class, "rem__III",
62 Double.valueOf(3.0), 303, 10
66 @Test public void deserializeInt() throws Exception {
67 int exp = Numbers.deserInt();
68 assertExec("Should be the same", Numbers.class, "deserInt__I",
73 @Test public void deserializeSimpleLong() throws Exception {
74 assertExec("Should be 3454", Numbers.class, "deserLong__J_3B",
76 new byte[] { (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)13, (byte)126 }
79 /* XXX: JavaScript cannot represent as big longs as Java.
80 @Test public void deserializeLargeLong() throws Exception {
81 final byte[] arr = new byte[] {
82 (byte)64, (byte)8, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0
84 long exp = Numbers.deserLong(arr);
85 assertExec("Should be " + exp, "org_apidesign_vm4brwsr_Numbers_deserLong__JAB",
86 Double.valueOf(exp), arr);
90 @Test public void deserializeFloatInJava() throws Exception {
91 float f = 54324.32423f;
92 float r = Numbers.deserFloat();
93 assertEquals(r, f, "Floats are the same");
96 @Test public void deserializeFloatInJS() throws Exception {
97 float f = 54324.32423f;
98 assertExec("Should be the same", Numbers.class, "deserFloat__F",
103 @Test public void deserializeDoubleInJava() throws Exception {
105 double r = Numbers.deserDouble();
106 assertEquals(r, f, 0.001, "Doubles are the same");
109 @Test public void deserializeDoubleInJS() throws Exception {
111 assertExec("Should be the same", Numbers.class, "deserDouble__D", f);
114 @Test public void serDouble() throws IOException {
116 ByteArrayOutputStream os = new ByteArrayOutputStream();
117 DataOutputStream d = new DataOutputStream(os);
121 StringBuilder sb = new StringBuilder();
122 byte[] arr = os.toByteArray();
123 for (int i = 0; i < arr.length; i++) {
124 sb.append("(byte)").append(arr[i]).append(", ");
129 @Test public void fiveInStringJS() throws Exception {
130 String s = Numbers.intToString();
131 assertExec("Should be the same: " + s,
132 Numbers.class, "intToString__Ljava_lang_String_2",
137 @Test public void sevenInStringJS() throws Exception {
138 String s = Numbers.floatToString();
139 assertExec("Should be the same: " + s,
140 Numbers.class, "floatToString__Ljava_lang_String_2",
145 @Test public void longConversion() throws Exception {
146 assertExec("Long from cPool",
147 Numbers.class, "conversionL__J",
148 Double.valueOf(Long.MAX_VALUE)
152 @Test public void longNegate1() throws Exception {
153 final long res = -0x00fa37d7763e0ca1l;
154 assertExec("Long negate",
155 Numbers.class, "negL__J_3B",
157 new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }
161 @Test public void longNegate2() throws Exception {
162 final long res = -0x80fa37d7763e0ca1l;
163 assertExec("Long negate",
164 Numbers.class, "negL__J_3B",
166 new byte[] { (byte)0x80, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }
170 @Test public void longNegate3() throws Exception {
171 final long res = -0xfffffffffffffeddl;
172 assertExec("Long negate",
173 Numbers.class, "negL__J_3B",
175 new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xfe, (byte)0xdd }
179 @Test public void longAddOverflow() throws Exception {
180 final long res = Long.MAX_VALUE + 1l;
181 assertExec("Addition 1+MAX",
182 Numbers.class, "addL__J_3B_3B",
184 new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff },
185 new byte[] { (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)1 }
189 @Test public void longAddMaxAndMax() throws Exception {
190 final long res = Long.MAX_VALUE + Long.MAX_VALUE;
191 assertExec("Addition MAX+MAX",
192 Numbers.class, "addL__J_3B_3B",
194 new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff },
195 new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff }
199 @Test public void longSubUnderflow() throws Exception {
200 final long res = Long.MIN_VALUE - 1l;
201 assertExec("Subtraction MIN-1",
202 Numbers.class, "subL__J_3B_3B",
204 new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
205 new byte[] { (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)1 }
209 @Test public void longSubMinAndMin() throws Exception {
210 final long res = Long.MIN_VALUE - Long.MIN_VALUE;
211 assertExec("Subtraction MIN-MIN",
212 Numbers.class, "subL__J_3B_3B",
214 new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
215 new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }
219 @Test public void longSubMinAndMax() throws Exception {
220 final long res = Long.MIN_VALUE - Long.MAX_VALUE;
221 assertExec("Subtraction MIN-MAX",
222 Numbers.class, "subL__J_3B_3B",
224 new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
225 new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff }
229 @Test public void longMultiplyMax() throws Exception {
230 final long res = Long.MAX_VALUE * 2l;
231 assertExec("Multiplication MAX*2",
232 Numbers.class, "mulL__J_3B_3B",
234 new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff },
235 new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02 }
239 @Test public void longMultiplyMaxAndMax() throws Exception {
240 final long res = Long.MAX_VALUE * Long.MAX_VALUE;
241 assertExec("Multiplication MAX*MAX",
242 Numbers.class, "mulL__J_3B_3B",
244 new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff },
245 new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff }
249 @Test public void longMultiplyMin() throws Exception {
250 final long res = Long.MIN_VALUE * 2l;
251 assertExec("Multiplication MIN*2",
252 Numbers.class, "mulL__J_3B_3B",
254 new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
255 new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02 }
259 @Test public void longMultiplyMinAndMin() throws Exception {
260 final long res = Long.MIN_VALUE * Long.MIN_VALUE;
261 assertExec("Multiplication MIN*2",
262 Numbers.class, "mulL__J_3B_3B",
264 new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
265 new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }
269 @Test public void longMultiplyPrecision() throws Exception {
270 final long res = 0x00fa37d7763e0ca1l * 0xa7b3432fff00123el;
271 assertExec("Multiplication",
272 Numbers.class, "mulL__J_3B_3B",
274 new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
275 new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
279 @Test public void longDivideSmallPositiveNumbers() throws Exception {
280 final long res = 0xabcdef / 0x123;
281 assertExec("Division Small Positive Numbers",
282 Numbers.class, "divL__J_3B_3B",
284 new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xab, (byte)0xcd, (byte)0xef },
285 new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x23 }
289 @Test public void longDivideSmallNegativeNumbers() throws Exception {
290 final long res = -0xabcdef / -0x123;
291 assertExec("Division Small Negative Numbers",
292 Numbers.class, "divL__J_3B_3B",
294 new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0x54, (byte)0x32, (byte)0x11 },
295 new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xfe, (byte)0xdd }
299 @Test public void longDivideSmallMixedNumbers() throws Exception {
300 final long res = 0xabcdef / -0x123;
301 assertExec("Division Small Mixed Numbers",
302 Numbers.class, "divL__J_3B_3B",
304 new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xab, (byte)0xcd, (byte)0xef },
305 new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xfe, (byte)0xdd }
309 @Test public void longDividePositiveNumbersOneDigitDenom()
311 final long res = 0xabcdef0102ffffL / 0x654;
312 assertExec("Division Positive Numbers One Digit Denom",
313 Numbers.class, "divL__J_3B_3B",
315 new byte[] { (byte)0x00, (byte)0xab, (byte)0xcd, (byte)0xef, (byte)0x01, (byte)0x02, (byte)0xff, (byte)0xff },
316 new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x06, (byte)0x54 }
320 @Test public void longDivideNegativeNumbersOneDigitDenom()
322 final long res = -0xabcdef0102ffffL / -0x654;
323 assertExec("Division Negative Numbers One Digit Denom",
324 Numbers.class, "divL__J_3B_3B",
326 new byte[] { (byte)0xff, (byte)0x54, (byte)0x32, (byte)0x10, (byte)0xfe, (byte)0xfd, (byte)0x00, (byte)0x01 },
327 new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xf9, (byte)0xac }
331 @Test public void longDivideMixedNumbersOneDigitDenom()
333 final long res = -0xabcdef0102ffffL / 0x654;
334 assertExec("Division Mixed Numbers One Digit Denom",
335 Numbers.class, "divL__J_3B_3B",
337 new byte[] { (byte)0xff, (byte)0x54, (byte)0x32, (byte)0x10, (byte)0xfe, (byte)0xfd, (byte)0x00, (byte)0x01 },
338 new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x06, (byte)0x54 }
342 @Test public void longDividePositiveNumbersMultiDigitDenom()
344 final long res = 0x7ffefc003322aabbL / 0x89ab1000L;
345 assertExec("Division Positive Numbers Multi Digit Denom",
346 Numbers.class, "divL__J_3B_3B",
348 new byte[] { (byte)0x7f, (byte)0xfe, (byte)0xfc, (byte)0x00, (byte)0x33, (byte)0x22, (byte)0xaa, (byte)0xbb },
349 new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x89, (byte)0xab, (byte)0x10, (byte)0x00 }
353 @Test public void longDivideNegativeNumbersMultiDigitDenom()
355 final long res = -0x7ffefc003322aabbL / -0x123489ab1001L;
356 assertExec("Division Negative Numbers Multi Digit Denom",
357 Numbers.class, "divL__J_3B_3B",
359 new byte[] { (byte)0x80, (byte)0x01, (byte)0x03, (byte)0xff, (byte)0xcc, (byte)0xdd, (byte)0x55, (byte)0x45 },
360 new byte[] { (byte)0xff, (byte)0xff, (byte)0xed, (byte)0xcb, (byte)0x76, (byte)0x54, (byte)0xef, (byte)0xff }
364 @Test public void longDivideMixedNumbersMultiDigitDenom()
366 final long res = 0x7ffefc003322aabbL / -0x38f49b0b7574e36L;
367 assertExec("Division Mixed Numbers Multi Digit Denom",
368 Numbers.class, "divL__J_3B_3B",
370 new byte[] { (byte)0x7f, (byte)0xfe, (byte)0xfc, (byte)0x00, (byte)0x33, (byte)0x22, (byte)0xaa, (byte)0xbb },
371 new byte[] { (byte)0xfc, (byte)0x70, (byte)0xb6, (byte)0x4f, (byte)0x48, (byte)0xa8, (byte)0xb1, (byte)0xca }
375 @Test public void longDivideWithOverflow() throws Exception {
376 final long res = 0x8000fffe0000L / 0x8000ffffL;
377 assertExec("Division With Overflow",
378 Numbers.class, "divL__J_3B_3B",
380 new byte[] { (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0xff, (byte)0xfe, (byte)0x00, (byte)0x00 },
381 new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0xff, (byte)0xff }
385 @Test public void longDivideWithCorrection() throws Exception {
386 final long res = 0x7fff800000000000L / 0x800000000001L;
387 assertExec("Division With Correction",
388 Numbers.class, "divL__J_3B_3B",
390 new byte[] { (byte)0x7f, (byte)0xff, (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
391 new byte[] { (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01 }
395 @Test public void longModuloSmallPositiveNumbers() throws Exception {
396 final long res = 0xabcdef % 0x123;
397 assertExec("Modulo Small Positive Numbers",
398 Numbers.class, "modL__J_3B_3B",
400 new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xab, (byte)0xcd, (byte)0xef },
401 new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0x23 }
405 @Test public void longModuloSmallNegativeNumbers() throws Exception {
406 final long res = -0xabcdef % -0x123;
407 assertExec("Modulo Small Negative Numbers",
408 Numbers.class, "modL__J_3B_3B",
410 new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0x54, (byte)0x32, (byte)0x11 },
411 new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xfe, (byte)0xdd }
415 @Test public void longModuloSmallMixedNumbers() throws Exception {
416 final long res = 0xabcdef % -0x123;
417 assertExec("Modulo Small Mixed Numbers",
418 Numbers.class, "modL__J_3B_3B",
420 new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xab, (byte)0xcd, (byte)0xef },
421 new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xfe, (byte)0xdd }
425 @Test public void longModuloPositiveNumbersOneDigitDenom()
427 final long res = 0xabcdef0102ffffL % 0x654;
428 assertExec("Modulo Positive Numbers One Digit Denom",
429 Numbers.class, "modL__J_3B_3B",
431 new byte[] { (byte)0x00, (byte)0xab, (byte)0xcd, (byte)0xef, (byte)0x01, (byte)0x02, (byte)0xff, (byte)0xff },
432 new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x06, (byte)0x54 }
436 @Test public void longModuloNegativeNumbersOneDigitDenom()
438 final long res = -0xabcdef0102ffffL % -0x654;
439 assertExec("Modulo Negative Numbers One Digit Denom",
440 Numbers.class, "modL__J_3B_3B",
442 new byte[] { (byte)0xff, (byte)0x54, (byte)0x32, (byte)0x10, (byte)0xfe, (byte)0xfd, (byte)0x00, (byte)0x01 },
443 new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xf9, (byte)0xac }
447 @Test public void longModuloMixedNumbersOneDigitDenom()
449 final long res = -0xabcdef0102ffffL % 0x654;
450 assertExec("Modulo Mixed Numbers One Digit Denom",
451 Numbers.class, "modL__J_3B_3B",
453 new byte[] { (byte)0xff, (byte)0x54, (byte)0x32, (byte)0x10, (byte)0xfe, (byte)0xfd, (byte)0x00, (byte)0x01 },
454 new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x06, (byte)0x54 }
458 @Test public void longModuloPositiveNumbersMultiDigitDenom()
460 final long res = 0x7ffefc003322aabbL % 0x89ab1000L;
461 assertExec("Modulo Positive Numbers Multi Digit Denom",
462 Numbers.class, "modL__J_3B_3B",
464 new byte[] { (byte)0x7f, (byte)0xfe, (byte)0xfc, (byte)0x00, (byte)0x33, (byte)0x22, (byte)0xaa, (byte)0xbb },
465 new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x89, (byte)0xab, (byte)0x10, (byte)0x00 }
469 @Test public void longModuloNegativeNumbersMultiDigitDenom()
471 final long res = -0x7ffefc003322aabbL % -0x123489ab1001L;
472 assertExec("Modulo Negative Numbers Multi Digit Denom",
473 Numbers.class, "modL__J_3B_3B",
475 new byte[] { (byte)0x80, (byte)0x01, (byte)0x03, (byte)0xff, (byte)0xcc, (byte)0xdd, (byte)0x55, (byte)0x45 },
476 new byte[] { (byte)0xff, (byte)0xff, (byte)0xed, (byte)0xcb, (byte)0x76, (byte)0x54, (byte)0xef, (byte)0xff }
480 @Test public void longModuloMixedNumbersMultiDigitDenom()
482 final long res = 0x7ffefc003322aabbL % -0x38f49b0b7574e36L;
483 assertExec("Modulo Mixed Numbers Multi Digit Denom",
484 Numbers.class, "modL__J_3B_3B",
486 new byte[] { (byte)0x7f, (byte)0xfe, (byte)0xfc, (byte)0x00, (byte)0x33, (byte)0x22, (byte)0xaa, (byte)0xbb },
487 new byte[] { (byte)0xfc, (byte)0x70, (byte)0xb6, (byte)0x4f, (byte)0x48, (byte)0xa8, (byte)0xb1, (byte)0xca }
491 @Test public void longModuloWithOverflow() throws Exception {
492 final long res = 0x8000fffe0000L % 0x8000ffffL;
493 assertExec("Modulo With Overflow",
494 Numbers.class, "modL__J_3B_3B",
496 new byte[] { (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0xff, (byte)0xfe, (byte)0x00, (byte)0x00 },
497 new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0xff, (byte)0xff }
501 @Test public void longModuloWithCorrection() throws Exception {
502 final long res = 0x7fff800000000000L % 0x800000000001L;
503 assertExec("Modulo With Correction",
504 Numbers.class, "modL__J_3B_3B",
506 new byte[] { (byte)0x7f, (byte)0xff, (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
507 new byte[] { (byte)0x00, (byte)0x00, (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01 }
511 @Test public void longShiftL1() throws Exception {
512 final long res = 0x00fa37d7763e0ca1l << 5;
513 assertExec("Long << 5",
514 Numbers.class, "shlL__J_3BI",
516 new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
520 @Test public void longShiftL2() throws Exception {
521 final long res = 0x00fa37d7763e0ca1l << 32;
522 assertExec("Long << 32",
523 Numbers.class, "shlL__J_3BI",
525 new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
529 @Test public void longShiftL3() throws Exception {
530 final long res = 0x00fa37d7763e0ca1l << 45;
531 assertExec("Long << 45",
532 Numbers.class, "shlL__J_3BI",
534 new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
538 @Test public void longShiftR1() throws Exception {
539 final long res = 0x00fa37d7763e0ca1l >> 5;
540 assertExec("Long >> 5",
541 Numbers.class, "shrL__J_3BI",
543 new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
547 @Test public void longShiftR2() throws Exception {
548 final long res = 0x00fa37d7763e0ca1l >> 32;
549 assertExec("Long >> 32",
550 Numbers.class, "shrL__J_3BI",
552 new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
556 @Test public void longShiftR3() throws Exception {
557 final long res = 0x00fa37d7763e0ca1l >> 45;
558 assertExec("Long >> 45",
559 Numbers.class, "shrL__J_3BI",
561 new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
565 @Test public void longUShiftR1() throws Exception {
566 final long res = 0x00fa37d7763e0ca1l >>> 5;
567 assertExec("Long >>> 5",
568 Numbers.class, "ushrL__J_3BI",
570 new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
574 @Test public void longUShiftR2() throws Exception {
575 final long res = 0x00fa37d7763e0ca1l >>> 45;
576 assertExec("Long >>> 45",
577 Numbers.class, "ushrL__J_3BI",
579 new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
583 @Test public void longUShiftR3() throws Exception {
584 final long res = 0xf0fa37d7763e0ca1l >>> 5;
585 assertExec("Long >>> 5",
586 Numbers.class, "ushrL__J_3BI",
588 new byte[] { (byte)0xf0, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
592 @Test public void longUShiftR4() throws Exception {
593 final long res = 0xf0fa37d7763e0ca1l >>> 45;
594 assertExec("Long >>> 45",
595 Numbers.class, "ushrL__J_3BI",
597 new byte[] { (byte)0xf0, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
601 @Test public void longAnd() throws Exception {
602 final long res = 0x00fa37d7763e0ca1l & 0xa7b3432fff00123el;
603 assertExec("LOng binary AND",
604 Numbers.class, "andL__J_3B_3B",
606 new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
607 new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
611 @Test public void longOr() throws Exception {
612 final long res = 0x00fa37d7763e0ca1l | 0xa7b3432fff00123el;
613 assertExec("Long binary OR",
614 Numbers.class, "orL__J_3B_3B",
616 new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
617 new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
621 @Test public void longXor1() throws Exception {
622 final long res = 0x00fa37d7763e0ca1l ^ 0xa7b3432fff00123el;
623 assertExec("Long binary XOR",
624 Numbers.class, "xorL__J_3B_3B",
626 new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
627 new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
631 @Test public void longXor2() throws Exception {
632 final long res = 0x00fa37d7763e0ca1l ^ 0x00000000ff00123el;
633 assertExec("Long binary XOR",
634 Numbers.class, "xorL__J_3B_3B",
636 new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
637 new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
641 @Test public void longXor3() throws Exception {
642 final long res = 0x00000000763e0ca1l ^ 0x00000000ff00123el;
643 assertExec("Long binary XOR",
644 Numbers.class, "xorL__J_3B_3B",
646 new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
647 new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
651 @Test public void longCompareSameNumbers() throws Exception {
652 assertExec("Long compare same numbers",
653 Numbers.class, "compareL__I_3B_3BI",
655 new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
656 new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
661 @Test public void longComparePositiveNumbers() throws Exception {
662 assertExec("Long compare positive numbers",
663 Numbers.class, "compareL__I_3B_3BI",
665 new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x00 },
666 new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x10, (byte)0x00, (byte)0x00, (byte)0x00 },
671 @Test public void longCompareNegativeNumbers() throws Exception {
672 assertExec("Long compare negative numbers",
673 Numbers.class, "compareL__I_3B_3BI",
675 new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff },
676 new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
681 @Test public void longCompareMixedNumbers() throws Exception {
682 assertExec("Long compare mixed numbers",
683 Numbers.class, "compareL__I_3B_3BI",
685 new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
686 new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff },
691 private static TestVM code;
694 public void compileTheCode() throws Exception {
695 code = TestVM.compileClass("org/apidesign/vm4brwsr/Numbers");
698 private static void assertExec(
699 String msg, Class<?> clazz, String method, Object expRes, Object... args) throws Exception
701 Object ret = code.execCode(msg, clazz, method, expRes, args);
705 if (expRes instanceof Double && ret instanceof Double) {
706 double expD = ((Double)expRes).doubleValue();
707 double retD = ((Double)ret).doubleValue();
708 assertEquals(retD, expD, 0.000004, msg + " "
712 assertEquals(ret, expRes, msg + " " + code.toString());