vmtest/src/test/java/org/apidesign/bck2brwsr/tck/LongArithmeticTest.java
author Martin Soch <Martin.Soch@oracle.com>
Fri, 25 Jan 2013 11:00:52 +0100
brancharithmetic
changeset 582 8e546d108658
child 698 ff57af563cb8
permissions -rw-r--r--
Long arithmetic prototype, Long currently represented by separate JavaScript object with two JS-Numbers.
Just few operation implemented to pass tests. Tests under vmtest directory are still failing.
Martin@582
     1
/**
Martin@582
     2
 * Back 2 Browser Bytecode Translator
Martin@582
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Martin@582
     4
 *
Martin@582
     5
 * This program is free software: you can redistribute it and/or modify
Martin@582
     6
 * it under the terms of the GNU General Public License as published by
Martin@582
     7
 * the Free Software Foundation, version 2 of the License.
Martin@582
     8
 *
Martin@582
     9
 * This program is distributed in the hope that it will be useful,
Martin@582
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Martin@582
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Martin@582
    12
 * GNU General Public License for more details.
Martin@582
    13
 *
Martin@582
    14
 * You should have received a copy of the GNU General Public License
Martin@582
    15
 * along with this program. Look for COPYING file in the top folder.
Martin@582
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
Martin@582
    17
 */
Martin@582
    18
package org.apidesign.bck2brwsr.tck;
Martin@582
    19
Martin@582
    20
import org.apidesign.bck2brwsr.vmtest.Compare;
Martin@582
    21
import org.apidesign.bck2brwsr.vmtest.VMTest;
Martin@582
    22
import org.testng.annotations.Factory;
Martin@582
    23
Martin@582
    24
/**
Martin@582
    25
 *
Martin@582
    26
 * @author Jaroslav Tulach <jtulach@netbeans.org>
Martin@582
    27
 */
Martin@582
    28
public class LongArithmeticTest {
Martin@582
    29
    
Martin@582
    30
    private static long add(long x, long y) {
Martin@582
    31
        return (x + y);
Martin@582
    32
    }
Martin@582
    33
    
Martin@582
    34
    private static long sub(long x, long y) {
Martin@582
    35
        return (x - y);
Martin@582
    36
    }
Martin@582
    37
    
Martin@582
    38
    private static long mul(long x, long y) {
Martin@582
    39
        return (x * y);
Martin@582
    40
    }
Martin@582
    41
    
Martin@582
    42
    private static long div(long x, long y) {
Martin@582
    43
        return (x / y);
Martin@582
    44
    }
Martin@582
    45
    
Martin@582
    46
    private static long mod(long x, long y) {
Martin@582
    47
        return (x % y);
Martin@582
    48
    }
Martin@582
    49
    
Martin@582
    50
    @Compare public long conversion() {
Martin@582
    51
        return Long.MAX_VALUE;
Martin@582
    52
    }
Martin@582
    53
    
Martin@582
    54
    /*
Martin@582
    55
    @Compare public long addOverflow() {
Martin@582
    56
        return add(Long.MAX_VALUE, 1l);
Martin@582
    57
    }
Martin@582
    58
    
Martin@582
    59
    @Compare public long subUnderflow() {
Martin@582
    60
        return sub(Long.MIN_VALUE, 1l);
Martin@582
    61
    }
Martin@582
    62
    
Martin@582
    63
    @Compare public long addMaxLongAndMaxLong() {
Martin@582
    64
        return add(Long.MAX_VALUE, Long.MAX_VALUE);
Martin@582
    65
    }
Martin@582
    66
    
Martin@582
    67
    @Compare public long subMinLongAndMinLong() {
Martin@582
    68
        return sub(Long.MIN_VALUE, Long.MIN_VALUE);
Martin@582
    69
    }
Martin@582
    70
    
Martin@582
    71
    @Compare public long multiplyMaxLong() {
Martin@582
    72
        return mul(Long.MAX_VALUE, 2l);
Martin@582
    73
    }
Martin@582
    74
    
Martin@582
    75
    @Compare public long multiplyMaxLongAndMaxLong() {
Martin@582
    76
        return mul(Long.MAX_VALUE, Long.MAX_VALUE);
Martin@582
    77
    }
Martin@582
    78
    
Martin@582
    79
    @Compare public long multiplyMinLong() {
Martin@582
    80
        return mul(Long.MIN_VALUE, 2l);
Martin@582
    81
    }
Martin@582
    82
    
Martin@582
    83
    @Compare public long multiplyMinLongAndMinLong() {
Martin@582
    84
        return mul(Long.MIN_VALUE, Long.MIN_VALUE);
Martin@582
    85
    }
Martin@582
    86
    
Martin@582
    87
    @Compare public long multiplyPrecision() {
Martin@582
    88
        return mul(17638l, 1103l);
Martin@582
    89
    }
Martin@582
    90
    
Martin@582
    91
    @Compare public long division() {
Martin@582
    92
        return div(1l, 2l);
Martin@582
    93
    }
Martin@582
    94
    
Martin@582
    95
    @Compare public long divisionReminder() {
Martin@582
    96
        return mod(1l, 2l);
Martin@582
    97
    }
Martin@582
    98
    */
Martin@582
    99
    
Martin@582
   100
    @Factory
Martin@582
   101
    public static Object[] create() {
Martin@582
   102
        return VMTest.create(LongArithmeticTest.class);
Martin@582
   103
    }
Martin@582
   104
}