Reusable assertions for arrays of doubles. @author Alex Ruiz @author Mikhail Mazursky @author Nicolas François
| 27 | * @author Nicolas François |
| 28 | */ |
| 29 | public class DoubleArrays { |
| 30 | |
| 31 | private static final DoubleArrays INSTANCE = new DoubleArrays(); |
| 32 | |
| 33 | /** |
| 34 | * Returns the singleton instance of this class. |
| 35 | * |
| 36 | * @return the singleton instance of this class. |
| 37 | */ |
| 38 | public static DoubleArrays instance() { |
| 39 | return INSTANCE; |
| 40 | } |
| 41 | |
| 42 | private Arrays arrays = Arrays.instance(); |
| 43 | |
| 44 | @VisibleForTesting |
| 45 | Failures failures = Failures.instance(); |
| 46 | |
| 47 | @VisibleForTesting |
| 48 | DoubleArrays() { |
| 49 | this(StandardComparisonStrategy.instance()); |
| 50 | } |
| 51 | |
| 52 | public DoubleArrays(ComparisonStrategy comparisonStrategy) { |
| 53 | this.arrays = new Arrays(comparisonStrategy); |
| 54 | } |
| 55 | |
| 56 | @VisibleForTesting |
| 57 | public Comparator<?> getComparator() { |
| 58 | return arrays.getComparator(); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Asserts that the given array is {@code null} or empty. |
| 63 | * |
| 64 | * @param info contains information about the assertion. |
| 65 | * @param actual the given array. |
| 66 | * @throws AssertionError if the given array is not {@code null} *and* contains one or more elements. |
| 67 | */ |
| 68 | public void assertNullOrEmpty(AssertionInfo info, double[] actual) { |
| 69 | arrays.assertNullOrEmpty(info, failures, actual); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Asserts that the given array is empty. |
| 74 | * |
| 75 | * @param info contains information about the assertion. |
| 76 | * @param actual the given array. |
| 77 | * @throws AssertionError if the given array is {@code null}. |
| 78 | * @throws AssertionError if the given array is not empty. |
| 79 | */ |
| 80 | public void assertEmpty(AssertionInfo info, double[] actual) { |
| 81 | arrays.assertEmpty(info, failures, actual); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Asserts that the given array is not empty. |
| 86 | * |