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@698
|
50 |
private static long neg(long x) {
|
Martin@698
|
51 |
return -x;
|
Martin@698
|
52 |
}
|
Martin@698
|
53 |
|
Martin@582
|
54 |
@Compare public long conversion() {
|
Martin@582
|
55 |
return Long.MAX_VALUE;
|
Martin@582
|
56 |
}
|
Martin@582
|
57 |
|
Martin@698
|
58 |
@Compare public long negate1() {
|
Martin@698
|
59 |
return neg(0x00fa37d7763e0ca1l);
|
Martin@698
|
60 |
}
|
Martin@698
|
61 |
|
Martin@698
|
62 |
@Compare public long negate2() {
|
Martin@698
|
63 |
return neg(0x80fa37d7763e0ca1l);
|
Martin@698
|
64 |
}
|
Martin@698
|
65 |
|
Martin@698
|
66 |
@Compare public long negate3() {
|
Martin@698
|
67 |
return neg(0xfffffffffffffeddl);
|
Martin@698
|
68 |
}
|
Martin@698
|
69 |
|
Martin@582
|
70 |
@Compare public long addOverflow() {
|
Martin@582
|
71 |
return add(Long.MAX_VALUE, 1l);
|
Martin@582
|
72 |
}
|
Martin@698
|
73 |
|
Martin@582
|
74 |
@Compare public long subUnderflow() {
|
Martin@582
|
75 |
return sub(Long.MIN_VALUE, 1l);
|
Martin@582
|
76 |
}
|
Martin@698
|
77 |
|
Martin@582
|
78 |
@Compare public long addMaxLongAndMaxLong() {
|
Martin@582
|
79 |
return add(Long.MAX_VALUE, Long.MAX_VALUE);
|
Martin@582
|
80 |
}
|
Martin@582
|
81 |
|
Martin@582
|
82 |
@Compare public long subMinLongAndMinLong() {
|
Martin@582
|
83 |
return sub(Long.MIN_VALUE, Long.MIN_VALUE);
|
Martin@582
|
84 |
}
|
Martin@582
|
85 |
|
Martin@698
|
86 |
@Compare public long subMinLongAndMaxLong() {
|
Martin@698
|
87 |
return sub(Long.MIN_VALUE, Long.MAX_VALUE);
|
Martin@698
|
88 |
}
|
Martin@698
|
89 |
|
Martin@582
|
90 |
@Compare public long multiplyMaxLong() {
|
Martin@582
|
91 |
return mul(Long.MAX_VALUE, 2l);
|
Martin@582
|
92 |
}
|
Martin@582
|
93 |
|
Martin@582
|
94 |
@Compare public long multiplyMaxLongAndMaxLong() {
|
Martin@582
|
95 |
return mul(Long.MAX_VALUE, Long.MAX_VALUE);
|
Martin@582
|
96 |
}
|
Martin@582
|
97 |
|
Martin@582
|
98 |
@Compare public long multiplyMinLong() {
|
Martin@582
|
99 |
return mul(Long.MIN_VALUE, 2l);
|
Martin@582
|
100 |
}
|
Martin@582
|
101 |
|
Martin@582
|
102 |
@Compare public long multiplyMinLongAndMinLong() {
|
Martin@582
|
103 |
return mul(Long.MIN_VALUE, Long.MIN_VALUE);
|
Martin@582
|
104 |
}
|
Martin@582
|
105 |
|
Martin@582
|
106 |
@Compare public long multiplyPrecision() {
|
Martin@698
|
107 |
return mul(0x00fa37d7763e0ca1l, 0xa7b3432fff00123el);
|
Martin@582
|
108 |
}
|
Martin@582
|
109 |
|
Martin@698
|
110 |
@Compare public long divideSmallPositiveNumbers() {
|
Martin@698
|
111 |
return div(0xabcdef, 0x123);
|
Martin@582
|
112 |
}
|
Martin@698
|
113 |
|
Martin@698
|
114 |
@Compare public long divideSmallNegativeNumbers() {
|
Martin@698
|
115 |
return div(-0xabcdef, -0x123);
|
Martin@582
|
116 |
}
|
Martin@698
|
117 |
|
Martin@698
|
118 |
@Compare public long divideSmallMixedNumbers() {
|
Martin@698
|
119 |
return div(0xabcdef, -0x123);
|
Martin@698
|
120 |
}
|
Martin@698
|
121 |
|
Martin@698
|
122 |
@Compare public long dividePositiveNumbersOneDigitDenom() {
|
Martin@698
|
123 |
return div(0xabcdef0102ffffl, 0x654);
|
Martin@698
|
124 |
}
|
Martin@698
|
125 |
|
Martin@698
|
126 |
@Compare public long divideNegativeNumbersOneDigitDenom() {
|
Martin@698
|
127 |
return div(-0xabcdef0102ffffl, -0x654);
|
Martin@698
|
128 |
}
|
Martin@698
|
129 |
|
Martin@698
|
130 |
@Compare public long divideMixedNumbersOneDigitDenom() {
|
Martin@698
|
131 |
return div(-0xabcdef0102ffffl, 0x654);
|
Martin@698
|
132 |
}
|
Martin@698
|
133 |
|
Martin@698
|
134 |
@Compare public long dividePositiveNumbersMultiDigitDenom() {
|
Martin@698
|
135 |
return div(0x7ffefc003322aabbl, 0x89ab1000l);
|
Martin@698
|
136 |
}
|
Martin@698
|
137 |
|
Martin@698
|
138 |
@Compare public long divideNegativeNumbersMultiDigitDenom() {
|
Martin@698
|
139 |
return div(-0x7ffefc003322aabbl, -0x123489ab1001l);
|
Martin@698
|
140 |
}
|
Martin@698
|
141 |
|
Martin@698
|
142 |
@Compare public long divideMixedNumbersMultiDigitDenom() {
|
Martin@698
|
143 |
return div(0x7ffefc003322aabbl, -0x38f49b0b7574e36l);
|
Martin@698
|
144 |
}
|
Martin@698
|
145 |
|
Martin@698
|
146 |
@Compare public long divideWithOverflow() {
|
Martin@698
|
147 |
return div(0x8000fffe0000l, 0x8000ffffl);
|
Martin@698
|
148 |
}
|
Martin@698
|
149 |
|
Martin@698
|
150 |
@Compare public long divideWithCorrection() {
|
Martin@698
|
151 |
return div(0x7fff800000000000l, 0x800000000001l);
|
Martin@698
|
152 |
}
|
Martin@698
|
153 |
|
Martin@698
|
154 |
@Compare public long moduloSmallPositiveNumbers() {
|
Martin@698
|
155 |
return mod(0xabcdef, 0x123);
|
Martin@698
|
156 |
}
|
Martin@698
|
157 |
|
Martin@698
|
158 |
@Compare public long moduloSmallNegativeNumbers() {
|
Martin@698
|
159 |
return mod(-0xabcdef, -0x123);
|
Martin@698
|
160 |
}
|
Martin@698
|
161 |
|
Martin@698
|
162 |
@Compare public long moduloSmallMixedNumbers() {
|
Martin@698
|
163 |
return mod(0xabcdef, -0x123);
|
Martin@698
|
164 |
}
|
Martin@698
|
165 |
|
Martin@698
|
166 |
@Compare public long moduloPositiveNumbersOneDigitDenom() {
|
Martin@698
|
167 |
return mod(0xabcdef0102ffffl, 0x654);
|
Martin@698
|
168 |
}
|
Martin@698
|
169 |
|
Martin@698
|
170 |
@Compare public long moduloNegativeNumbersOneDigitDenom() {
|
Martin@698
|
171 |
return mod(-0xabcdef0102ffffl, -0x654);
|
Martin@698
|
172 |
}
|
Martin@698
|
173 |
|
Martin@698
|
174 |
@Compare public long moduloMixedNumbersOneDigitDenom() {
|
Martin@698
|
175 |
return mod(-0xabcdef0102ffffl, 0x654);
|
Martin@698
|
176 |
}
|
Martin@698
|
177 |
|
Martin@698
|
178 |
@Compare public long moduloPositiveNumbersMultiDigitDenom() {
|
Martin@698
|
179 |
return mod(0x7ffefc003322aabbl, 0x89ab1000l);
|
Martin@698
|
180 |
}
|
Martin@698
|
181 |
|
Martin@698
|
182 |
@Compare public long moduloNegativeNumbersMultiDigitDenom() {
|
Martin@698
|
183 |
return mod(-0x7ffefc003322aabbl, -0x123489ab1001l);
|
Martin@698
|
184 |
}
|
Martin@698
|
185 |
|
Martin@698
|
186 |
@Compare public long moduloMixedNumbersMultiDigitDenom() {
|
Martin@698
|
187 |
return mod(0x7ffefc003322aabbl, -0x38f49b0b7574e36l);
|
Martin@698
|
188 |
}
|
Martin@698
|
189 |
|
Martin@698
|
190 |
@Compare public long moduloWithOverflow() {
|
Martin@698
|
191 |
return mod(0x8000fffe0000l, 0x8000ffffl);
|
Martin@698
|
192 |
}
|
Martin@698
|
193 |
|
Martin@698
|
194 |
@Compare public long moduloWithCorrection() {
|
Martin@698
|
195 |
return mod(0x7fff800000000000l, 0x800000000001l);
|
Martin@698
|
196 |
}
|
Martin@582
|
197 |
|
Martin@582
|
198 |
@Factory
|
Martin@582
|
199 |
public static Object[] create() {
|
Martin@582
|
200 |
return VMTest.create(LongArithmeticTest.class);
|
Martin@582
|
201 |
}
|
Martin@582
|
202 |
}
|