jaroslav@106
|
1 |
/**
|
jaroslav@106
|
2 |
* Back 2 Browser Bytecode Translator
|
jaroslav@1787
|
3 |
* Copyright (C) 2012-2015 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
|
jaroslav@106
|
4 |
*
|
jaroslav@106
|
5 |
* This program is free software: you can redistribute it and/or modify
|
jaroslav@106
|
6 |
* it under the terms of the GNU General Public License as published by
|
jaroslav@106
|
7 |
* the Free Software Foundation, version 2 of the License.
|
jaroslav@106
|
8 |
*
|
jaroslav@106
|
9 |
* This program is distributed in the hope that it will be useful,
|
jaroslav@106
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
jaroslav@106
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
jaroslav@106
|
12 |
* GNU General Public License for more details.
|
jaroslav@106
|
13 |
*
|
jaroslav@106
|
14 |
* You should have received a copy of the GNU General Public License
|
jaroslav@106
|
15 |
* along with this program. Look for COPYING file in the top folder.
|
jaroslav@106
|
16 |
* If not, see http://opensource.org/licenses/GPL-2.0.
|
jaroslav@106
|
17 |
*/
|
jaroslav@22
|
18 |
package org.apidesign.vm4brwsr;
|
jaroslav@0
|
19 |
|
jaroslav@789
|
20 |
import org.testng.annotations.AfterClass;
|
jaroslav@103
|
21 |
import org.testng.annotations.BeforeClass;
|
jaroslav@0
|
22 |
import org.testng.annotations.Test;
|
jaroslav@0
|
23 |
|
jaroslav@1773
|
24 |
/** Checks behavior on Math class.
|
jaroslav@0
|
25 |
*
|
jaroslav@0
|
26 |
* @author Jaroslav Tulach <jtulach@netbeans.org>
|
jaroslav@0
|
27 |
*/
|
jaroslav@1773
|
28 |
public class MathTest {
|
jaroslav@600
|
29 |
@Test public void rintNegativeUp() throws Exception {
|
jaroslav@600
|
30 |
final double cnts = -453904.634;
|
jaroslav@1773
|
31 |
assertExec("Should round up to end with 5", mathClass(), "rint__DD",
|
jaroslav@600
|
32 |
-453905.0, cnts
|
jaroslav@600
|
33 |
);
|
jaroslav@600
|
34 |
}
|
jaroslav@600
|
35 |
|
jaroslav@1773
|
36 |
protected Class<?> mathClass() {
|
jaroslav@1773
|
37 |
return Math.class;
|
jaroslav@1773
|
38 |
}
|
jaroslav@1773
|
39 |
|
jaroslav@600
|
40 |
@Test public void rintNegativeDown() throws Exception {
|
jaroslav@600
|
41 |
final double cnts = -453904.434;
|
jaroslav@1773
|
42 |
assertExec("Should round up to end with 4", mathClass(), "rint__DD",
|
jaroslav@600
|
43 |
-453904.0, cnts
|
jaroslav@600
|
44 |
);
|
jaroslav@600
|
45 |
}
|
jaroslav@600
|
46 |
|
jaroslav@600
|
47 |
@Test public void rintPositiveUp() throws Exception {
|
jaroslav@600
|
48 |
final double cnts = 453904.634;
|
jaroslav@1773
|
49 |
assertExec("Should round up to end with 5", mathClass(), "rint__DD",
|
jaroslav@600
|
50 |
453905.0, cnts
|
jaroslav@600
|
51 |
);
|
jaroslav@600
|
52 |
}
|
jaroslav@600
|
53 |
@Test public void rintPositiveDown() throws Exception {
|
jaroslav@600
|
54 |
final double cnts = 453904.434;
|
jaroslav@1773
|
55 |
assertExec("Should round up to end with 4", mathClass(), "rint__DD",
|
jaroslav@600
|
56 |
453904.0, cnts
|
jaroslav@600
|
57 |
);
|
jaroslav@600
|
58 |
}
|
jaroslav@600
|
59 |
@Test public void rintOneHalf() throws Exception {
|
jaroslav@600
|
60 |
final double cnts = 1.5;
|
jaroslav@1773
|
61 |
assertExec("Should round up to end with 2", mathClass(), "rint__DD",
|
jaroslav@600
|
62 |
2.0, cnts
|
jaroslav@600
|
63 |
);
|
jaroslav@600
|
64 |
}
|
jaroslav@600
|
65 |
@Test public void rintNegativeOneHalf() throws Exception {
|
jaroslav@600
|
66 |
final double cnts = -1.5;
|
jaroslav@1773
|
67 |
assertExec("Should round up to end with 2", mathClass(), "rint__DD",
|
jaroslav@600
|
68 |
-2.0, cnts
|
jaroslav@600
|
69 |
);
|
jaroslav@600
|
70 |
}
|
jaroslav@600
|
71 |
@Test public void rintTwoAndHalf() throws Exception {
|
jaroslav@600
|
72 |
final double cnts = 2.5;
|
jaroslav@1773
|
73 |
assertExec("Should round up to end with 2", mathClass(), "rint__DD",
|
jaroslav@600
|
74 |
2.0, cnts
|
jaroslav@600
|
75 |
);
|
jaroslav@600
|
76 |
}
|
jaroslav@600
|
77 |
@Test public void rintNegativeTwoOneHalf() throws Exception {
|
jaroslav@600
|
78 |
final double cnts = -2.5;
|
jaroslav@1773
|
79 |
assertExec("Should round up to end with 2", mathClass(), "rint__DD",
|
jaroslav@600
|
80 |
-2.0, cnts
|
jaroslav@600
|
81 |
);
|
jaroslav@600
|
82 |
}
|
jaroslav@3
|
83 |
|
jaroslav@605
|
84 |
@Test public void ieeeReminder1() throws Exception {
|
jaroslav@1773
|
85 |
assertExec("Same result 1", mathClass(), "IEEEremainder__DDD",
|
jaroslav@605
|
86 |
Math.IEEEremainder(10.0, 4.5), 10.0, 4.5
|
jaroslav@605
|
87 |
);
|
jaroslav@605
|
88 |
}
|
jaroslav@605
|
89 |
|
jaroslav@605
|
90 |
@Test public void ieeeReminder2() throws Exception {
|
jaroslav@1773
|
91 |
assertExec("Same result 1", mathClass(), "IEEEremainder__DDD",
|
jaroslav@605
|
92 |
Math.IEEEremainder(Integer.MAX_VALUE, -4.5), Integer.MAX_VALUE, -4.5
|
jaroslav@605
|
93 |
);
|
jaroslav@605
|
94 |
}
|
jaroslav@605
|
95 |
|
jaroslav@708
|
96 |
private static TestVM code;
|
jaroslav@103
|
97 |
|
jaroslav@103
|
98 |
@BeforeClass
|
jaroslav@789
|
99 |
public static void compileTheCode() throws Exception {
|
jaroslav@103
|
100 |
StringBuilder sb = new StringBuilder();
|
jaroslav@1773
|
101 |
code = TestVM.compileClass(sb);
|
jaroslav@2
|
102 |
}
|
jaroslav@789
|
103 |
@AfterClass
|
jaroslav@789
|
104 |
public static void releaseTheCode() {
|
jaroslav@789
|
105 |
code = null;
|
jaroslav@789
|
106 |
}
|
jaroslav@2
|
107 |
|
jaroslav@708
|
108 |
private void assertExec(
|
jaroslav@708
|
109 |
String msg, Class<?> clazz, String method,
|
jaroslav@708
|
110 |
Object ret, Object... args
|
jaroslav@708
|
111 |
) throws Exception {
|
jaroslav@708
|
112 |
code.assertExec(msg, clazz, method, ret, args);
|
jaroslav@298
|
113 |
}
|
jaroslav@1773
|
114 |
|
jaroslav@0
|
115 |
}
|