1
1
/*
2
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
24
24
import java .util .Random ;
25
25
import jdk .internal .math .FloatingDecimal ;
26
26
27
+ import jdk .test .lib .RandomFactory ;
28
+
29
+ import org .junit .jupiter .api .Test ;
30
+
31
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
32
+
27
33
/*
28
34
OldFloatingDecimalForTest
29
35
@@ -57,48 +63,35 @@ public class jdk.internal.math.FloatingDecimal {
57
63
/**
58
64
* @test
59
65
* @bug 7032154
60
- * @summary unit tests of FloatingDecimal
66
+ * @summary unit tests of FloatingDecimal (use -Dseed=X to set PRANDOM seed)
61
67
* @modules java.base/jdk.internal.math
68
+ * @library ..
69
+ * @library /test/lib
62
70
* @library /java/lang/Math
71
+ * @build jdk.test.lib.RandomFactory
63
72
* @build DoubleConsts FloatConsts
64
- * @run main TestFloatingDecimal
73
+ * @run junit TestFloatingDecimal
65
74
* @author Brian Burkhalter
66
75
* @key randomness
67
76
*/
68
77
public class TestFloatingDecimal {
69
- private static enum ResultType {
70
- RESULT_EXCEPTION ,
71
- RESULT_PRINT
72
- }
78
+ private static final int NUM_RANDOM_TESTS = 100_000 ;
73
79
74
- private static final ResultType RESULT_TYPE = ResultType .RESULT_PRINT ;
75
- private static final int NUM_RANDOM_TESTS = 100000 ;
76
-
77
- private static final Random RANDOM = new Random ();
78
-
79
- private static void result (String message ) {
80
- switch (RESULT_TYPE ) {
81
- case RESULT_EXCEPTION :
82
- throw new RuntimeException (message );
83
- case RESULT_PRINT :
84
- System .err .println (message );
85
- break ;
86
- default :
87
- assert false ;
88
- }
89
- }
80
+ private static final Random RANDOM = RandomFactory .getRandom ();
90
81
91
82
private static int check (String test , Object expected , Object actual ) {
92
83
int failures = 0 ;
93
84
if (!actual .equals (expected )) {
94
85
failures ++;
95
- result ("Test " +test +" expected " +expected +" but obtained " +actual );
86
+ System .err .println ("Test " + test +
87
+ " expected " + expected +
88
+ " but obtained " + actual );
96
89
}
97
90
return failures ;
98
91
}
99
92
100
- private static int testAppendToDouble () {
101
- System . out . println ( " testAppendToDouble" );
93
+ @ Test
94
+ public void testAppendToDouble () {
102
95
int failures = 0 ;
103
96
104
97
for (int i = 0 ; i < NUM_RANDOM_TESTS ; i ++) {
@@ -119,11 +112,11 @@ private static int testAppendToDouble() {
119
112
}
120
113
}
121
114
122
- return failures ;
115
+ assertEquals ( 0 , failures ) ;
123
116
}
124
117
125
- private static int testAppendToFloat () {
126
- System . out . println ( " testAppendToFloat" );
118
+ @ Test
119
+ public void testAppendToFloat () {
127
120
int failures = 0 ;
128
121
129
122
for (int i = 0 ; i < NUM_RANDOM_TESTS ; i ++) {
@@ -144,21 +137,11 @@ private static int testAppendToFloat() {
144
137
}
145
138
}
146
139
147
- return failures ;
140
+ assertEquals ( 0 , failures ) ;
148
141
}
149
142
150
- private static int testAppendTo () {
151
- System .out .println ("testAppendTo" );
152
- int failures = 0 ;
153
-
154
- failures += testAppendToDouble ();
155
- failures += testAppendToFloat ();
156
-
157
- return failures ;
158
- }
159
-
160
- private static int testParseDouble () {
161
- System .out .println (" testParseDouble" );
143
+ @ Test
144
+ public void testParseDouble () {
162
145
int failures = 0 ;
163
146
164
147
for (int i = 0 ; i < NUM_RANDOM_TESTS ; i ++) {
@@ -177,11 +160,11 @@ private static int testParseDouble() {
177
160
}
178
161
}
179
162
180
- return failures ;
163
+ assertEquals ( 0 , failures ) ;
181
164
}
182
165
183
- private static int testParseFloat () {
184
- System . out . println ( " testParseFloat" );
166
+ @ Test
167
+ public void testParseFloat () {
185
168
int failures = 0 ;
186
169
187
170
for (int i = 0 ; i < NUM_RANDOM_TESTS ; i ++) {
@@ -200,21 +183,11 @@ private static int testParseFloat() {
200
183
}
201
184
}
202
185
203
- return failures ;
204
- }
205
-
206
- private static int testParse () {
207
- System .out .println ("testParse" );
208
- int failures = 0 ;
209
-
210
- failures += testParseDouble ();
211
- failures += testParseFloat ();
212
-
213
- return failures ;
186
+ assertEquals (0 , failures );
214
187
}
215
188
216
- private static int testToJavaFormatStringDoubleFixed () {
217
- System . out . println ( " testToJavaFormatStringDoubleFixed" );
189
+ @ Test
190
+ public void testToJavaFormatStringDoubleFixed () {
218
191
int failures = 0 ;
219
192
220
193
double [] d = new double [] {
@@ -228,11 +201,11 @@ private static int testToJavaFormatStringDoubleFixed() {
228
201
failures += check ("testToJavaFormatStringDoubleFixed" , ofd .toJavaFormatString (), FloatingDecimal .toJavaFormatString (d [i ]));
229
202
}
230
203
231
- return failures ;
204
+ assertEquals ( 0 , failures ) ;
232
205
}
233
206
234
- private static int testToJavaFormatStringDoubleRandom () {
235
- System . out . println ( " testToJavaFormatStringDoubleRandom" );
207
+ @ Test
208
+ public void testToJavaFormatStringDoubleRandom () {
236
209
int failures = 0 ;
237
210
238
211
for (int i = 0 ; i < NUM_RANDOM_TESTS ; i ++) {
@@ -247,19 +220,11 @@ private static int testToJavaFormatStringDoubleRandom() {
247
220
}
248
221
}
249
222
250
- return failures ;
223
+ assertEquals ( 0 , failures ) ;
251
224
}
252
225
253
- private static int testToJavaFormatStringDouble () {
254
- System .out .println (" testToJavaFormatStringDouble" );
255
- int failures = 0 ;
256
- failures += testToJavaFormatStringDoubleFixed ();
257
- failures += testToJavaFormatStringDoubleRandom ();
258
- return failures ;
259
- }
260
-
261
- private static int testToJavaFormatStringFloatFixed () {
262
- System .out .println (" testToJavaFormatStringFloatFixed" );
226
+ @ Test
227
+ public void testToJavaFormatStringFloatFixed () {
263
228
int failures = 0 ;
264
229
265
230
float [] f = new float [] {
@@ -273,11 +238,11 @@ private static int testToJavaFormatStringFloatFixed() {
273
238
failures += check ("testToJavaFormatStringFloatFixed" , ofd .toJavaFormatString (), FloatingDecimal .toJavaFormatString (f [i ]));
274
239
}
275
240
276
- return failures ;
241
+ assertEquals ( 0 , failures ) ;
277
242
}
278
243
279
- private static int testToJavaFormatStringFloatRandom () {
280
- System . out . println ( " testToJavaFormatStringFloatRandom" );
244
+ @ Test
245
+ public void testToJavaFormatStringFloatRandom () {
281
246
int failures = 0 ;
282
247
283
248
for (int i = 0 ; i < NUM_RANDOM_TESTS ; i ++) {
@@ -292,38 +257,6 @@ private static int testToJavaFormatStringFloatRandom() {
292
257
}
293
258
}
294
259
295
- return failures ;
296
- }
297
-
298
- private static int testToJavaFormatStringFloat () {
299
- System .out .println (" testToJavaFormatStringFloat" );
300
- int failures = 0 ;
301
-
302
- failures += testToJavaFormatStringFloatFixed ();
303
- failures += testToJavaFormatStringFloatRandom ();
304
-
305
- return failures ;
306
- }
307
-
308
- private static int testToJavaFormatString () {
309
- System .out .println ("testToJavaFormatString" );
310
- int failures = 0 ;
311
-
312
- failures += testToJavaFormatStringDouble ();
313
- failures += testToJavaFormatStringFloat ();
314
-
315
- return failures ;
316
- }
317
-
318
- public static void main (String [] args ) {
319
- int failures = 0 ;
320
-
321
- failures += testAppendTo ();
322
- failures += testParse ();
323
- failures += testToJavaFormatString ();
324
-
325
- if (failures != 0 ) {
326
- throw new RuntimeException ("" + failures + " failures while testing FloatingDecimal" );
327
- }
260
+ assertEquals (0 , failures );
328
261
}
329
262
}
7 commit comments
openjdk-notifier[bot] commentedon Oct 30, 2023
Review
Issues
SoniaZaldana commentedon Dec 12, 2023
/backport jdk21u
openjdk[bot] commentedon Dec 12, 2023
@SoniaZaldana the backport was successfully created on the branch backport-SoniaZaldana-864a876e in my personal fork of openjdk/jdk21u. To create a pull request with this backport targeting openjdk/jdk21u:master, just click the following link:
➡️ Create pull request
The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:
If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u:
SoniaZaldana commentedon Dec 13, 2023
/backport jdk21u-dev
openjdk[bot] commentedon Dec 13, 2023
@SoniaZaldana the backport was successfully created on the branch backport-SoniaZaldana-864a876e in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:
➡️ Create pull request
The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:
If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:
SoniaZaldana commentedon Dec 15, 2023
/backport jdk17u-dev
openjdk[bot] commentedon Dec 15, 2023
@SoniaZaldana the backport was successfully created on the branch backport-SoniaZaldana-864a876e in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:
➡️ Create pull request
The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:
If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev: