Package at.jku.ssw.fp.sect11_3.check4j
Class Property<A>
- java.lang.Object
-
- at.jku.ssw.fp.sect11_3.check4j.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 Summary
Fields Modifier and Type Field Description private Gen<A>
generator
The generator for generating test values.int
N
Constant for the number of generated test values.private Optional<Shrinker<A>>
optShrinker
The optional shrinker for shrinking a failed test value.private Predicate<? super A>
predicate
The predicate for testing test values.
-
Constructor Summary
Constructors Modifier Constructor Description private
Property(Gen<A> generator, Predicate<? super A> predicate)
Constructor setting generator and predicate.private
Property(Gen<A> generator, Predicate<? super A> predicate, Shrinker<A> shrinker)
Constructor setting generator, predicate and shrinker.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Result<A>
check()
Runs the property-based test represented by this property object.Result<A>
checkAndShrink()
Runs the property-based test represented by this property object.void
checkVerbose()
Runs the property-based test represented by this property object.void
checkVerbose(PrintStream printer)
Runs the property-based test represented by this property object.static <A> Property<A>
forAll(Gen<A> generator, Predicate<? super A> predicate)
Creates a property object from a generator and predicate.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.
-
-
-
Field Detail
-
N
public final int N
Constant for the number of generated test values.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Property
private Property(Gen<A> generator, Predicate<? super A> predicate)
Constructor setting generator and predicate.- Parameters:
generator
- the generator for generating test valuespredicate
- 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 valuespredicate
- the predicate for testing test valuesshrinker
- 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 valuespredicate
- the predicate for testing test valuesshrinker
- 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 valuespredicate
- 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.
-
-