Skip to content

Commit

Permalink
Remove 'supplemental test data' from unit tests.
Browse files Browse the repository at this point in the history
Fix CI scripts.
  • Loading branch information
wrandelshofer committed Dec 10, 2023
1 parent fc6e16c commit 17cbfcc
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 166 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest ]
java: [ 20 ]
java: [ 21 ]
arch: [ x64 ]
dist: [ zulu ]
fail-fast: false
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/maven-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '11'
java-version: '21'
distribution: 'temurin'
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
settings-path: ${{ github.workspace }} # location for the settings.xml file
Expand Down
1 change: 1 addition & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,8 @@
*/
package ch.randelshofer.fastdoubleparser;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

public abstract class AbstractFloatValueParserTest {
protected boolean longRunningTests = !"false".equals(System.getProperty("enableLongRunningTests"));
Expand Down Expand Up @@ -122,78 +116,6 @@ protected List<NumberTestData> createDataForSignificandDigitsInputClasses() {
);
}

enum NumberType {
FLOAT16, FLOAT32, FLOAT64
}

protected Stream<NumberTestData> createSupplementalTestData(NumberType type) {
try {
return
Files.walk(Paths.get("../supplemental_test_files/data"))
.filter(path -> path.getFileName().toString().endsWith(".txt"))
.map(path1 -> createSupplementalTestData(path1, type))
.reduce(Stream.empty(), Stream::concat);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

protected Stream<Path> getSupplementalTestDataFiles() {
if (longRunningTests) {
try {
return Files.walk(Paths.get("../supplemental_test_files/data"))
.filter(path -> path.getFileName().toString().endsWith(".txt"));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
return Stream.empty();
}


/**
* Reads a text file. Each line has the following format:
* <pre>
* float16 bits (4 hex digits)
* │ float32 bits (8 hex digits)
* │ │ float64 bits (16 hex digits)
* │ │ │ input string
* ↓ ↓ ↓ ↓
* 0000 00000000 0000000000000000 .0
* </pre>
*
* @param path path to text file
* @return A stream of {@link NumberTestData}.
*/
protected Stream<NumberTestData> createSupplementalTestData(Path path, NumberType type) {
try {
@SuppressWarnings("resource")
Stream<String> lines = Files.lines(path);
String fileName = path.getFileName().toString();
int[] lineNumber = {1};
return lines.map(line -> {
String[] fields = line.split(" ");
Number number;
switch (type) {
case FLOAT16:
number = Short.parseShort(fields[0], 16);
break;
case FLOAT32:
number = Float.intBitsToFloat(Integer.parseInt(fields[1], 16));
break;
case FLOAT64:
number = Double.longBitsToDouble(Long.parseLong(fields[2], 16));
break;
default:
throw new IllegalArgumentException();
}
return new NumberTestData(fileName + " " + lineNumber[0]++ + " " + fields[3], fields[3], number);
});
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}


protected List<NumberTestData> createDataWithVeryLongInputStrings() {
return Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.junit.jupiter.api.DynamicNode;
import org.junit.jupiter.api.TestFactory;

import java.nio.file.Path;
import java.util.Objects;
import java.util.function.ToDoubleFunction;
import java.util.stream.Stream;
Expand Down Expand Up @@ -42,14 +41,9 @@ public Stream<DynamicNode> dynamicTests_parseDouble_CharSequence_int_int() {
@TestFactory
public Stream<DynamicNode> dynamicTests_parseDouble_CharSequence_int_int_longRunningTests() {
ToDoubleFunction<NumberTestData> lambda = u -> JavaDoubleParser.parseDouble(u.input(), u.charOffset(), u.charLength());
return Stream.concat(
getSupplementalTestDataFiles()
.map(t -> dynamicTest(t.getFileName().toString(),
() -> testFile(t, lambda))),
createLongRunningDoubleTestData()
return createLongRunningDoubleTestData()
.map(t -> dynamicTest(t.title(),
() -> test(t, lambda)))
);
() -> test(t, lambda)));
}

@TestFactory
Expand All @@ -72,14 +66,9 @@ public Stream<DynamicNode> dynamicTests_parseDouble_byteArray_int_int() {
@TestFactory
public Stream<DynamicNode> dynamicTests_parseDouble_byteArray_int_int_longRunningTests() {
ToDoubleFunction<NumberTestData> lambda = u -> JavaDoubleParser.parseDouble(toByteArray(u.input()), u.charOffset(), u.charLength());
return Stream.concat(
getSupplementalTestDataFiles()
.map(t -> dynamicTest(t.getFileName().toString(),
() -> testFile(t, lambda))),
createLongRunningDoubleTestData()
return createLongRunningDoubleTestData()
.map(t -> dynamicTest(t.title(),
() -> test(t, lambda)))
);
() -> test(t, lambda)));
}

@TestFactory
Expand All @@ -102,19 +91,9 @@ public Stream<DynamicNode> dynamicTests_parseDouble_charArray_int_int() {
@TestFactory
public Stream<DynamicNode> dynamicTests_parseDouble_charArray_int_int_longRunningTests() {
ToDoubleFunction<NumberTestData> lambda = u -> JavaDoubleParser.parseDouble(toCharArray(u.input()), u.charOffset(), u.charLength());
return Stream.concat(
getSupplementalTestDataFiles()
.map(t -> dynamicTest(t.getFileName().toString(),
() -> testFile(t, lambda))),
createLongRunningDoubleTestData()
return createLongRunningDoubleTestData()
.map(t -> dynamicTest(t.title(),
() -> test(t, lambda)))
);
}

protected void testFile(Path path, ToDoubleFunction<NumberTestData> f) {
createSupplementalTestData(path, NumberType.FLOAT64)
.forEach(d -> test(d, f));
() -> test(t, lambda)));
}

private void test(NumberTestData d, ToDoubleFunction<NumberTestData> f) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.junit.jupiter.api.DynamicNode;
import org.junit.jupiter.api.TestFactory;

import java.nio.file.Path;
import java.util.Objects;
import java.util.stream.Stream;

Expand Down Expand Up @@ -43,14 +42,9 @@ public Stream<DynamicNode> dynamicTests_parseFloat_CharSequence_Int_Int() {
@TestFactory
public Stream<DynamicNode> dynamicTests_parseFloat_CharSequence_int_int_longRunningTests() {
ToFloatFunction<NumberTestData> lambda = u -> JavaFloatParser.parseFloat((u.input()), u.charOffset(), u.charLength());
return Stream.concat(
getSupplementalTestDataFiles()
.map(t -> dynamicTest(t.getFileName().toString(),
() -> testFile(t, lambda))),
createLongRunningFloatTestData()
return createLongRunningFloatTestData()
.map(t -> dynamicTest(t.title(),
() -> test(t, lambda)))
);
() -> test(t, lambda)));
}

@TestFactory
Expand All @@ -76,14 +70,9 @@ public Stream<DynamicNode> dynamicTests_parseFloat_byteArray_int_int() {
@TestFactory
public Stream<DynamicNode> dynamicTests_parseFloat_byteArray_int_int_longRunningTests() {
ToFloatFunction<NumberTestData> lambda = u -> JavaFloatParser.parseFloat(toByteArray(u.input()), u.charOffset(), u.charLength());
return Stream.concat(
getSupplementalTestDataFiles()
.map(t -> dynamicTest(t.getFileName().toString(),
() -> testFile(t, lambda))),
createLongRunningFloatTestData()
return createLongRunningFloatTestData()
.map(t -> dynamicTest(t.title(),
() -> test(t, lambda)))
);
() -> test(t, lambda)));
}

@TestFactory
Expand All @@ -107,19 +96,9 @@ public Stream<DynamicNode> dynamicTests_parseFloat_charArray_int_int() {
@TestFactory
public Stream<DynamicNode> dynamicTests_parseFloat_charArray_int_int_longRunningTests() {
ToFloatFunction<NumberTestData> lambda = u -> JavaFloatParser.parseFloat(toCharArray(u.input()), u.charOffset(), u.charLength());
return Stream.concat(
getSupplementalTestDataFiles()
.map(t -> dynamicTest(t.getFileName().toString(),
() -> testFile(t, lambda))),
createLongRunningFloatTestData()
return createLongRunningFloatTestData()
.map(t -> dynamicTest(t.title(),
() -> test(t, lambda)))
);
}

protected void testFile(Path path, ToFloatFunction<NumberTestData> f) {
createSupplementalTestData(path, NumberType.FLOAT32)
.forEach(d -> test(d, f));
() -> test(t, lambda)));
}

