GDSC Test provides utility functionality for writing Java tests.
Functionality includes:
- Predicate library for single- or bi-valued test predicates using Java primitives
- Assertion utilities for asserting predicates
- Dynamic messages implementing
Supplier<String>
- Configurable random seed utilities
See the latest documentation on ReadTheDocs.
The GDSC predicate library is an extension of the java.util.function
primitive predicates DoublePredicate
and LongPredicate
to all java
primitives. These are functional interfaces for single or bi-valued predicates,
for example for int
primitives:
@FunctionalInterface
public interface IntPredicate {
boolean test(int value);
// default methods
}
@FunctionalInterface
public interface IntIntBiPredicate {
boolean test(int value1, int value2);
// default methods
}
Standard predicates are provided to test equality and closeness within an
absolute
or relative
error for use in a testing framework.
Support for testing using a test framework is provided with a utility class that
will test primitive value(s) using a single or bi-valued predicate. An
AssertionError
is generated when a test fails. For example a test for
relative equality:
import uk.ac.sussex.gdsc.test.api.TestAssertions;
import uk.ac.sussex.gdsc.test.api.Predicates;
@Test
public void testRelativeEquality() {
double relativeError = 0.01;
double expected = 100;
double actual = 99;
DoubleDoubleBiPredicate areClose = Predicates.doublesAreRelativelyClose(relativeError);
// This will pass as 99 is within (0.01*100) of 100
TestAssertions.assertTest(expected, actual, areClose);
}
All provided implementations of the TypePredicate
or TypeTypeBiPredicate
interface implement Supplier<String>
to provide a text description of the predicate. This is used to format an error message for the failed test.
Nested arrays are supported using recursion allowing testing of matrices:
IntIntBiPredicate equal = Predicates.intsAreEqual();
Object[] expected = new int[4][5][6];
Object[] actual = new int[4][5][6];
TestAssertions.assertArrayTest(expected, actual, equal);
This package is a library to be used used by other Java programs. The latest version is on Maven central:
The package can be installed locally from the source using Maven.
git clone https://github.com/aherbert/gdsc-test.git
cd gdsc-test
mvn install
Developed at the Genome Damage and Stability Centre, University of Sussex.