001 package org.fest.assertions.internal;
002
003 import org.fest.assertions.core.AssertionInfo;
004 import org.fest.assertions.data.Offset;
005 import org.fest.util.ComparisonStrategy;
006
007 /**
008 * Base class of reusable assertions for real numbers (float and double).
009 *
010 * @author Joel Costigliola
011 */
012 public abstract class RealNumbers<NUMBER extends Comparable<NUMBER>> extends Numbers<NUMBER> {
013
014 public RealNumbers() {
015 super();
016 }
017
018 public RealNumbers(ComparisonStrategy comparisonStrategy) {
019 super(comparisonStrategy);
020 }
021
022 /**
023 * Verifies that the actual value is equal to {@code NaN}.<br>
024 * It does not rely on the custom comparisonStrategy (if one is set).
025 *
026 * @param info contains information about the assertion.
027 * @param actual the actual value.
028 * @throws AssertionError if the actual value is not equal to {@code NaN}.
029 */
030 public void assertIsNaN(AssertionInfo info, NUMBER actual) {
031 assertEqualByComparison(info, actual, NaN());
032 }
033
034 protected abstract NUMBER NaN();
035
036 /**
037 * Verifies that the actual value is not equal to {@code NaN}.
038 * @param info contains information about the assertion.
039 * @param actual the actual value.
040 * @throws AssertionError if the actual value is equal to {@code NaN}.
041 */
042 public void assertIsNotNaN(AssertionInfo info, NUMBER actual) {
043 assertNotEqualByComparison(info, actual, NaN());
044 }
045
046 /**
047 * Returns true if the two floats parameter are equal within a positive offset, false otherwise.<br>
048 * It does not rely on the custom comparisonStrategy (if one is set) because using an offset is already a specific
049 * comparison strategy.
050 * @param actual the actual value.
051 * @param expected the expected value.
052 * @param offset the given positive offset.
053 * @return true if the two floats parameter are equal within a positive offset, false otherwise.
054 */
055 protected abstract boolean isEqualTo(NUMBER actual, NUMBER expected, Offset<?> offset);
056
057 }