Class FloatSubject

    • Method Detail

      • isNotWithin

        public FloatSubject.TolerantFloatComparison isNotWithin​(float tolerance)
        Prepares for a check that the actual value is a finite number not within the given tolerance of an expected value that will be provided in the next call in the fluent chain.

        The check will fail if either the actual value or the expected value is Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, or Float.NaN. See isFinite(), isNotNaN(), or isNotEqualTo(java.lang.Object) for checks with other behaviours.

        The check will fail if both values are zero, even if one is 0.0f and the other is -0.0f. Use isNotEqualTo(java.lang.Object) for a test which fails for a value of exactly zero with one sign but passes for zero with the opposite sign.

        You can use a tolerance of 0.0f to assert the exact non-equality of finite floats, but sometimes isNotEqualTo(java.lang.Object) is preferable (note the different behaviours around non-finite values and -0.0f).

        Parameters:
        tolerance - an exclusive lower bound on the difference between the actual value and expected value allowed by the check, which must be a non-negative finite value, i.e. not Float.NaN, Float.POSITIVE_INFINITY, or negative, including -0.0f
      • isEqualTo

        public void isEqualTo​(@Nullable Object expected)
        Asserts that the actual value is exactly equal to the given value, with equality defined as by Float.equals(java.lang.Object). This method is not recommended when the code under test is doing any kind of arithmetic: use isWithin(float) with a suitable tolerance in that case. (Remember that the exact result of floating point arithmetic is sensitive to apparently trivial changes such as replacing (a + b) + c with a + (b + c).) This method is recommended when the code under test is specified as either copying a value without modification from its input or returning a well-defined literal or constant value.

        Note: The assertion isEqualTo(0.0f) fails for an input of -0.0f, and vice versa. For an assertion that passes for either 0.0f or -0.0f, use isZero().

        Overrides:
        isEqualTo in class Subject
      • isZero

        public void isZero()
        Asserts that the actual value is zero (i.e. it is either 0.0f or -0.0f).
      • isNonZero

        public void isNonZero()
        Asserts that the actual value is a non-null value other than zero (i.e. it is not 0.0f, -0.0f or null).
      • isNaN

        public void isNaN()
        Asserts that the actual value is Float.NaN.
      • isGreaterThan

        public void isGreaterThan​(int other)
        Checks that the actual value is greater than other.

        To check that the actual value is greater than or equal to other, use isAtLeast(int).

      • isLessThan

        public void isLessThan​(int other)
        Checks that the actual value is less than other.

        To check that the actual value is less than or equal to other, use isAtMost(int) .

      • isAtMost

        public void isAtMost​(int other)
        Checks that the actual value is less than or equal to other.

        To check that the actual value is strictly less than other, use isLessThan(int).

      • isAtLeast

        public void isAtLeast​(int other)
        Checks that the actual value is greater than or equal to other.

        To check that the actual value is strictly greater than other, use isGreaterThan(int).