diff --git a/core/src/test/java/com/google/common/truth/PrimitiveFloatArraySubjectTest.java b/core/src/test/java/com/google/common/truth/PrimitiveFloatArraySubjectTest.java index 078ae8985..3748cb7dd 100644 --- a/core/src/test/java/com/google/common/truth/PrimitiveFloatArraySubjectTest.java +++ b/core/src/test/java/com/google/common/truth/PrimitiveFloatArraySubjectTest.java @@ -833,4 +833,86 @@ public void hasLengthNullArray() { private static float[] array(float... primitives) { return primitives; } + + @Test + public void isEmpty_emptyArray_success() { + assertThat(array()).isEmpty(); + } + + @Test + public void isEmpty_nonEmptyArray_failure() { + expectFailure(whenTesting -> whenTesting.that(array(1.0f)).isEmpty()); + } + + @Test + public void isNotEmpty_nonEmptyArray_success() { + assertThat(array(1.0f)).isNotEmpty(); + } + + @Test + public void isNotEmpty_emptyArray_failure() { + expectFailure(whenTesting -> whenTesting.that(array()).isNotEmpty()); + } + + @Test + public void usingExactEquality_nullArray_failure() { + expectFailure( + whenTesting -> + whenTesting.that((float[]) null).usingExactEquality().contains(1.0f)); + } + + @Test + public void usingTolerance_nullArray_failure() { + expectFailure( + whenTesting -> + whenTesting.that((float[]) null).usingTolerance(0.001).contains(1.0f)); + } + + @Test + public void usingExactEquality_contains_otherTypes_negativeIntOutOfRange() { + int expected = -(1 << 24) - 1; + float[] actual = array(1.0f, 2.0f, 3.0f); + AssertionError e = + expectFailure( + whenTesting -> whenTesting.that(actual).usingExactEquality().contains(expected)); + assertThat(e) + .factValue("first exception") + .startsWith( + "compare(" + + actual[0] + + ", " + + expected + + ") threw java.lang.IllegalArgumentException"); + assertThat(e) + .factValue("first exception") + .contains( + "Expected value " + + expected + + " in assertion using exact float equality was an int with an absolute value " + + "greater than 2^24 which has no exact float representation"); + } + + @Test + public void usingExactEquality_contains_otherTypes_negativeLongOutOfRange() { + long expected = -(1L << 24) - 1L; + float[] actual = array(1.0f, 2.0f, 3.0f); + AssertionError e = + expectFailure( + whenTesting -> whenTesting.that(actual).usingExactEquality().contains(expected)); + assertThat(e) + .factValue("first exception") + .startsWith( + "compare(" + + actual[0] + + ", " + + expected + + ") threw java.lang.IllegalArgumentException"); + assertThat(e) + .factValue("first exception") + .contains( + "Expected value " + + expected + + " in assertion using exact float equality was a long with an absolute value " + + "greater than 2^24 which has no exact float representation"); + } }