rt/emul/compacttest/src/test/java/org/apidesign/bck2brwsr/tck/ShortArithmeticTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 19 Nov 2014 19:32:00 +0100
changeset 1723 3a1f262311cf
parent 1034 rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/tck/ShortArithmeticTest.java@28dc692f3b11
child 1787 ea12a3bb4b33
permissions -rw-r--r--
Separating compact profile tests into own project, so launcher.http can depend on compact profile JAR
Martin@439
     1
/**
Martin@439
     2
 * Back 2 Browser Bytecode Translator
Martin@439
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Martin@439
     4
 *
Martin@439
     5
 * This program is free software: you can redistribute it and/or modify
Martin@439
     6
 * it under the terms of the GNU General Public License as published by
Martin@439
     7
 * the Free Software Foundation, version 2 of the License.
Martin@439
     8
 *
Martin@439
     9
 * This program is distributed in the hope that it will be useful,
Martin@439
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Martin@439
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Martin@439
    12
 * GNU General Public License for more details.
Martin@439
    13
 *
Martin@439
    14
 * You should have received a copy of the GNU General Public License
Martin@439
    15
 * along with this program. Look for COPYING file in the top folder.
Martin@439
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
Martin@439
    17
 */
Martin@439
    18
package org.apidesign.bck2brwsr.tck;
Martin@439
    19
Martin@439
    20
import org.apidesign.bck2brwsr.vmtest.Compare;
Martin@439
    21
import org.apidesign.bck2brwsr.vmtest.VMTest;
Martin@439
    22
import org.testng.annotations.Factory;
Martin@439
    23
Martin@439
    24
/**
Martin@439
    25
 *
Martin@439
    26
 * @author Jaroslav Tulach <jtulach@netbeans.org>
Martin@439
    27
 */
Martin@439
    28
public class ShortArithmeticTest {
Martin@439
    29
    
Martin@439
    30
    private static short add(short x, short y) {
Martin@439
    31
        return (short)(x + y);
Martin@439
    32
    }
Martin@439
    33
    
Martin@439
    34
    private static short sub(short x, short y) {
Martin@439
    35
        return (short)(x - y);
Martin@439
    36
    }
Martin@439
    37
    
Martin@439
    38
    private static short mul(short x, short y) {
Martin@439
    39
        return (short)(x * y);
Martin@439
    40
    }
Martin@439
    41
    
Martin@439
    42
    private static short div(short x, short y) {
Martin@439
    43
        return (short)(x / y);
Martin@439
    44
    }
Martin@439
    45
    
Martin@439
    46
    private static short mod(short x, short y) {
Martin@439
    47
        return (short)(x % y);
Martin@439
    48
    }
Martin@439
    49
    
Martin@439
    50
    @Compare public short conversion() {
Martin@439
    51
        return (short)123456;
Martin@439
    52
    }
Martin@439
    53
    
Martin@439
    54
    @Compare public short addOverflow() {
Martin@439
    55
        return add(Short.MAX_VALUE, (short)1);
Martin@439
    56
    }
Martin@439
    57
    
Martin@439
    58
    @Compare public short subUnderflow() {
Martin@439
    59
        return sub(Short.MIN_VALUE, (short)1);
Martin@439
    60
    }
Martin@439
    61
    
Martin@439
    62
    @Compare public short addMaxShortAndMaxShort() {
Martin@439
    63
        return add(Short.MAX_VALUE, Short.MAX_VALUE);
Martin@439
    64
    }
Martin@439
    65
    
Martin@439
    66
    @Compare public short subMinShortAndMinShort() {
Martin@439
    67
        return sub(Short.MIN_VALUE, Short.MIN_VALUE);
Martin@439
    68
    }
Martin@439
    69
    
Martin@439
    70
    @Compare public short multiplyMaxShort() {
Martin@439
    71
        return mul(Short.MAX_VALUE, (short)2);
Martin@439
    72
    }
Martin@439
    73
    
Martin@439
    74
    @Compare public short multiplyMaxShortAndMaxShort() {
Martin@439
    75
        return mul(Short.MAX_VALUE, Short.MAX_VALUE);
Martin@439
    76
    }
Martin@439
    77
    
Martin@439
    78
    @Compare public short multiplyMinShort() {
Martin@439
    79
        return mul(Short.MIN_VALUE, (short)2);
Martin@439
    80
    }
Martin@439
    81
    
Martin@439
    82
    @Compare public short multiplyMinShortAndMinShort() {
Martin@439
    83
        return mul(Short.MIN_VALUE, Short.MIN_VALUE);
Martin@439
    84
    }
Martin@439
    85
    
Martin@439
    86
    @Compare public short multiplyPrecision() {
Martin@439
    87
        return mul((short)17638, (short)1103);
Martin@439
    88
    }
Martin@439
    89
    
Martin@439
    90
    @Compare public short division() {
Martin@439
    91
        return div((short)1, (short)2);
Martin@439
    92
    }
Martin@439
    93
    
Martin@439
    94
    @Compare public short divisionReminder() {
Martin@439
    95
        return mod((short)1, (short)2);
Martin@439
    96
    }
Martin@439
    97
    
Martin@439
    98
    @Factory
Martin@439
    99
    public static Object[] create() {
Martin@439
   100
        return VMTest.create(ShortArithmeticTest.class);
Martin@439
   101
    }
Martin@439
   102
}