diff --git a/lib/vdyp-common/src/test/java/ca/bc/gov/nrs/vdyp/test/TestUtils.java b/lib/vdyp-common/src/test/java/ca/bc/gov/nrs/vdyp/test/TestUtils.java index 4eaddab3..50bba9ad 100644 --- a/lib/vdyp-common/src/test/java/ca/bc/gov/nrs/vdyp/test/TestUtils.java +++ b/lib/vdyp-common/src/test/java/ca/bc/gov/nrs/vdyp/test/TestUtils.java @@ -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"); }); diff --git a/lib/vdyp-common/src/test/java/ca/bc/gov/nrs/vdyp/test/TestUtilsTest.java b/lib/vdyp-common/src/test/java/ca/bc/gov/nrs/vdyp/test/TestUtilsTest.java index 45f237c2..d2e5b390 100644 --- a/lib/vdyp-common/src/test/java/ca/bc/gov/nrs/vdyp/test/TestUtilsTest.java +++ b/lib/vdyp-common/src/test/java/ca/bc/gov/nrs/vdyp/test/TestUtilsTest.java @@ -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); @@ -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 */ @@ -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( @@ -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( @@ -946,7 +946,7 @@ void testProcessingState() throws IOException, ProcessingException { /* End of generated ProcessingState definition */ } - assertThat(result, deepEquals((ProcessingState) expectedState)); + assertThat(result, deepEquals(expectedState)); } diff --git a/lib/vdyp-common/src/test/java/ca/bc/gov/nrs/vdyp/test/VdypMatchers.java b/lib/vdyp-common/src/test/java/ca/bc/gov/nrs/vdyp/test/VdypMatchers.java index b46bcb33..050f0feb 100644 --- a/lib/vdyp-common/src/test/java/ca/bc/gov/nrs/vdyp/test/VdypMatchers.java +++ b/lib/vdyp-common/src/test/java/ca/bc/gov/nrs/vdyp/test/VdypMatchers.java @@ -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); } }; @@ -576,7 +578,10 @@ protected boolean matchesSafely(Float item, Description mismatchDescription) { } public static Matcher closeTo(float expected) { - return closeTo(expected, currentEpsilon); + if (Float.isFinite(expected)) { + return closeTo(expected, currentEpsilon); + } + return equalTo(expected); } public static Matcher closeTo(float expected, float threshold) { @@ -1370,7 +1375,6 @@ public static Matcher arrayCloseTo3D(float[][][] expected) { } public static > Matcher deepEquals(T expected) { - expected.getBank(); return allOf( hasProperty( "polygon",