vmtest/src/test/java/org/apidesign/bck2brwsr/tck/LongArithmeticTest.java
author Martin Soch <Martin.Soch@oracle.com>
Thu, 07 Feb 2013 16:11:53 +0100
brancharithmetic
changeset 698 ff57af563cb8
parent 582 8e546d108658
child 699 6cad41d877d2
permissions -rw-r--r--
Fix issue with Long.MIN_VALUE in Number.toExactString
Moved the first part of tests from vm/.../NumberTests to vmtest/.../LongArithmeticTest
     1 /**
     2  * Back 2 Browser Bytecode Translator
     3  * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     4  *
     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.
     8  *
     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.
    13  *
    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.
    17  */
    18 package org.apidesign.bck2brwsr.tck;
    19 
    20 import org.apidesign.bck2brwsr.vmtest.Compare;
    21 import org.apidesign.bck2brwsr.vmtest.VMTest;
    22 import org.testng.annotations.Factory;
    23 
    24 /**
    25  *
    26  * @author Jaroslav Tulach <jtulach@netbeans.org>
    27  */
    28 public class LongArithmeticTest {
    29     
    30     private static long add(long x, long y) {
    31         return (x + y);
    32     }
    33     
    34     private static long sub(long x, long y) {
    35         return (x - y);
    36     }
    37     
    38     private static long mul(long x, long y) {
    39         return (x * y);
    40     }
    41     
    42     private static long div(long x, long y) {
    43         return (x / y);
    44     }
    45     
    46     private static long mod(long x, long y) {
    47         return (x % y);
    48     }
    49     
    50     private static long neg(long x) {
    51         return -x;
    52     }
    53     
    54     @Compare public long conversion() {
    55         return Long.MAX_VALUE;
    56     }
    57     
    58     @Compare public long negate1() {
    59         return neg(0x00fa37d7763e0ca1l);
    60     }
    61     
    62     @Compare public long negate2() {
    63         return neg(0x80fa37d7763e0ca1l);
    64     }
    65 
    66     @Compare public long negate3() {
    67         return neg(0xfffffffffffffeddl);
    68     }
    69 
    70     @Compare public long addOverflow() {
    71         return add(Long.MAX_VALUE, 1l);
    72     }
    73 
    74     @Compare public long subUnderflow() {
    75         return sub(Long.MIN_VALUE, 1l);
    76     }
    77 
    78     @Compare public long addMaxLongAndMaxLong() {
    79         return add(Long.MAX_VALUE, Long.MAX_VALUE);
    80     }
    81     
    82     @Compare public long subMinLongAndMinLong() {
    83         return sub(Long.MIN_VALUE, Long.MIN_VALUE);
    84     }
    85     
    86     @Compare public long subMinLongAndMaxLong() {
    87         return sub(Long.MIN_VALUE, Long.MAX_VALUE);
    88     }
    89 
    90     @Compare public long multiplyMaxLong() {
    91         return mul(Long.MAX_VALUE, 2l);
    92     }
    93     
    94     @Compare public long multiplyMaxLongAndMaxLong() {
    95         return mul(Long.MAX_VALUE, Long.MAX_VALUE);
    96     }
    97     
    98     @Compare public long multiplyMinLong() {
    99         return mul(Long.MIN_VALUE, 2l);
   100     }
   101     
   102     @Compare public long multiplyMinLongAndMinLong() {
   103         return mul(Long.MIN_VALUE, Long.MIN_VALUE);
   104     }
   105     
   106     @Compare public long multiplyPrecision() {
   107         return mul(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
   108     }
   109     
   110     @Compare public long divideSmallPositiveNumbers() {
   111         return div(0xabcdef, 0x123);
   112     }
   113 
   114     @Compare public long divideSmallNegativeNumbers() {
   115         return div(-0xabcdef, -0x123);
   116     }
   117 
   118     @Compare public long divideSmallMixedNumbers() {
   119         return div(0xabcdef, -0x123);
   120     }
   121 
   122     @Compare public long dividePositiveNumbersOneDigitDenom() {
   123         return div(0xabcdef0102ffffl, 0x654);
   124     }
   125 
   126     @Compare public long divideNegativeNumbersOneDigitDenom() {
   127         return div(-0xabcdef0102ffffl, -0x654);
   128     }
   129 
   130     @Compare public long divideMixedNumbersOneDigitDenom() {
   131         return div(-0xabcdef0102ffffl, 0x654);
   132     }
   133 
   134     @Compare public long dividePositiveNumbersMultiDigitDenom() {
   135         return div(0x7ffefc003322aabbl, 0x89ab1000l);
   136     }
   137 
   138     @Compare public long divideNegativeNumbersMultiDigitDenom() {
   139         return div(-0x7ffefc003322aabbl, -0x123489ab1001l);
   140     }
   141 
   142     @Compare public long divideMixedNumbersMultiDigitDenom() {
   143         return div(0x7ffefc003322aabbl, -0x38f49b0b7574e36l);
   144     }
   145 
   146     @Compare public long divideWithOverflow() {
   147         return div(0x8000fffe0000l, 0x8000ffffl);
   148     }
   149 
   150     @Compare public long divideWithCorrection() {
   151         return div(0x7fff800000000000l, 0x800000000001l);
   152     }
   153 
   154     @Compare public long moduloSmallPositiveNumbers() {
   155         return mod(0xabcdef, 0x123);
   156     }
   157 
   158     @Compare public long moduloSmallNegativeNumbers() {
   159         return mod(-0xabcdef, -0x123);
   160     }
   161 
   162     @Compare public long moduloSmallMixedNumbers() {
   163         return mod(0xabcdef, -0x123);
   164     }
   165 
   166     @Compare public long moduloPositiveNumbersOneDigitDenom() {
   167         return mod(0xabcdef0102ffffl, 0x654);
   168     }
   169 
   170     @Compare public long moduloNegativeNumbersOneDigitDenom() {
   171         return mod(-0xabcdef0102ffffl, -0x654);
   172     }
   173 
   174     @Compare public long moduloMixedNumbersOneDigitDenom() {
   175         return mod(-0xabcdef0102ffffl, 0x654);
   176     }
   177 
   178     @Compare public long moduloPositiveNumbersMultiDigitDenom() {
   179         return mod(0x7ffefc003322aabbl, 0x89ab1000l);
   180     }
   181 
   182     @Compare public long moduloNegativeNumbersMultiDigitDenom() {
   183         return mod(-0x7ffefc003322aabbl, -0x123489ab1001l);
   184     }
   185 
   186     @Compare public long moduloMixedNumbersMultiDigitDenom() {
   187         return mod(0x7ffefc003322aabbl, -0x38f49b0b7574e36l);
   188     }
   189 
   190     @Compare public long moduloWithOverflow() {
   191         return mod(0x8000fffe0000l, 0x8000ffffl);
   192     }
   193 
   194     @Compare public long moduloWithCorrection() {
   195         return mod(0x7fff800000000000l, 0x800000000001l);
   196     }
   197     
   198     @Factory
   199     public static Object[] create() {
   200         return VMTest.create(LongArithmeticTest.class);
   201     }
   202 }