protected void test(NumberTestData d, ToFloatFunction<NumberTestData> f) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.junit.jupiter.api.TestFactory;

import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.Objects;
import java.util.function.ToDoubleFunction;
import java.util.stream.Stream;
Expand Down Expand Up @@ -44,14 +43,9 @@ public Stream<DynamicNode> dynamicTests_parseDouble_CharSequence_int_int() {
@TestFactory
public Stream<DynamicNode> dynamicTests_parseDouble_CharSequence_int_int_longRunningTest() {
ToDoubleFunction<NumberTestData> lambda = u -> JsonDoubleParser.parseDouble((u.input()), u.charOffset(), u.charLength());
return Stream.concat(
getSupplementalTestDataFiles()
.map(t -> dynamicTest(t.getFileName().toString(),
() -> testFile(t, lambda))),
createLongRunningTestData()
return createLongRunningTestData()
.map(t -> dynamicTest(t.title(),
() -> test(t, lambda)))
);
() -> test(t, lambda)));
}

@TestFactory
Expand All @@ -74,14 +68,9 @@ public Stream<DynamicNode> dynamicTests_parseDouble_ByteArray_int_int() {
@TestFactory
public Stream<DynamicNode> dynamicTests_parseDouble_ByteArray_int_int_longRunningTests() {
ToDoubleFunction<NumberTestData> lambda = u -> JsonDoubleParser.parseDouble(toByteArray(u.input()), u.charOffset(), u.charLength());
return Stream.concat(
getSupplementalTestDataFiles()
.map(t -> dynamicTest(t.getFileName().toString(),
() -> testFile(t, lambda))),
createLongRunningTestData()
return createLongRunningTestData()
.map(t -> dynamicTest(t.title(),
() -> test(t, lambda)))
);
() -> test(t, lambda)));
}

