vm/src/test/java/org/apidesign/vm4brwsr/tck/IntegerArithmeticTest.java
author Martin Soch <Martin.Soch@oracle.com>
Tue, 18 Dec 2012 20:19:11 +0100
brancharithmetic
changeset 351 b7459b10d581
parent 345 f954edc48431
child 352 c0fd4e7919b3
permissions -rw-r--r--
Added test for + - * operations in int32 arithmetic, updated JS generator to produce code for correct int32 arithmetic.
Martin@345
     1
/**
Martin@345
     2
 * Back 2 Browser Bytecode Translator
Martin@345
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Martin@345
     4
 *
Martin@345
     5
 * This program is free software: you can redistribute it and/or modify
Martin@345
     6
 * it under the terms of the GNU General Public License as published by
Martin@345
     7
 * the Free Software Foundation, version 2 of the License.
Martin@345
     8
 *
Martin@345
     9
 * This program is distributed in the hope that it will be useful,
Martin@345
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Martin@345
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Martin@345
    12
 * GNU General Public License for more details.
Martin@345
    13
 *
Martin@345
    14
 * You should have received a copy of the GNU General Public License
Martin@345
    15
 * along with this program. Look for COPYING file in the top folder.
Martin@345
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
Martin@345
    17
 */
Martin@345
    18
package org.apidesign.vm4brwsr.tck;
Martin@345
    19
Martin@345
    20
import org.apidesign.vm4brwsr.Compare;
Martin@345
    21
import org.apidesign.vm4brwsr.CompareVMs;
Martin@345
    22
import org.testng.annotations.Factory;
Martin@345
    23
Martin@345
    24
/**
Martin@345
    25
 *
Martin@345
    26
 * @author Jaroslav Tulach <jtulach@netbeans.org>
Martin@345
    27
 */
Martin@345
    28
public class IntegerArithmeticTest {
Martin@345
    29
    
Martin@351
    30
    private static int add(int x, int y) {
Martin@351
    31
        return x + y;
Martin@345
    32
    }
Martin@345
    33
    
Martin@351
    34
    private static int sub(int x, int y) {
Martin@351
    35
        return x - y;
Martin@345
    36
    }
Martin@345
    37
    
Martin@351
    38
    private static int mul(int x, int y) {
Martin@351
    39
        return x * y;
Martin@351
    40
    }
Martin@351
    41
    
Martin@351
    42
    @Compare public int addOverflow() {
Martin@351
    43
        return add(Integer.MAX_VALUE, 1);
Martin@351
    44
    }
Martin@351
    45
    
Martin@351
    46
    @Compare public int subUnderflow() {
Martin@351
    47
        return sub(Integer.MIN_VALUE, 1);
Martin@351
    48
    }
Martin@351
    49
    
Martin@351
    50
    @Compare public int addMaxIntAndMaxInt() {
Martin@351
    51
        return add(Integer.MAX_VALUE, Integer.MAX_VALUE);
Martin@351
    52
    }
Martin@351
    53
    
Martin@351
    54
    @Compare public int subMinIntAndMinInt() {
Martin@351
    55
        return sub(Integer.MIN_VALUE, Integer.MIN_VALUE);
Martin@345
    56
    }
Martin@345
    57
    
Martin@345
    58
    @Compare public int multiplyMaxInt() {
Martin@351
    59
        return mul(Integer.MAX_VALUE, 2);
Martin@351
    60
    }
Martin@351
    61
    
Martin@351
    62
    @Compare public int multiplyMaxIntAndMaxInt() {
Martin@351
    63
        return mul(Integer.MAX_VALUE, Integer.MAX_VALUE);
Martin@351
    64
    }
Martin@351
    65
    
Martin@351
    66
    @Compare public int multiplyMinInt() {
Martin@351
    67
        return mul(Integer.MIN_VALUE, 2);
Martin@351
    68
    }
Martin@351
    69
    
Martin@351
    70
    @Compare public int multiplyMinIntAndMinInt() {
Martin@351
    71
        return mul(Integer.MIN_VALUE, Integer.MIN_VALUE);
Martin@351
    72
    }
Martin@351
    73
    
Martin@351
    74
    @Compare public int multiplyPrecision() {
Martin@351
    75
        return mul(119106029, 1103515245);
Martin@345
    76
    }
Martin@345
    77
    
Martin@345
    78
    @Factory
Martin@345
    79
    public static Object[] create() {
Martin@345
    80
        return CompareVMs.create(IntegerArithmeticTest.class);
Martin@345
    81
    }
Martin@345
    82
}