Class Property<A>

  • Type Parameters:
    A - the type of the test values

    public class Property<A>
    extends Object
    A property object in a property-based test.

    It consists of a generator for generating test values, a predicate for testing test values, and a shrinker for shrinking a failed test value.

    Author:
    Herbert Praehofer
    • Field Detail

      • N

        public final int N
        Constant for the number of generated test values.
        See Also:
        Constant Field Values
      • generator

        private final Gen<A> generator
        The generator for generating test values.
      • predicate

        private final Predicate<? super A> predicate
        The predicate for testing test values.
      • optShrinker

        private final Optional<Shrinker<A>> optShrinker
        The optional shrinker for shrinking a failed test value.
    • Constructor Detail

      • Property

        private Property​(Gen<A> generator,
                         Predicate<? super A> predicate)
        Constructor setting generator and predicate.
        Parameters:
        generator - the generator for generating test values
        predicate - the predicate for testing test values
      • Property

        private Property​(Gen<A> generator,
                         Predicate<? super A> predicate,
                         Shrinker<A> shrinker)
        Constructor setting generator, predicate and shrinker.
        Parameters:
        generator - the generator for generating test values
        predicate - the predicate for testing test values
        shrinker - the shrinker for shrinking a failed test value
    • Method Detail

      • forAll

        public static <A> Property<A> forAll​(Gen<A> generator,
                                             Predicate<? super A> predicate,
                                             Shrinker<A> shrinker)
        Creates a property object from a generator, predicate and shrinker.
        Type Parameters:
        A - the type of test values
        Parameters:
        generator - the generator for generating test values
        predicate - the predicate for testing test values
        shrinker - the shrinker for shrinking a failed test value
        Returns:
        the property object
      • forAll

        public static <A> Property<A> forAll​(Gen<A> generator,
                                             Predicate<? super A> predicate)
        Creates a property object from a generator and predicate. No shrinker is used.
        Type Parameters:
        A - the type of test values
        Parameters:
        generator - the generator for generating test values
        predicate - the predicate for testing test values
        Returns:
        the property object
      • check

        public Result<A> check()
        Runs the property-based test represented by this property object.

        Generates N test values using the generator and test them by the predicate. When the first fails the test is aborted. Does not shrink a failed value.

        Returns:
        the result of the test run
      • checkAndShrink

        public Result<A> checkAndShrink()
        Runs the property-based test represented by this property object.

        Generates N test values using the generator and test them by the predicate. When the first fails, the failed value is shrunk by the shrinker and the test is aborted.

        Returns:
        the result of the test run
      • checkVerbose

        public void checkVerbose​(PrintStream printer)
        Runs the property-based test represented by this property object.

        Generates N test values using the generator and test them by the predicate. When the first fails, the test is aborted. If a shrinker is set, the failed value is shrunk. Prints out the result of the test on the given printer stream.

        Parameters:
        printer - the printer stream
      • checkVerbose

        public void checkVerbose()
        Runs the property-based test represented by this property object. Prints out the result of the test on standard output.