Final part of Long tests moved from vm/.../NumberTest to vmtest/.../LongArithmeticTest
1.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java Thu Feb 07 16:11:53 2013 +0100
1.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java Thu Feb 07 17:24:19 2013 +0100
1.3 @@ -144,186 +144,6 @@
1.4 );
1.5 }
1.6
1.7 - @Test public void longShiftL1() throws Exception {
1.8 - final long res = 0x00fa37d7763e0ca1l << 5;
1.9 - assertExec("Long << 5",
1.10 - Numbers.class, "shlL__J_3BI",
1.11 - Double.valueOf(res),
1.12 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
1.13 - 5);
1.14 - }
1.15 -
1.16 - @Test public void longShiftL2() throws Exception {
1.17 - final long res = 0x00fa37d7763e0ca1l << 32;
1.18 - assertExec("Long << 32",
1.19 - Numbers.class, "shlL__J_3BI",
1.20 - Double.valueOf(res),
1.21 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
1.22 - 32);
1.23 - }
1.24 -
1.25 - @Test public void longShiftL3() throws Exception {
1.26 - final long res = 0x00fa37d7763e0ca1l << 45;
1.27 - assertExec("Long << 45",
1.28 - Numbers.class, "shlL__J_3BI",
1.29 - Double.valueOf(res),
1.30 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
1.31 - 45);
1.32 - }
1.33 -
1.34 - @Test public void longShiftR1() throws Exception {
1.35 - final long res = 0x00fa37d7763e0ca1l >> 5;
1.36 - assertExec("Long >> 5",
1.37 - Numbers.class, "shrL__J_3BI",
1.38 - Double.valueOf(res),
1.39 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
1.40 - 5);
1.41 - }
1.42 -
1.43 - @Test public void longShiftR2() throws Exception {
1.44 - final long res = 0x00fa37d7763e0ca1l >> 32;
1.45 - assertExec("Long >> 32",
1.46 - Numbers.class, "shrL__J_3BI",
1.47 - Double.valueOf(res),
1.48 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
1.49 - 32);
1.50 - }
1.51 -
1.52 - @Test public void longShiftR3() throws Exception {
1.53 - final long res = 0x00fa37d7763e0ca1l >> 45;
1.54 - assertExec("Long >> 45",
1.55 - Numbers.class, "shrL__J_3BI",
1.56 - Double.valueOf(res),
1.57 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
1.58 - 45);
1.59 - }
1.60 -
1.61 - @Test public void longUShiftR1() throws Exception {
1.62 - final long res = 0x00fa37d7763e0ca1l >>> 5;
1.63 - assertExec("Long >>> 5",
1.64 - Numbers.class, "ushrL__J_3BI",
1.65 - Double.valueOf(res),
1.66 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
1.67 - 5);
1.68 - }
1.69 -
1.70 - @Test public void longUShiftR2() throws Exception {
1.71 - final long res = 0x00fa37d7763e0ca1l >>> 45;
1.72 - assertExec("Long >>> 45",
1.73 - Numbers.class, "ushrL__J_3BI",
1.74 - Double.valueOf(res),
1.75 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
1.76 - 45);
1.77 - }
1.78 -
1.79 - @Test public void longUShiftR3() throws Exception {
1.80 - final long res = 0xf0fa37d7763e0ca1l >>> 5;
1.81 - assertExec("Long >>> 5",
1.82 - Numbers.class, "ushrL__J_3BI",
1.83 - Double.valueOf(res),
1.84 - new byte[] { (byte)0xf0, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
1.85 - 5);
1.86 - }
1.87 -
1.88 - @Test public void longUShiftR4() throws Exception {
1.89 - final long res = 0xf0fa37d7763e0ca1l >>> 45;
1.90 - assertExec("Long >>> 45",
1.91 - Numbers.class, "ushrL__J_3BI",
1.92 - Double.valueOf(res),
1.93 - new byte[] { (byte)0xf0, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
1.94 - 45);
1.95 - }
1.96 -
1.97 - @Test public void longAnd() throws Exception {
1.98 - final long res = 0x00fa37d7763e0ca1l & 0xa7b3432fff00123el;
1.99 - assertExec("LOng binary AND",
1.100 - Numbers.class, "andL__J_3B_3B",
1.101 - Double.valueOf(res),
1.102 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
1.103 - new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
1.104 - );
1.105 - }
1.106 -
1.107 - @Test public void longOr() throws Exception {
1.108 - final long res = 0x00fa37d7763e0ca1l | 0xa7b3432fff00123el;
1.109 - assertExec("Long binary OR",
1.110 - Numbers.class, "orL__J_3B_3B",
1.111 - Double.valueOf(res),
1.112 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
1.113 - new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
1.114 - );
1.115 - }
1.116 -
1.117 - @Test public void longXor1() throws Exception {
1.118 - final long res = 0x00fa37d7763e0ca1l ^ 0xa7b3432fff00123el;
1.119 - assertExec("Long binary XOR",
1.120 - Numbers.class, "xorL__J_3B_3B",
1.121 - Double.valueOf(res),
1.122 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
1.123 - new byte[] { (byte)0xa7, (byte)0xb3, (byte)0x43, (byte)0x2f, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
1.124 - );
1.125 - }
1.126 -
1.127 - @Test public void longXor2() throws Exception {
1.128 - final long res = 0x00fa37d7763e0ca1l ^ 0x00000000ff00123el;
1.129 - assertExec("Long binary XOR",
1.130 - Numbers.class, "xorL__J_3B_3B",
1.131 - Double.valueOf(res),
1.132 - new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
1.133 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
1.134 - );
1.135 - }
1.136 -
1.137 - @Test public void longXor3() throws Exception {
1.138 - final long res = 0x00000000763e0ca1l ^ 0x00000000ff00123el;
1.139 - assertExec("Long binary XOR",
1.140 - Numbers.class, "xorL__J_3B_3B",
1.141 - Double.valueOf(res),
1.142 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
1.143 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0xff, (byte)0x00, (byte)0x12, (byte)0x3e }
1.144 - );
1.145 - }
1.146 -
1.147 - @Test public void longCompareSameNumbers() throws Exception {
1.148 - assertExec("Long compare same numbers",
1.149 - Numbers.class, "compareL__I_3B_3BI",
1.150 - 0.0,
1.151 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
1.152 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
1.153 - 0
1.154 - );
1.155 - }
1.156 -
1.157 - @Test public void longComparePositiveNumbers() throws Exception {
1.158 - assertExec("Long compare positive numbers",
1.159 - Numbers.class, "compareL__I_3B_3BI",
1.160 - -1.0,
1.161 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x20, (byte)0x00, (byte)0x00 },
1.162 - new byte[] { (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x10, (byte)0x00, (byte)0x00, (byte)0x00 },
1.163 - 0
1.164 - );
1.165 - }
1.166 -
1.167 - @Test public void longCompareNegativeNumbers() throws Exception {
1.168 - assertExec("Long compare negative numbers",
1.169 - Numbers.class, "compareL__I_3B_3BI",
1.170 - 1.0,
1.171 - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff },
1.172 - new byte[] { (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
1.173 - 0
1.174 - );
1.175 - }
1.176 -
1.177 - @Test public void longCompareMixedNumbers() throws Exception {
1.178 - assertExec("Long compare mixed numbers",
1.179 - Numbers.class, "compareL__I_3B_3BI",
1.180 - -1.0,
1.181 - new byte[] { (byte)0x80, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00 },
1.182 - new byte[] { (byte)0x7f, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff, (byte)0xff },
1.183 - 0
1.184 - );
1.185 - }
1.186 -
1.187 private static CharSequence codeSeq;
1.188 private static Invocable code;
1.189
2.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java Thu Feb 07 16:11:53 2013 +0100
2.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java Thu Feb 07 17:24:19 2013 +0100
2.3 @@ -67,86 +67,4 @@
2.4 static String floatToString() {
2.5 return new Float(7.0).toString().toString();
2.6 }
2.7 -
2.8 - public static long shlL(byte[] arrValue, int nBits) throws IOException {
2.9 - ByteArrayInputStream isValue = new ByteArrayInputStream(arrValue);
2.10 - DataInputStream disValue = new DataInputStream(isValue);
2.11 - return (disValue.readLong() << nBits);
2.12 - }
2.13 -
2.14 - public static long shrL(byte[] arrValue, int nBits) throws IOException {
2.15 - ByteArrayInputStream isValue = new ByteArrayInputStream(arrValue);
2.16 - DataInputStream disValue = new DataInputStream(isValue);
2.17 - return (disValue.readLong() >> nBits);
2.18 - }
2.19 -
2.20 - public static long ushrL(byte[] arrValue, int nBits) throws IOException {
2.21 - ByteArrayInputStream isValue = new ByteArrayInputStream(arrValue);
2.22 - DataInputStream disValue = new DataInputStream(isValue);
2.23 - return (disValue.readLong() >>> nBits);
2.24 - }
2.25 -
2.26 - public static long andL(byte[] arrX, byte[] arrY) throws IOException {
2.27 - ByteArrayInputStream isX = new ByteArrayInputStream(arrX);
2.28 - DataInputStream disX = new DataInputStream(isX);
2.29 - ByteArrayInputStream isY = new ByteArrayInputStream(arrY);
2.30 - DataInputStream disY = new DataInputStream(isY);
2.31 - return (disX.readLong() & disY.readLong());
2.32 - }
2.33 -
2.34 - public static long orL(byte[] arrX, byte[] arrY) throws IOException {
2.35 - ByteArrayInputStream isX = new ByteArrayInputStream(arrX);
2.36 - DataInputStream disX = new DataInputStream(isX);
2.37 - ByteArrayInputStream isY = new ByteArrayInputStream(arrY);
2.38 - DataInputStream disY = new DataInputStream(isY);
2.39 - return (disX.readLong() | disY.readLong());
2.40 - }
2.41 -
2.42 - public static long xorL(byte[] arrX, byte[] arrY) throws IOException {
2.43 - ByteArrayInputStream isX = new ByteArrayInputStream(arrX);
2.44 - DataInputStream disX = new DataInputStream(isX);
2.45 - ByteArrayInputStream isY = new ByteArrayInputStream(arrY);
2.46 - DataInputStream disY = new DataInputStream(isY);
2.47 - return (disX.readLong() ^ disY.readLong());
2.48 - }
2.49 -
2.50 - public static int compareL(byte[] arrX, byte[] arrY,
2.51 - int zero) throws IOException {
2.52 - ByteArrayInputStream isX = new ByteArrayInputStream(arrX);
2.53 - DataInputStream disX = new DataInputStream(isX);
2.54 - ByteArrayInputStream isY = new ByteArrayInputStream(arrY);
2.55 - DataInputStream disY = new DataInputStream(isY);
2.56 - final long x = disX.readLong();
2.57 - final long y = disY.readLong();
2.58 -
2.59 - final int xyResult = compareL(x, y, zero);
2.60 - final int yxResult = compareL(y, x, zero);
2.61 -
2.62 - return ((xyResult + yxResult) == 0) ? xyResult : -2;
2.63 - }
2.64 -
2.65 - private static int compareL(long x, long y, int zero) {
2.66 - int result = -2;
2.67 - int trueCount = 0;
2.68 -
2.69 - x += zero;
2.70 - if (x == y) {
2.71 - result = 0;
2.72 - ++trueCount;
2.73 - }
2.74 -
2.75 - x += zero;
2.76 - if (x < y) {
2.77 - result = -1;
2.78 - ++trueCount;
2.79 - }
2.80 -
2.81 - x += zero;
2.82 - if (x > y) {
2.83 - result = 1;
2.84 - ++trueCount;
2.85 - }
2.86 -
2.87 - return (trueCount == 1) ? result : -2;
2.88 - }
2.89 }
3.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/LongArithmeticTest.java Thu Feb 07 16:11:53 2013 +0100
3.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/LongArithmeticTest.java Thu Feb 07 17:24:19 2013 +0100
3.3 @@ -48,7 +48,63 @@
3.4 }
3.5
3.6 private static long neg(long x) {
3.7 - return -x;
3.8 + return (-x);
3.9 + }
3.10 +
3.11 + private static long shl(long x, int b) {
3.12 + return (x << b);
3.13 + }
3.14 +
3.15 + private static long shr(long x, int b) {
3.16 + return (x >> b);
3.17 + }
3.18 +
3.19 + private static long ushr(long x, int b) {
3.20 + return (x >>> b);
3.21 + }
3.22 +
3.23 + private static long and(long x, long y) {
3.24 + return (x & y);
3.25 + }
3.26 +
3.27 + private static long or(long x, long y) {
3.28 + return (x | y);
3.29 + }
3.30 +
3.31 + private static long xor(long x, long y) {
3.32 + return (x ^ y);
3.33 + }
3.34 +
3.35 + public static int compare(long x, long y, int zero) {
3.36 + final int xyResult = compareL(x, y, zero);
3.37 + final int yxResult = compareL(y, x, zero);
3.38 +
3.39 + return ((xyResult + yxResult) == 0) ? xyResult : -2;
3.40 + }
3.41 +
3.42 + private static int compareL(long x, long y, int zero) {
3.43 + int result = -2;
3.44 + int trueCount = 0;
3.45 +
3.46 + x += zero;
3.47 + if (x == y) {
3.48 + result = 0;
3.49 + ++trueCount;
3.50 + }
3.51 +
3.52 + x += zero;
3.53 + if (x < y) {
3.54 + result = -1;
3.55 + ++trueCount;
3.56 + }
3.57 +
3.58 + x += zero;
3.59 + if (x > y) {
3.60 + result = 1;
3.61 + ++trueCount;
3.62 + }
3.63 +
3.64 + return (trueCount == 1) ? result : -2;
3.65 }
3.66
3.67 @Compare public long conversion() {
3.68 @@ -195,6 +251,82 @@
3.69 return mod(0x7fff800000000000l, 0x800000000001l);
3.70 }
3.71
3.72 + @Compare public long shiftL1() {
3.73 + return shl(0x00fa37d7763e0ca1l, 5);
3.74 + }
3.75 +
3.76 + @Compare public long shiftL2() {
3.77 + return shl(0x00fa37d7763e0ca1l, 32);
3.78 + }
3.79 +
3.80 + @Compare public long shiftL3() {
3.81 + return shl(0x00fa37d7763e0ca1l, 45);
3.82 + }
3.83 +
3.84 + @Compare public long shiftR1() {
3.85 + return shr(0x00fa37d7763e0ca1l, 5);
3.86 + }
3.87 +
3.88 + @Compare public long shiftR2() {
3.89 + return shr(0x00fa37d7763e0ca1l, 32);
3.90 + }
3.91 +
3.92 + @Compare public long shiftR3() {
3.93 + return shr(0x00fa37d7763e0ca1l, 45);
3.94 + }
3.95 +
3.96 + @Compare public long uShiftR1() {
3.97 + return ushr(0x00fa37d7763e0ca1l, 5);
3.98 + }
3.99 +
3.100 + @Compare public long uShiftR2() {
3.101 + return ushr(0x00fa37d7763e0ca1l, 45);
3.102 + }
3.103 +
3.104 + @Compare public long uShiftR3() {
3.105 + return ushr(0xf0fa37d7763e0ca1l, 5);
3.106 + }
3.107 +
3.108 + @Compare public long uShiftR4() {
3.109 + return ushr(0xf0fa37d7763e0ca1l, 45);
3.110 + }
3.111 +
3.112 + @Compare public long and1() {
3.113 + return and(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
3.114 + }
3.115 +
3.116 + @Compare public long or1() {
3.117 + return or(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
3.118 + }
3.119 +
3.120 + @Compare public long xor1() {
3.121 + return xor(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
3.122 + }
3.123 +
3.124 + @Compare public long xor2() {
3.125 + return xor(0x00fa37d7763e0ca1l, 0x00000000ff00123el);
3.126 + }
3.127 +
3.128 + @Compare public long xor3() {
3.129 + return xor(0x00000000763e0ca1l, 0x00000000ff00123el);
3.130 + }
3.131 +
3.132 + @Compare public int compareSameNumbers() {
3.133 + return compare(0x0000000000000000l, 0x0000000000000000l, 0);
3.134 + }
3.135 +
3.136 + @Compare public int comparePositiveNumbers() {
3.137 + return compare(0x0000000000200000l, 0x0000000010000000l, 0);
3.138 + }
3.139 +
3.140 + @Compare public int compareNegativeNumbers() {
3.141 + return compare(0xffffffffffffffffl, 0xffffffff00000000l, 0);
3.142 + }
3.143 +
3.144 + @Compare public int compareMixedNumbers() {
3.145 + return compare(0x8000000000000000l, 0x7fffffffffffffffl, 0);
3.146 + }
3.147 +
3.148 @Factory
3.149 public static Object[] create() {
3.150 return VMTest.create(LongArithmeticTest.class);