Skip to content

Commit

Permalink
Dump state for processing state tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smithkm committed Dec 5, 2024
1 parent 72906ea commit d78f01e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1037,14 +1037,14 @@ public static void writeModel(ProcessingState<?, ?> expected, Appendable out, in

writeModel(poly, out, indent, "var polygon");

line(out, indent, "var state = new TestProcessingState(controlMap);");
line(out, indent, "state.setPolygon(polygon);");
line(out, indent, "var primaryBank = state.getPrimaryLayerProcessingState().getBank();");
line(out, indent, "%s = new TestProcessingState(controlMap);", assignTo);
line(out, indent, "%s.setPolygon(polygon);", assignTo);
line(out, indent, "var primaryBank = %s.getPrimaryLayerProcessingState().getBank();", assignTo);

writeBankConfig(expected.getPrimaryLayerProcessingState().getBank(), out, indent, "primaryBank");

expected.getVeteranLayerProcessingState().ifPresent(vetState -> {
line(out, indent, "var veteranBank = state.getVeteranLayerProcessingState().get().getBank();");
line(out, indent, "var veteranBank = %s.getVeteranLayerProcessingState().get().getBank();", assignTo);
writeBankConfig(vetState.getBank(), out, indent, "veteranBank");
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void testBank() throws IOException {
assertThat(result, deepEquals(expected));
}

public void jitterBank(Bank expected) {
void jitterBank(Bank expected) {
TestUtils.jitterArray(expected.ageTotals, rand);
TestUtils.jitterArray(expected.basalAreas, rand);
TestUtils.jitterArray(expected.dominantHeights, rand);
Expand Down Expand Up @@ -304,7 +304,7 @@ void testProcessingState() throws IOException, ProcessingException {

System.out.print(buf.toString());

ProcessingState result = null;
ProcessingState<?, ?> result = null;

{
/* the following ProcessingState definition was generated */
Expand Down Expand Up @@ -912,9 +912,9 @@ void testProcessingState() throws IOException, ProcessingException {
});

/* End of generated Polygon definition */
var state = new TestProcessingState(controlMap);
state.setPolygon(polygon);
var primaryBank = state.getPrimaryLayerProcessingState().getBank();
result = new TestProcessingState(controlMap);
result.setPolygon(polygon);
var primaryBank = result.getPrimaryLayerProcessingState().getBank();
System.arraycopy(new float[] { 0.000000f, 37.029385f }, 0, primaryBank.ageTotals, 0, 2);
System.arraycopy(new float[] { 0.000000f, 0.000000f }, 0, primaryBank.percentagesOfForestedLand, 0, 2);
System.arraycopy(
Expand All @@ -928,7 +928,7 @@ void testProcessingState() throws IOException, ProcessingException {
System.arraycopy(new float[] { 0.000000f, 31.781885f }, 0, primaryBank.yearsAtBreastHeight, 0, 2);
System.arraycopy(new float[] { 0.000000f, 4.648443f }, 0, primaryBank.yearsToBreastHeight, 0, 2);
System.arraycopy(new int[] { -1, 41 }, 0, primaryBank.siteCurveNumbers, 0, 2);
var veteranBank = state.getVeteranLayerProcessingState().get().getBank();
var veteranBank = result.getVeteranLayerProcessingState().get().getBank();
System.arraycopy(new float[] { 0.000000f, Float.NaN }, 0, veteranBank.ageTotals, 0, 2);
System.arraycopy(new float[] { 0.000000f, 0.000000f }, 0, veteranBank.percentagesOfForestedLand, 0, 2);
System.arraycopy(
Expand All @@ -946,7 +946,7 @@ void testProcessingState() throws IOException, ProcessingException {
/* End of generated ProcessingState definition */
}

assertThat(result, deepEquals((ProcessingState) expectedState));
assertThat(result, deepEquals(expectedState));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ public void describeMismatch(Object item, Description description) {
description.appendText("Not present");
return;
}
delegate.describeMismatch(item, description);

description.appendText("was present but ");
delegate.describeMismatch( ((Optional<?>) item).get(), description);
}

};
Expand Down Expand Up @@ -576,7 +578,10 @@ protected boolean matchesSafely(Float item, Description mismatchDescription) {
}

public static Matcher<Float> closeTo(float expected) {
return closeTo(expected, currentEpsilon);
if (Float.isFinite(expected)) {
return closeTo(expected, currentEpsilon);
}
return equalTo(expected);
}

public static Matcher<Float> closeTo(float expected, float threshold) {
Expand Down Expand Up @@ -1370,7 +1375,6 @@ public static Matcher<float[][]> arrayCloseTo3D(float[][][] expected) {
}

public static <T extends LayerProcessingState<?, T>> Matcher<? super T> deepEquals(T expected) {
expected.getBank();
return allOf(
hasProperty(
"polygon",
Expand Down

0 comments on commit d78f01e

Please sign in to comment.