jaroslav@114: /** jaroslav@114: * Back 2 Browser Bytecode Translator jaroslav@114: * Copyright (C) 2012 Jaroslav Tulach jaroslav@114: * jaroslav@114: * This program is free software: you can redistribute it and/or modify jaroslav@114: * it under the terms of the GNU General Public License as published by jaroslav@114: * the Free Software Foundation, version 2 of the License. jaroslav@114: * jaroslav@114: * This program is distributed in the hope that it will be useful, jaroslav@114: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@114: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@114: * GNU General Public License for more details. jaroslav@114: * jaroslav@114: * You should have received a copy of the GNU General Public License jaroslav@114: * along with this program. Look for COPYING file in the top folder. jaroslav@114: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@114: */ jaroslav@114: package org.apidesign.vm4brwsr; jaroslav@114: jaroslav@114: import javax.script.Invocable; jaroslav@114: import javax.script.ScriptException; jtulach@132: import static org.testng.Assert.*; jaroslav@114: import org.testng.annotations.BeforeClass; jaroslav@114: import org.testng.annotations.Test; jaroslav@114: jaroslav@114: /** jaroslav@114: * jaroslav@114: * @author Jaroslav Tulach jaroslav@114: */ jaroslav@114: public class NumberTest { jaroslav@114: @Test public void integerFromString() throws Exception { jaroslav@248: assertExec("Can convert string to integer", Integer.class, "parseInt__ILjava_lang_String_2", jaroslav@114: Double.valueOf(333), "333" jaroslav@114: ); jaroslav@114: } jaroslav@114: jaroslav@114: @Test public void doubleFromString() throws Exception { jaroslav@248: assertExec("Can convert string to double", Double.class, "parseDouble__DLjava_lang_String_2", jaroslav@114: Double.valueOf(33.3), "33.3" jaroslav@114: ); jaroslav@114: } jaroslav@114: jaroslav@114: @Test public void autoboxDouble() throws Exception { jaroslav@248: assertExec("Autoboxing of doubles is OK", Numbers.class, "autoboxDblToString__Ljava_lang_String_2", jaroslav@114: "3.3" jaroslav@114: ); jaroslav@114: } jtulach@132: jtulach@132: @Test public void javalog1000() throws Exception { jtulach@132: assertEquals(3.0, Math.log10(1000.0), 0.00003, "log_10(1000) == 3"); jtulach@132: } jtulach@132: jtulach@132: @Test public void jslog1000() throws Exception { jaroslav@248: assertExec("log_10(1000) == 3", Math.class, "log10__DD", jtulach@132: Double.valueOf(3.0), 1000.0 jtulach@132: ); jtulach@132: } jaroslav@178: jaroslav@178: @Test public void javaRem() { jaroslav@178: assertEquals(3, Numbers.rem(303, 10)); jaroslav@178: } jaroslav@178: @Test public void jsRem() throws Exception { jaroslav@248: assertExec("Should be three", Numbers.class, "rem__III", jaroslav@178: Double.valueOf(3.0), 303, 10 jaroslav@178: ); jaroslav@178: } jaroslav@181: jaroslav@181: @Test public void deserializeInt() throws Exception { jaroslav@181: int exp = Numbers.deserInt(); jaroslav@248: assertExec("Should be the same", Numbers.class, "deserInt__I", jaroslav@181: Double.valueOf(exp) jaroslav@181: ); jaroslav@181: } jaroslav@185: jaroslav@185: @Test public void deserializeSimpleLong() throws Exception { jaroslav@248: assertExec("Should be 3454", Numbers.class, "deserLong__J_3B", jaroslav@185: Double.valueOf(3454), jaroslav@185: new byte[] { (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)13, (byte)126 } jaroslav@185: ); jaroslav@185: } jaroslav@185: /* XXX: JavaScript cannot represent as big longs as Java. jaroslav@185: @Test public void deserializeLargeLong() throws Exception { jaroslav@185: final byte[] arr = new byte[] { jaroslav@185: (byte)64, (byte)8, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0 jaroslav@185: }; jaroslav@185: long exp = Numbers.deserLong(arr); jaroslav@248: assertExec("Should be " + exp, "org_apidesign_vm4brwsr_Numbers_deserLong__JAB", jaroslav@185: Double.valueOf(exp), arr); jaroslav@185: } jaroslav@185: */ jaroslav@181: jaroslav@181: @Test public void deserializeFloatInJava() throws Exception { jaroslav@181: float f = 54324.32423f; jaroslav@181: float r = Numbers.deserFloat(); jaroslav@181: assertEquals(r, f, "Floats are the same"); jaroslav@181: } jaroslav@181: jaroslav@181: @Test public void deserializeFloatInJS() throws Exception { jaroslav@181: float f = 54324.32423f; jaroslav@248: assertExec("Should be the same", Numbers.class, "deserFloat__F", jaroslav@181: Double.valueOf(f) jaroslav@181: ); jaroslav@181: } jaroslav@114: jaroslav@185: @Test public void deserializeDoubleInJava() throws Exception { jaroslav@185: double f = 3.0; jaroslav@185: double r = Numbers.deserDouble(); jaroslav@185: assertEquals(r, f, 0.001, "Doubles are the same"); jaroslav@185: } jaroslav@114: jaroslav@185: @Test public void deserializeDoubleInJS() throws Exception { jaroslav@185: double f = 3.0; jaroslav@248: assertExec("Should be the same", Numbers.class, "deserDouble__D", f); jaroslav@185: } jaroslav@185: /* jaroslav@185: @Test public void serDouble() throws IOException { jaroslav@185: double f = 3.0; jaroslav@185: ByteArrayOutputStream os = new ByteArrayOutputStream(); jaroslav@185: DataOutputStream d = new DataOutputStream(os); jaroslav@185: d.writeLong(3454); jaroslav@185: d.close(); jaroslav@185: jaroslav@185: StringBuilder sb = new StringBuilder(); jaroslav@185: byte[] arr = os.toByteArray(); jaroslav@185: for (int i = 0; i < arr.length; i++) { jaroslav@185: sb.append("(byte)").append(arr[i]).append(", "); jaroslav@185: } jaroslav@185: fail("" + sb); jaroslav@185: } jaroslav@185: */ jaroslav@186: @Test public void fiveInStringJS() throws Exception { jaroslav@186: String s = Numbers.intToString(); jaroslav@186: assertExec("Should be the same: " + s, jaroslav@248: Numbers.class, "intToString__Ljava_lang_String_2", jaroslav@186: s jaroslav@186: ); jaroslav@186: } jaroslav@187: jaroslav@187: @Test public void sevenInStringJS() throws Exception { jaroslav@187: String s = Numbers.floatToString(); jaroslav@187: assertExec("Should be the same: " + s, jaroslav@248: Numbers.class, "floatToString__Ljava_lang_String_2", jaroslav@187: s jaroslav@187: ); jaroslav@187: } jaroslav@186: Martin@615: @Test public void longConversion() throws Exception { Martin@615: assertExec("Long from cPool", Martin@615: Numbers.class, "conversionL__J", Martin@615: Double.valueOf(Long.MAX_VALUE) Martin@615: ); Martin@615: } Martin@615: Martin@630: @Test public void longNegate1() throws Exception { Martin@630: final long res = -0x00fa37d7763e0ca1l; Martin@630: assertExec("Long negate", Martin@630: Numbers.class, "negL__J_3B", Martin@630: Double.valueOf(res), Martin@630: new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 } Martin@630: ); Martin@630: } Martin@630: Martin@630: @Test public void longNegate2() throws Exception { Martin@630: final long res = -0x80fa37d7763e0ca1l; Martin@630: assertExec("Long negate", Martin@630: Numbers.class, "negL__J_3B", Martin@630: Double.valueOf(res), Martin@630: new byte[] { (byte)0x80, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 } Martin@630: ); Martin@630: } Martin@630: Martin@669: @Test public void longNegate3() throws Exception { Martin@669: final long res = -0xfffffffffffffeddl; Martin@669: assertExec("Long negate", Martin@669: Numbers.class, "negL__J_3B", Martin@669: Double.valueOf(res), Martin@669: new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xfe, (byte)0xdd } Martin@669: ); Martin@669: } Martin@669: Martin@669: Martin@616: @Test public void longAddOverflow() throws Exception { Martin@616: final long res = Long.MAX_VALUE + 1l; Martin@616: assertExec("Addition 1+MAX", Martin@616: Numbers.class, "addL__J_3B_3B", Martin@616: Double.valueOf(res), Martin@616: new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff }, Martin@616: new byte[] { (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)1 } Martin@616: ); Martin@616: } Martin@616: Martin@616: @Test public void longAddMaxAndMax() throws Exception { Martin@616: final long res = Long.MAX_VALUE + Long.MAX_VALUE; Martin@616: assertExec("Addition MAX+MAX", Martin@616: Numbers.class, "addL__J_3B_3B", Martin@616: Double.valueOf(res), Martin@616: new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff }, Martin@616: new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff } Martin@616: ); Martin@616: } Martin@616: Martin@620: @Test public void longSubUnderflow() throws Exception { Martin@620: final long res = Long.MIN_VALUE - 1l; Martin@620: assertExec("Subtraction MIN-1", Martin@620: Numbers.class, "subL__J_3B_3B", Martin@620: Double.valueOf(res), Martin@620: new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }, Martin@620: new byte[] { (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)1 } Martin@620: ); Martin@620: } Martin@620: Martin@620: @Test public void longSubMinAndMin() throws Exception { Martin@620: final long res = Long.MIN_VALUE - Long.MIN_VALUE; Martin@620: assertExec("Subtraction MIN-MIN", Martin@620: Numbers.class, "subL__J_3B_3B", Martin@620: Double.valueOf(res), Martin@620: new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }, Martin@620: new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 } Martin@620: ); Martin@620: } Martin@620: Martin@620: @Test public void longSubMinAndMax() throws Exception { Martin@620: final long res = Long.MIN_VALUE - Long.MAX_VALUE; Martin@620: assertExec("Subtraction MIN-MAX", Martin@620: Numbers.class, "subL__J_3B_3B", Martin@620: Double.valueOf(res), Martin@620: new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }, Martin@620: new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff } Martin@620: ); Martin@620: } Martin@620: Martin@657: @Test public void longMultiplyMax() throws Exception { Martin@657: final long res = Long.MAX_VALUE * 2l; Martin@657: assertExec("Multiplication MAX*2", Martin@657: Numbers.class, "mulL__J_3B_3B", Martin@657: Double.valueOf(res), Martin@657: new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff }, Martin@657: new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02 } Martin@657: ); Martin@657: } Martin@657: Martin@657: @Test public void longMultiplyMaxAndMax() throws Exception { Martin@657: final long res = Long.MAX_VALUE * Long.MAX_VALUE; Martin@657: assertExec("Multiplication MAX*MAX", Martin@657: Numbers.class, "mulL__J_3B_3B", Martin@657: Double.valueOf(res), Martin@657: new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff }, Martin@657: new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff } Martin@657: ); Martin@657: } Martin@657: Martin@657: @Test public void longMultiplyMin() throws Exception { Martin@657: final long res = Long.MIN_VALUE * 2l; Martin@657: assertExec("Multiplication MIN*2", Martin@657: Numbers.class, "mulL__J_3B_3B", Martin@657: Double.valueOf(res), Martin@657: new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }, Martin@657: new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x02 } Martin@657: ); Martin@657: } Martin@657: Martin@657: @Test public void longMultiplyMinAndMin() throws Exception { Martin@657: final long res = Long.MIN_VALUE * Long.MIN_VALUE; Martin@657: assertExec("Multiplication MIN*2", Martin@657: Numbers.class, "mulL__J_3B_3B", Martin@657: Double.valueOf(res), Martin@657: new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 }, Martin@657: new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 } Martin@657: ); Martin@657: } Martin@657: Martin@657: @Test public void longMultiplyPrecision() throws Exception { Martin@657: final long res = 0x00fa37d7763e0ca1l * 0xa7b3432fff00123el; Martin@657: assertExec("Multiplication", Martin@657: Numbers.class, "mulL__J_3B_3B", Martin@657: Double.valueOf(res), Martin@657: new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, Martin@657: new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e } Martin@657: ); Martin@657: } Martin@657: Martin@617: @Test public void longShiftL1() throws Exception { Martin@617: final long res = 0x00fa37d7763e0ca1l << 5; Martin@618: assertExec("Long << 5", Martin@617: Numbers.class, "shlL__J_3BI", Martin@617: Double.valueOf(res), Martin@617: new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, Martin@618: 5); Martin@617: } Martin@617: Martin@617: @Test public void longShiftL2() throws Exception { Martin@617: final long res = 0x00fa37d7763e0ca1l << 32; Martin@618: assertExec("Long << 32", Martin@617: Numbers.class, "shlL__J_3BI", Martin@617: Double.valueOf(res), Martin@617: new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, Martin@618: 32); Martin@617: } Martin@617: Martin@617: @Test public void longShiftL3() throws Exception { Martin@617: final long res = 0x00fa37d7763e0ca1l << 45; Martin@618: assertExec("Long << 45", Martin@617: Numbers.class, "shlL__J_3BI", Martin@617: Double.valueOf(res), Martin@617: new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, Martin@618: 45); Martin@618: } Martin@618: Martin@618: @Test public void longShiftR1() throws Exception { Martin@618: final long res = 0x00fa37d7763e0ca1l >> 5; Martin@618: assertExec("Long >> 5", Martin@618: Numbers.class, "shrL__J_3BI", Martin@618: Double.valueOf(res), Martin@618: new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, Martin@618: 5); Martin@618: } Martin@618: Martin@618: @Test public void longShiftR2() throws Exception { Martin@618: final long res = 0x00fa37d7763e0ca1l >> 32; Martin@618: assertExec("Long >> 32", Martin@618: Numbers.class, "shrL__J_3BI", Martin@618: Double.valueOf(res), Martin@618: new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, Martin@618: 32); Martin@618: } Martin@618: Martin@618: @Test public void longShiftR3() throws Exception { Martin@618: final long res = 0x00fa37d7763e0ca1l >> 45; Martin@618: assertExec("Long >> 45", Martin@618: Numbers.class, "shrL__J_3BI", Martin@618: Double.valueOf(res), Martin@618: new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, Martin@618: 45); Martin@617: } Martin@617: Martin@629: @Test public void longUShiftR1() throws Exception { Martin@629: final long res = 0x00fa37d7763e0ca1l >>> 5; Martin@629: assertExec("Long >>> 5", Martin@629: Numbers.class, "ushrL__J_3BI", Martin@629: Double.valueOf(res), Martin@629: new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, Martin@629: 5); Martin@629: } Martin@629: Martin@629: @Test public void longUShiftR2() throws Exception { Martin@629: final long res = 0x00fa37d7763e0ca1l >>> 45; Martin@629: assertExec("Long >>> 45", Martin@629: Numbers.class, "ushrL__J_3BI", Martin@629: Double.valueOf(res), Martin@629: new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, Martin@629: 45); Martin@629: } Martin@629: Martin@629: @Test public void longUShiftR3() throws Exception { Martin@629: final long res = 0xf0fa37d7763e0ca1l >>> 5; Martin@629: assertExec("Long >>> 5", Martin@629: Numbers.class, "ushrL__J_3BI", Martin@629: Double.valueOf(res), Martin@629: new byte[] { (byte)0xf0, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, Martin@629: 5); Martin@629: } Martin@629: Martin@629: @Test public void longUShiftR4() throws Exception { Martin@629: final long res = 0xf0fa37d7763e0ca1l >>> 45; Martin@629: assertExec("Long >>> 45", Martin@629: Numbers.class, "ushrL__J_3BI", Martin@629: Double.valueOf(res), Martin@629: new byte[] { (byte)0xf0, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, Martin@629: 45); Martin@629: } Martin@629: Martin@627: @Test public void longAnd() throws Exception { Martin@627: final long res = 0x00fa37d7763e0ca1l & 0xa7b3432fff00123el; Martin@627: assertExec("LOng binary AND", Martin@627: Numbers.class, "andL__J_3B_3B", Martin@627: Double.valueOf(res), Martin@627: new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, Martin@627: new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e } Martin@627: ); Martin@627: } Martin@627: Martin@627: @Test public void longOr() throws Exception { Martin@627: final long res = 0x00fa37d7763e0ca1l | 0xa7b3432fff00123el; Martin@627: assertExec("Long binary OR", Martin@627: Numbers.class, "orL__J_3B_3B", Martin@627: Double.valueOf(res), Martin@627: new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, Martin@627: new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e } Martin@627: ); Martin@627: } Martin@627: Martin@628: @Test public void longXor1() throws Exception { Martin@628: final long res = 0x00fa37d7763e0ca1l ^ 0xa7b3432fff00123el; Martin@628: assertExec("Long binary XOR", Martin@628: Numbers.class, "xorL__J_3B_3B", Martin@628: Double.valueOf(res), Martin@628: new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, Martin@628: new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e } Martin@628: ); Martin@628: } Martin@628: Martin@628: @Test public void longXor2() throws Exception { Martin@628: final long res = 0x00fa37d7763e0ca1l ^ 0x00000000ff00123el; Martin@628: assertExec("Long binary XOR", Martin@628: Numbers.class, "xorL__J_3B_3B", Martin@628: Double.valueOf(res), Martin@628: new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, Martin@628: new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e } Martin@628: ); Martin@628: } Martin@628: Martin@628: @Test public void longXor3() throws Exception { Martin@628: final long res = 0x00000000763e0ca1l ^ 0x00000000ff00123el; Martin@628: assertExec("Long binary XOR", Martin@628: Numbers.class, "xorL__J_3B_3B", Martin@628: Double.valueOf(res), Martin@628: new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 }, Martin@628: new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e } Martin@628: ); Martin@628: } Martin@628: jaroslav@114: private static CharSequence codeSeq; jaroslav@114: private static Invocable code; jaroslav@114: jaroslav@114: @BeforeClass jaroslav@114: public void compileTheCode() throws Exception { jaroslav@114: if (codeSeq == null) { jaroslav@114: StringBuilder sb = new StringBuilder(); jaroslav@114: code = StaticMethodTest.compileClass(sb, "org/apidesign/vm4brwsr/Numbers"); jaroslav@114: codeSeq = sb; jaroslav@114: } jaroslav@114: } jaroslav@114: jaroslav@114: private static void assertExec( Martin@582: String msg, Class clazz, String method, Object expRes, Object... args) throws Exception Martin@582: { Martin@582: Object ret = TestUtils.execCode(code, codeSeq, msg, clazz, method, expRes, args); Martin@582: if (ret == null) { jaroslav@114: return; jaroslav@114: } jtulach@132: if (expRes instanceof Double && ret instanceof Double) { jtulach@132: double expD = ((Double)expRes).doubleValue(); jtulach@132: double retD = ((Double)ret).doubleValue(); Martin@616: assertEquals(retD, expD, 0.000004, msg + " " Martin@616: + StaticMethodTest.dumpJS(codeSeq)); jtulach@132: return; jtulach@132: } Martin@616: assertEquals(ret, expRes, msg + " " + StaticMethodTest.dumpJS(codeSeq)); jaroslav@114: } jaroslav@114: jaroslav@114: }