Added test for Long << arithmetic
authorMartin Soch <Martin.Soch@oracle.com>
Thu, 31 Jan 2013 13:55:12 +0100
brancharithmetic
changeset 617960e219425e2
parent 616 9cbf1f2ad7ee
child 618 171fa0ca3add
Added test for Long <<
vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java
vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java
     1.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java	Thu Jan 31 13:42:14 2013 +0100
     1.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java	Thu Jan 31 13:55:12 2013 +0100
     1.3 @@ -171,6 +171,36 @@
     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 MAX",
    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 +    
    1.17 +    @Test public void longShiftL2() throws Exception {
    1.18 +        final long res = 0x00fa37d7763e0ca1l << 32;
    1.19 +        assertExec("Long MAX",
    1.20 +            Numbers.class, "shlL__J_3BI", 
    1.21 +            Double.valueOf(res),
    1.22 +                new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
    1.23 +                32
    1.24 +        );
    1.25 +    }
    1.26 +    
    1.27 +    @Test public void longShiftL3() throws Exception {
    1.28 +        final long res = 0x00fa37d7763e0ca1l << 45;
    1.29 +        assertExec("Long MAX",
    1.30 +            Numbers.class, "shlL__J_3BI", 
    1.31 +            Double.valueOf(res),
    1.32 +                new byte[] { (byte)0x00, (byte)0xfa, (byte)0x37, (byte)0xd7, (byte)0x76, (byte)0x3e, (byte)0x0c, (byte)0xa1 },
    1.33 +                45
    1.34 +        );
    1.35 +    }
    1.36 +    
    1.37      private static CharSequence codeSeq;
    1.38      private static Invocable code;
    1.39  
     2.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java	Thu Jan 31 13:42:14 2013 +0100
     2.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java	Thu Jan 31 13:55:12 2013 +0100
     2.3 @@ -95,4 +95,16 @@
     2.4      public static long modL(long x, long y) {
     2.5          return (x % y);
     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  }