RFR: 8345403: Add more randomized tests to better cover FloatingDecimal parsing

Chen Liang liach at openjdk.org
Wed Dec 4 00:31:38 UTC 2024


On Tue, 3 Dec 2024 18:49:43 GMT, Raffaello Giulietti <rgiulietti at openjdk.org> wrote:

> `jdk.internal.math.FloatingDecimal` parsing is mostly exercised on inputs produced by `Float.toString` and `Double.toString`, but should be extended on more random inputs.

test/jdk/jdk/internal/math/FloatingDecimal/TestRandomFloatingDecimal.java line 36:

> 34: import static org.junit.jupiter.api.Assertions.assertEquals;
> 35: 
> 36: /**

Suggestion:

/*

Jtreg directives is usually formatted as block comments, and is often placed between license header and package/imports.

test/jdk/jdk/internal/math/FloatingDecimal/TestRandomFloatingDecimal.java line 213:

> 211:             sb.append('-');
> 212:         } else if (e == 0) {
> 213:             switch (RANDOM.nextInt(4)) {  // 50% chance of tacit sign

Maybe just call `appendRandomSign(sb)` here?

test/jdk/jdk/internal/math/FloatingDecimal/TestRandomFloatingDecimal.java line 239:

> 237: 
> 238:     private static void appendZeros(StringBuilder sb, int count) {
> 239:         for (; count > 0; --count) {

Can use `sb.repeat('0', count)`

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/22523#discussion_r1868534858
PR Review Comment: https://git.openjdk.org/jdk/pull/22523#discussion_r1868533049
PR Review Comment: https://git.openjdk.org/jdk/pull/22523#discussion_r1868533468


More information about the core-libs-dev mailing list