vmtest/src/test/java/org/apidesign/bck2brwsr/tck/LongArithmeticTest.java
brancharithmetic
changeset 699 6cad41d877d2
parent 698 ff57af563cb8
child 737 b2731af0357d
     1.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/LongArithmeticTest.java	Thu Feb 07 16:11:53 2013 +0100
     1.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/LongArithmeticTest.java	Thu Feb 07 17:24:19 2013 +0100
     1.3 @@ -48,7 +48,63 @@
     1.4      }
     1.5      
     1.6      private static long neg(long x) {
     1.7 -        return -x;
     1.8 +        return (-x);
     1.9 +    }
    1.10 +    
    1.11 +    private static long shl(long x, int b) {
    1.12 +        return (x << b);
    1.13 +    }
    1.14 +    
    1.15 +    private static long shr(long x, int b) {
    1.16 +        return (x >> b);
    1.17 +    }
    1.18 +    
    1.19 +    private static long ushr(long x, int b) {
    1.20 +        return (x >>> b);
    1.21 +    }
    1.22 +    
    1.23 +    private static long and(long x, long y) {
    1.24 +        return (x & y);
    1.25 +    }
    1.26 +    
    1.27 +    private static long or(long x, long y) {
    1.28 +        return (x | y);
    1.29 +    }
    1.30 +    
    1.31 +    private static long xor(long x, long y) {
    1.32 +        return (x ^ y);
    1.33 +    }
    1.34 +    
    1.35 +    public static int compare(long x, long y, int zero) {
    1.36 +        final int xyResult = compareL(x, y, zero);
    1.37 +        final int yxResult = compareL(y, x, zero);
    1.38 +
    1.39 +        return ((xyResult + yxResult) == 0) ? xyResult : -2;
    1.40 +    }
    1.41 +
    1.42 +    private static int compareL(long x, long y, int zero) {
    1.43 +        int result = -2;
    1.44 +        int trueCount = 0;
    1.45 +
    1.46 +        x += zero;
    1.47 +        if (x == y) {
    1.48 +            result = 0;
    1.49 +            ++trueCount;
    1.50 +        }
    1.51 +
    1.52 +        x += zero;
    1.53 +        if (x < y) {
    1.54 +            result = -1;
    1.55 +            ++trueCount;
    1.56 +        }
    1.57 +
    1.58 +        x += zero;
    1.59 +        if (x > y) {
    1.60 +            result = 1;
    1.61 +            ++trueCount;
    1.62 +        }
    1.63 +
    1.64 +        return (trueCount == 1) ? result : -2;
    1.65      }
    1.66      
    1.67      @Compare public long conversion() {
    1.68 @@ -195,6 +251,82 @@
    1.69          return mod(0x7fff800000000000l, 0x800000000001l);
    1.70      }
    1.71      
    1.72 +    @Compare public long shiftL1() {
    1.73 +        return shl(0x00fa37d7763e0ca1l, 5);
    1.74 +    }
    1.75 +    
    1.76 +    @Compare public long shiftL2() {
    1.77 +        return shl(0x00fa37d7763e0ca1l, 32);
    1.78 +    }
    1.79 +    
    1.80 +    @Compare public long shiftL3() {
    1.81 +        return shl(0x00fa37d7763e0ca1l, 45);
    1.82 +    }
    1.83 +    
    1.84 +    @Compare public long shiftR1() {
    1.85 +        return shr(0x00fa37d7763e0ca1l, 5);
    1.86 +    }
    1.87 +    
    1.88 +    @Compare public long shiftR2() {
    1.89 +        return shr(0x00fa37d7763e0ca1l, 32);
    1.90 +    }
    1.91 +    
    1.92 +    @Compare public long shiftR3() {
    1.93 +        return shr(0x00fa37d7763e0ca1l, 45);
    1.94 +    }
    1.95 +    
    1.96 +    @Compare public long uShiftR1() {
    1.97 +        return ushr(0x00fa37d7763e0ca1l, 5);
    1.98 +    }
    1.99 +    
   1.100 +    @Compare public long uShiftR2() {
   1.101 +        return ushr(0x00fa37d7763e0ca1l, 45);
   1.102 +    }
   1.103 +    
   1.104 +    @Compare public long uShiftR3() {
   1.105 +        return ushr(0xf0fa37d7763e0ca1l, 5);
   1.106 +    }
   1.107 +    
   1.108 +    @Compare public long uShiftR4() {
   1.109 +        return ushr(0xf0fa37d7763e0ca1l, 45);
   1.110 +    }
   1.111 +    
   1.112 +    @Compare public long and1() {
   1.113 +        return and(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
   1.114 +    }
   1.115 +    
   1.116 +    @Compare public long or1() {
   1.117 +        return or(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
   1.118 +    }
   1.119 +    
   1.120 +    @Compare public long xor1() {
   1.121 +        return xor(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
   1.122 +    }
   1.123 +    
   1.124 +    @Compare public long xor2() {
   1.125 +        return xor(0x00fa37d7763e0ca1l, 0x00000000ff00123el);
   1.126 +    }
   1.127 +    
   1.128 +    @Compare public long xor3() {
   1.129 +        return xor(0x00000000763e0ca1l, 0x00000000ff00123el);
   1.130 +    }
   1.131 +    
   1.132 +    @Compare public int compareSameNumbers() {
   1.133 +        return compare(0x0000000000000000l, 0x0000000000000000l, 0);
   1.134 +    }
   1.135 +
   1.136 +    @Compare public int comparePositiveNumbers() {
   1.137 +        return compare(0x0000000000200000l, 0x0000000010000000l, 0);
   1.138 +    }
   1.139 +
   1.140 +    @Compare public int compareNegativeNumbers() {
   1.141 +        return compare(0xffffffffffffffffl, 0xffffffff00000000l, 0);
   1.142 +    }
   1.143 +
   1.144 +    @Compare public int compareMixedNumbers() {
   1.145 +        return compare(0x8000000000000000l, 0x7fffffffffffffffl, 0);
   1.146 +    }
   1.147 +    
   1.148      @Factory
   1.149      public static Object[] create() {
   1.150          return VMTest.create(LongArithmeticTest.class);