Skip to content

Commit

Permalink
8313621: test/jdk/jdk/internal/math/FloatingDecimal/TestFloatingDecim…
Browse files Browse the repository at this point in the history
…al should use RandomFactory

Reviewed-by: rgiulietti
  • Loading branch information
Brian Burkhalter committed Oct 30, 2023
1 parent 4679e9a commit 864a876
Showing 1 changed file with 41 additions and 108 deletions.
149 changes: 41 additions & 108 deletions test/jdk/jdk/internal/math/FloatingDecimal/TestFloatingDecimal.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -24,6 +24,12 @@
import java.util.Random;
import jdk.internal.math.FloatingDecimal;

import jdk.test.lib.RandomFactory;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

/*
OldFloatingDecimalForTest
Expand Down Expand Up @@ -57,48 +63,35 @@ public class jdk.internal.math.FloatingDecimal {
/**
* @test
* @bug 7032154
* @summary unit tests of FloatingDecimal
* @summary unit tests of FloatingDecimal (use -Dseed=X to set PRANDOM seed)
* @modules java.base/jdk.internal.math
* @library ..
* @library /test/lib
* @library /java/lang/Math
* @build jdk.test.lib.RandomFactory
* @build DoubleConsts FloatConsts
* @run main TestFloatingDecimal
* @run junit TestFloatingDecimal
* @author Brian Burkhalter
* @key randomness
*/
public class TestFloatingDecimal {
private static enum ResultType {
RESULT_EXCEPTION,
RESULT_PRINT
}
private static final int NUM_RANDOM_TESTS = 100_000;

private static final ResultType RESULT_TYPE = ResultType.RESULT_PRINT;
private static final int NUM_RANDOM_TESTS = 100000;

private static final Random RANDOM = new Random();

private static void result(String message) {
switch (RESULT_TYPE) {
case RESULT_EXCEPTION:
throw new RuntimeException(message);
case RESULT_PRINT:
System.err.println(message);
break;
default:
assert false;
}
}
private static final Random RANDOM = RandomFactory.getRandom();

private static int check(String test, Object expected, Object actual) {
int failures = 0;
if(!actual.equals(expected)) {
failures++;
result("Test "+test+" expected "+expected+" but obtained "+actual);
System.err.println("Test " + test +
" expected " + expected +
" but obtained " + actual);
}
return failures;
}

private static int testAppendToDouble() {
System.out.println(" testAppendToDouble");
@Test
public void testAppendToDouble() {
int failures = 0;

for(int i = 0; i < NUM_RANDOM_TESTS; i++) {
Expand All @@ -119,11 +112,11 @@ private static int testAppendToDouble() {
}
}

return failures;
assertEquals(0, failures);
}

private static int testAppendToFloat() {
System.out.println(" testAppendToFloat");
@Test
public void testAppendToFloat() {
int failures = 0;

for(int i = 0; i < NUM_RANDOM_TESTS; i++) {
Expand All @@ -144,21 +137,11 @@ private static int testAppendToFloat() {
}
}

return failures;
assertEquals(0, failures);
}

private static int testAppendTo() {
System.out.println("testAppendTo");
int failures = 0;

failures += testAppendToDouble();
failures += testAppendToFloat();

return failures;
}

private static int testParseDouble() {
System.out.println(" testParseDouble");
@Test
public void testParseDouble() {
int failures = 0;

for(int i = 0; i < NUM_RANDOM_TESTS; i++) {
Expand All @@ -177,11 +160,11 @@ private static int testParseDouble() {
}
}

return failures;
assertEquals(0, failures);
}

private static int testParseFloat() {
System.out.println(" testParseFloat");
@Test
public void testParseFloat() {
int failures = 0;

for(int i = 0; i < NUM_RANDOM_TESTS; i++) {
Expand All @@ -200,21 +183,11 @@ private static int testParseFloat() {
}
}

return failures;
}

private static int testParse() {
System.out.println("testParse");
int failures = 0;

failures += testParseDouble();
failures += testParseFloat();

return failures;
assertEquals(0, failures);
}

private static int testToJavaFormatStringDoubleFixed() {
System.out.println(" testToJavaFormatStringDoubleFixed");
@Test
public void testToJavaFormatStringDoubleFixed() {
int failures = 0;

double[] d = new double [] {
Expand All @@ -228,11 +201,11 @@ private static int testToJavaFormatStringDoubleFixed() {
failures += check("testToJavaFormatStringDoubleFixed", ofd.toJavaFormatString(), FloatingDecimal.toJavaFormatString(d[i]));
}

return failures;
assertEquals(0, failures);
}

private static int testToJavaFormatStringDoubleRandom() {
System.out.println(" testToJavaFormatStringDoubleRandom");
@Test
public void testToJavaFormatStringDoubleRandom() {
int failures = 0;

for(int i = 0; i < NUM_RANDOM_TESTS; i++) {
Expand All @@ -247,19 +220,11 @@ private static int testToJavaFormatStringDoubleRandom() {
}
}

return failures;
assertEquals(0, failures);
}

private static int testToJavaFormatStringDouble() {
System.out.println(" testToJavaFormatStringDouble");
int failures = 0;
failures += testToJavaFormatStringDoubleFixed();
failures += testToJavaFormatStringDoubleRandom();
return failures;
}

private static int testToJavaFormatStringFloatFixed() {
System.out.println(" testToJavaFormatStringFloatFixed");
@Test
public void testToJavaFormatStringFloatFixed() {
int failures = 0;

float[] f = new float[] {
Expand All @@ -273,11 +238,11 @@ private static int testToJavaFormatStringFloatFixed() {
failures += check("testToJavaFormatStringFloatFixed", ofd.toJavaFormatString(), FloatingDecimal.toJavaFormatString(f[i]));
}

return failures;
assertEquals(0, failures);
}

private static int testToJavaFormatStringFloatRandom() {
System.out.println(" testToJavaFormatStringFloatRandom");
@Test
public void testToJavaFormatStringFloatRandom() {
int failures = 0;

for(int i = 0; i < NUM_RANDOM_TESTS; i++) {
Expand All @@ -292,38 +257,6 @@ private static int testToJavaFormatStringFloatRandom() {
}
}

return failures;
}

private static int testToJavaFormatStringFloat() {
System.out.println(" testToJavaFormatStringFloat");
int failures = 0;

failures += testToJavaFormatStringFloatFixed();
failures += testToJavaFormatStringFloatRandom();

return failures;
}

private static int testToJavaFormatString() {
System.out.println("testToJavaFormatString");
int failures = 0;

failures += testToJavaFormatStringDouble();
failures += testToJavaFormatStringFloat();

return failures;
}

public static void main(String[] args) {
int failures = 0;

failures += testAppendTo();
failures += testParse();
failures += testToJavaFormatString();

if (failures != 0) {
throw new RuntimeException("" + failures + " failures while testing FloatingDecimal");
}
assertEquals(0, failures);
}
}

7 comments on commit 864a876

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SoniaZaldana
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk21u

@openjdk
Copy link

@openjdk openjdk bot commented on 864a876 Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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:

Hi all,

This pull request contains a backport of commit 864a876e from the openjdk/jdk repository.

The commit being backported was authored by Brian Burkhalter on 30 Oct 2023 and was reviewed by Raffaello Giulietti.

Thanks!

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:

$ git fetch https://github.com/openjdk-bots/jdk21u.git backport-SoniaZaldana-864a876e:backport-SoniaZaldana-864a876e
$ git checkout backport-SoniaZaldana-864a876e
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u.git backport-SoniaZaldana-864a876e

@SoniaZaldana
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 864a876 Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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:

Hi all,

This pull request contains a backport of commit 864a876e from the openjdk/jdk repository.

The commit being backported was authored by Brian Burkhalter on 30 Oct 2023 and was reviewed by Raffaello Giulietti.

Thanks!

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:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-SoniaZaldana-864a876e:backport-SoniaZaldana-864a876e
$ git checkout backport-SoniaZaldana-864a876e
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-SoniaZaldana-864a876e

@SoniaZaldana
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 864a876 Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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:

Hi all,

This pull request contains a backport of commit 864a876e from the openjdk/jdk repository.

The commit being backported was authored by Brian Burkhalter on 30 Oct 2023 and was reviewed by Raffaello Giulietti.

Thanks!

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:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev.git backport-SoniaZaldana-864a876e:backport-SoniaZaldana-864a876e
$ git checkout backport-SoniaZaldana-864a876e
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev.git backport-SoniaZaldana-864a876e

Please sign in to comment.