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