@TestFactory
Expand All @@ -104,19 +93,9 @@ public Stream<DynamicNode> dynamicTests_parseDouble_charArray_int_int() {
@TestFactory
public Stream<DynamicNode> dynamicTests_parseDouble_charArray_int_int_longRunningTests() {
ToDoubleFunction<NumberTestData> lambda = u -> JsonDoubleParser.parseDouble(toCharArray(u.input()), u.charOffset(), u.charLength());
return Stream.concat(
getSupplementalTestDataFiles()
.map(t -> dynamicTest(t.getFileName().toString(),
() -> testFile(t, lambda))),
createLongRunningTestData()
return createLongRunningTestData()
.map(t -> dynamicTest(t.title(),
() -> test(t, lambda)))
);
}

protected void testFile(Path path, ToDoubleFunction<NumberTestData> f) {
createSupplementalTestData(path, NumberType.FLOAT64)
.forEach(d -> test(d, f));
() -> test(t, lambda)));
}

private void test(NumberTestData d, ToDoubleFunction<NumberTestData> f) {
Expand Down
2 changes: 1 addition & 1 deletion fastdoubleparserdemo-java21/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<maven.deploy.skip>true</maven.deploy.skip>
</properties>

<name>fastdoubleparserdemo-Java19</name>
<name>fastdoubleparserdemo-Java21</name>

<build>
<sourceDirectory>${basedir}/src/main/java/ch.randelshofer.fastdoubleparserdemo</sourceDirectory>
Expand Down
2 changes: 1 addition & 1 deletion fastdoubleparserdemo/src/assembly/mrjar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>ch.randelshofer:fastdoubleparserdemo-java19</include>
<include>ch.randelshofer:fastdoubleparserdemo-fastdoubleparser-java21</include>
</includes>
<binaries>
<outputDirectory>META-INF/versions/19</outputDirectory>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@
<systemPropertyVariables>
<enableLongRunningTests>false</enableLongRunningTests>
</systemPropertyVariables>
<argLine>-Xmx20g</argLine>
<argLine>-Xmx18g</argLine>
<parallel>classesAndMethods</parallel>
<forkCount>4</forkCount>
<forkCount>3</forkCount>
</configuration>
</plugin>
<plugin>
Expand Down

0 comments on commit 17cbfcc

Please sign in to comment.