vmtest/src/test/java/org/apidesign/bck2brwsr/tck/IntegerArithmeticTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 26 Jan 2013 08:47:05 +0100
changeset 592 5e13b1ac2886
parent 454 6506c5925775
child 700 b9bf26ea0118
permissions -rw-r--r--
In order to support fields of the same name in subclasses we are now prefixing them with name of the class that defines them. To provide convenient way to access them from generated bytecode and also directly from JavaScript, there is a getter/setter function for each field. It starts with _ followed by the field name. If called with a parameter, it sets the field, with a parameter it just returns it.
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@427
    18
package org.apidesign.bck2brwsr.tck;
Martin@345
    19
Martin@427
    20
import org.apidesign.bck2brwsr.vmtest.Compare;
Martin@427
    21
import org.apidesign.bck2brwsr.vmtest.VMTest;
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@352
    42
    private static int div(int x, int y) {
Martin@352
    43
        return x / y;
Martin@352
    44
    }
Martin@352
    45
    
Martin@352
    46
    private static int mod(int x, int y) {
Martin@352
    47
        return x % y;
Martin@352
    48
    }
Martin@352
    49
    
Martin@351
    50
    @Compare public int addOverflow() {
Martin@351
    51
        return add(Integer.MAX_VALUE, 1);
Martin@351
    52
    }
Martin@351
    53
    
Martin@351
    54
    @Compare public int subUnderflow() {
Martin@351
    55
        return sub(Integer.MIN_VALUE, 1);
Martin@351
    56
    }
Martin@351
    57
    
Martin@351
    58
    @Compare public int addMaxIntAndMaxInt() {
Martin@351
    59
        return add(Integer.MAX_VALUE, Integer.MAX_VALUE);
Martin@351
    60
    }
Martin@351
    61
    
Martin@351
    62
    @Compare public int subMinIntAndMinInt() {
Martin@351
    63
        return sub(Integer.MIN_VALUE, Integer.MIN_VALUE);
Martin@345
    64
    }
Martin@345
    65
    
Martin@345
    66
    @Compare public int multiplyMaxInt() {
Martin@351
    67
        return mul(Integer.MAX_VALUE, 2);
Martin@351
    68
    }
Martin@351
    69
    
Martin@351
    70
    @Compare public int multiplyMaxIntAndMaxInt() {
Martin@351
    71
        return mul(Integer.MAX_VALUE, Integer.MAX_VALUE);
Martin@351
    72
    }
Martin@351
    73
    
Martin@351
    74
    @Compare public int multiplyMinInt() {
Martin@351
    75
        return mul(Integer.MIN_VALUE, 2);
Martin@351
    76
    }
Martin@351
    77
    
Martin@351
    78
    @Compare public int multiplyMinIntAndMinInt() {
Martin@351
    79
        return mul(Integer.MIN_VALUE, Integer.MIN_VALUE);
Martin@351
    80
    }
Martin@351
    81
    
Martin@351
    82
    @Compare public int multiplyPrecision() {
Martin@351
    83
        return mul(119106029, 1103515245);
Martin@345
    84
    }
Martin@345
    85
    
Martin@352
    86
    @Compare public int division() {
Martin@352
    87
        return div(1, 2);
Martin@352
    88
    }
Martin@352
    89
    
Martin@352
    90
    @Compare public int divisionReminder() {
Martin@352
    91
        return mod(1, 2);
Martin@352
    92
    }
Martin@352
    93
    
jaroslav@454
    94
    @Compare public int sumTwoDimensions() {
jaroslav@454
    95
        int[][] matrix = createMatrix(4, 3);
jaroslav@457
    96
        matrix[0][0] += 10;
jaroslav@457
    97
        return matrix[0][0];
jaroslav@454
    98
    }
jaroslav@454
    99
    
jaroslav@454
   100
    static int[][] createMatrix(int x, int y) {
jaroslav@457
   101
        return new int[x][y];
jaroslav@454
   102
    }
jaroslav@454
   103
    
Martin@345
   104
    @Factory
Martin@345
   105
    public static Object[] create() {
Martin@427
   106
        return VMTest.create(IntegerArithmeticTest.class);
Martin@345
   107
    }
Martin@345
   108
}