javaslang.test.Property Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javaslang Show documentation
Show all versions of javaslang Show documentation
Javaslang is a Java standard library extension built for Java 8 and above.
/* / \____ _ ______ _____ / \____ ____ _____
* / \__ \/ \ / \__ \ / __// \__ \ / \/ __ \ Javaslang
* _/ // _\ \ \/ / _\ \\_ \/ // _\ \ /\ \__/ / Copyright 2014-2015 Daniel Dietrich
* /___/ \_____/\____/\_____/____/\___\_____/_/ \_/____/ Licensed under the Apache License, Version 2.0
*/
package javaslang.test;
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*\
G E N E R A T O R C R A F T E D
\*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
import java.util.Objects;
import java.util.Random;
import javaslang.*;
import javaslang.control.Failure;
import javaslang.control.None;
import javaslang.control.Some;
import javaslang.control.Try;
/**
* A property builder which provides a fluent API to build checkable properties.
* @since 1.2.0
*/
public class Property {
private final String name;
/**
* Construct a named property.
* @param name property name
*/
public Property(String name) {
Objects.requireNonNull(name, "name is null");
if (name.isEmpty()) {
throw new IllegalArgumentException("name is empty");
}
this.name = name;
}
private static void logSatisfied(String name, int tries, boolean exhausted) {
if (exhausted) {
log(String.format("%s: Exhausted after %s tests.", name, tries));
} else {
log(String.format("%s: OK, passed %s tests.", name, tries));
}
}
private static void logFalsified(String name, int currentTry) {
log(String.format("%s: Falsified after %s passed tests.", name, currentTry - 1));
}
private static void logErroneous(String name, int currentTry, String errorMessage) {
log(String.format("%s: Errored after %s passed tests with message: %s", name, Math.max(0, currentTry - 1), errorMessage));
}
private static void log(String msg) {
System.out.println(msg);
}
/**
* Returns a logical for all quantor of 1 given variables.
*
* @param 1st variable type of this for all quantor
* @param a1 1st variable of this for all quantor
* @return a new {@code ForAll1} instance of 1 variables
*/
public ForAll1 forAll(Arbitrary a1) {
return new ForAll1<>(name, a1);
}
/**
* Returns a logical for all quantor of 2 given variables.
*
* @param 1st variable type of this for all quantor
* @param 2nd variable type of this for all quantor
* @param a1 1st variable of this for all quantor
* @param a2 2nd variable of this for all quantor
* @return a new {@code ForAll2} instance of 2 variables
*/
public ForAll2 forAll(Arbitrary a1, Arbitrary a2) {
return new ForAll2<>(name, a1, a2);
}
/**
* Returns a logical for all quantor of 3 given variables.
*
* @param 1st variable type of this for all quantor
* @param 2nd variable type of this for all quantor
* @param 3rd variable type of this for all quantor
* @param a1 1st variable of this for all quantor
* @param a2 2nd variable of this for all quantor
* @param a3 3rd variable of this for all quantor
* @return a new {@code ForAll3} instance of 3 variables
*/
public ForAll3 forAll(Arbitrary a1, Arbitrary a2, Arbitrary a3) {
return new ForAll3<>(name, a1, a2, a3);
}
/**
* Returns a logical for all quantor of 4 given variables.
*
* @param 1st variable type of this for all quantor
* @param 2nd variable type of this for all quantor
* @param 3rd variable type of this for all quantor
* @param 4th variable type of this for all quantor
* @param a1 1st variable of this for all quantor
* @param a2 2nd variable of this for all quantor
* @param a3 3rd variable of this for all quantor
* @param a4 4th variable of this for all quantor
* @return a new {@code ForAll4} instance of 4 variables
*/
public ForAll4 forAll(Arbitrary a1, Arbitrary a2, Arbitrary a3, Arbitrary a4) {
return new ForAll4<>(name, a1, a2, a3, a4);
}
/**
* Returns a logical for all quantor of 5 given variables.
*
* @param 1st variable type of this for all quantor
* @param 2nd variable type of this for all quantor
* @param 3rd variable type of this for all quantor
* @param 4th variable type of this for all quantor
* @param 5th variable type of this for all quantor
* @param a1 1st variable of this for all quantor
* @param a2 2nd variable of this for all quantor
* @param a3 3rd variable of this for all quantor
* @param a4 4th variable of this for all quantor
* @param a5 5th variable of this for all quantor
* @return a new {@code ForAll5} instance of 5 variables
*/
public ForAll5 forAll(Arbitrary a1, Arbitrary a2, Arbitrary a3, Arbitrary a4, Arbitrary a5) {
return new ForAll5<>(name, a1, a2, a3, a4, a5);
}
/**
* Returns a logical for all quantor of 6 given variables.
*
* @param 1st variable type of this for all quantor
* @param 2nd variable type of this for all quantor
* @param 3rd variable type of this for all quantor
* @param 4th variable type of this for all quantor
* @param 5th variable type of this for all quantor
* @param 6th variable type of this for all quantor
* @param a1 1st variable of this for all quantor
* @param a2 2nd variable of this for all quantor
* @param a3 3rd variable of this for all quantor
* @param a4 4th variable of this for all quantor
* @param a5 5th variable of this for all quantor
* @param a6 6th variable of this for all quantor
* @return a new {@code ForAll6} instance of 6 variables
*/
public ForAll6 forAll(Arbitrary a1, Arbitrary a2, Arbitrary a3, Arbitrary a4, Arbitrary a5, Arbitrary a6) {
return new ForAll6<>(name, a1, a2, a3, a4, a5, a6);
}
/**
* Returns a logical for all quantor of 7 given variables.
*
* @param 1st variable type of this for all quantor
* @param 2nd variable type of this for all quantor
* @param 3rd variable type of this for all quantor
* @param 4th variable type of this for all quantor
* @param 5th variable type of this for all quantor
* @param 6th variable type of this for all quantor
* @param 7th variable type of this for all quantor
* @param a1 1st variable of this for all quantor
* @param a2 2nd variable of this for all quantor
* @param a3 3rd variable of this for all quantor
* @param a4 4th variable of this for all quantor
* @param a5 5th variable of this for all quantor
* @param a6 6th variable of this for all quantor
* @param a7 7th variable of this for all quantor
* @return a new {@code ForAll7} instance of 7 variables
*/
public ForAll7 forAll(Arbitrary a1, Arbitrary a2, Arbitrary a3, Arbitrary a4, Arbitrary a5, Arbitrary a6, Arbitrary a7) {
return new ForAll7<>(name, a1, a2, a3, a4, a5, a6, a7);
}
/**
* Returns a logical for all quantor of 8 given variables.
*
* @param 1st variable type of this for all quantor
* @param 2nd variable type of this for all quantor
* @param 3rd variable type of this for all quantor
* @param 4th variable type of this for all quantor
* @param 5th variable type of this for all quantor
* @param 6th variable type of this for all quantor
* @param 7th variable type of this for all quantor
* @param 8th variable type of this for all quantor
* @param a1 1st variable of this for all quantor
* @param a2 2nd variable of this for all quantor
* @param a3 3rd variable of this for all quantor
* @param a4 4th variable of this for all quantor
* @param a5 5th variable of this for all quantor
* @param a6 6th variable of this for all quantor
* @param a7 7th variable of this for all quantor
* @param a8 8th variable of this for all quantor
* @return a new {@code ForAll8} instance of 8 variables
*/
public ForAll8 forAll(Arbitrary a1, Arbitrary a2, Arbitrary a3, Arbitrary a4, Arbitrary a5, Arbitrary a6, Arbitrary a7, Arbitrary a8) {
return new ForAll8<>(name, a1, a2, a3, a4, a5, a6, a7, a8);
}
/**
* Returns a logical for all quantor of 9 given variables.
*
* @param 1st variable type of this for all quantor
* @param 2nd variable type of this for all quantor
* @param 3rd variable type of this for all quantor
* @param 4th variable type of this for all quantor
* @param 5th variable type of this for all quantor
* @param 6th variable type of this for all quantor
* @param 7th variable type of this for all quantor
* @param 8th variable type of this for all quantor
* @param 9th variable type of this for all quantor
* @param a1 1st variable of this for all quantor
* @param a2 2nd variable of this for all quantor
* @param a3 3rd variable of this for all quantor
* @param a4 4th variable of this for all quantor
* @param a5 5th variable of this for all quantor
* @param a6 6th variable of this for all quantor
* @param a7 7th variable of this for all quantor
* @param a8 8th variable of this for all quantor
* @param a9 9th variable of this for all quantor
* @return a new {@code ForAll9} instance of 9 variables
*/
public ForAll9 forAll(Arbitrary a1, Arbitrary a2, Arbitrary a3, Arbitrary a4, Arbitrary a5, Arbitrary a6, Arbitrary a7, Arbitrary a8, Arbitrary a9) {
return new ForAll9<>(name, a1, a2, a3, a4, a5, a6, a7, a8, a9);
}
/**
* Returns a logical for all quantor of 10 given variables.
*
* @param 1st variable type of this for all quantor
* @param 2nd variable type of this for all quantor
* @param 3rd variable type of this for all quantor
* @param 4th variable type of this for all quantor
* @param 5th variable type of this for all quantor
* @param 6th variable type of this for all quantor
* @param 7th variable type of this for all quantor
* @param 8th variable type of this for all quantor
* @param 9th variable type of this for all quantor
* @param 10th variable type of this for all quantor
* @param a1 1st variable of this for all quantor
* @param a2 2nd variable of this for all quantor
* @param a3 3rd variable of this for all quantor
* @param a4 4th variable of this for all quantor
* @param a5 5th variable of this for all quantor
* @param a6 6th variable of this for all quantor
* @param a7 7th variable of this for all quantor
* @param a8 8th variable of this for all quantor
* @param a9 9th variable of this for all quantor
* @param a10 10th variable of this for all quantor
* @return a new {@code ForAll10} instance of 10 variables
*/
public ForAll10 forAll(Arbitrary a1, Arbitrary a2, Arbitrary a3, Arbitrary a4, Arbitrary a5, Arbitrary a6, Arbitrary a7, Arbitrary a8, Arbitrary a9, Arbitrary a10) {
return new ForAll10<>(name, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
}
/**
* Returns a logical for all quantor of 11 given variables.
*
* @param 1st variable type of this for all quantor
* @param 2nd variable type of this for all quantor
* @param 3rd variable type of this for all quantor
* @param 4th variable type of this for all quantor
* @param 5th variable type of this for all quantor
* @param 6th variable type of this for all quantor
* @param 7th variable type of this for all quantor
* @param 8th variable type of this for all quantor
* @param 9th variable type of this for all quantor
* @param 10th variable type of this for all quantor
* @param 11th variable type of this for all quantor
* @param a1 1st variable of this for all quantor
* @param a2 2nd variable of this for all quantor
* @param a3 3rd variable of this for all quantor
* @param a4 4th variable of this for all quantor
* @param a5 5th variable of this for all quantor
* @param a6 6th variable of this for all quantor
* @param a7 7th variable of this for all quantor
* @param a8 8th variable of this for all quantor
* @param a9 9th variable of this for all quantor
* @param a10 10th variable of this for all quantor
* @param a11 11th variable of this for all quantor
* @return a new {@code ForAll11} instance of 11 variables
*/
public ForAll11 forAll(Arbitrary a1, Arbitrary a2, Arbitrary a3, Arbitrary a4, Arbitrary a5, Arbitrary a6, Arbitrary a7, Arbitrary a8, Arbitrary a9, Arbitrary a10, Arbitrary a11) {
return new ForAll11<>(name, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11);
}
/**
* Returns a logical for all quantor of 12 given variables.
*
* @param 1st variable type of this for all quantor
* @param 2nd variable type of this for all quantor
* @param 3rd variable type of this for all quantor
* @param 4th variable type of this for all quantor
* @param 5th variable type of this for all quantor
* @param 6th variable type of this for all quantor
* @param 7th variable type of this for all quantor
* @param 8th variable type of this for all quantor
* @param 9th variable type of this for all quantor
* @param 10th variable type of this for all quantor
* @param 11th variable type of this for all quantor
* @param 12th variable type of this for all quantor
* @param a1 1st variable of this for all quantor
* @param a2 2nd variable of this for all quantor
* @param a3 3rd variable of this for all quantor
* @param a4 4th variable of this for all quantor
* @param a5 5th variable of this for all quantor
* @param a6 6th variable of this for all quantor
* @param a7 7th variable of this for all quantor
* @param a8 8th variable of this for all quantor
* @param a9 9th variable of this for all quantor
* @param a10 10th variable of this for all quantor
* @param a11 11th variable of this for all quantor
* @param a12 12th variable of this for all quantor
* @return a new {@code ForAll12} instance of 12 variables
*/
public ForAll12 forAll(Arbitrary a1, Arbitrary a2, Arbitrary a3, Arbitrary a4, Arbitrary a5, Arbitrary a6, Arbitrary a7, Arbitrary a8, Arbitrary a9, Arbitrary a10, Arbitrary a11, Arbitrary a12) {
return new ForAll12<>(name, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12);
}
/**
* Returns a logical for all quantor of 13 given variables.
*
* @param 1st variable type of this for all quantor
* @param 2nd variable type of this for all quantor
* @param 3rd variable type of this for all quantor
* @param 4th variable type of this for all quantor
* @param 5th variable type of this for all quantor
* @param 6th variable type of this for all quantor
* @param 7th variable type of this for all quantor
* @param 8th variable type of this for all quantor
* @param 9th variable type of this for all quantor
* @param 10th variable type of this for all quantor
* @param 11th variable type of this for all quantor
* @param 12th variable type of this for all quantor
* @param 13th variable type of this for all quantor
* @param a1 1st variable of this for all quantor
* @param a2 2nd variable of this for all quantor
* @param a3 3rd variable of this for all quantor
* @param a4 4th variable of this for all quantor
* @param a5 5th variable of this for all quantor
* @param a6 6th variable of this for all quantor
* @param a7 7th variable of this for all quantor
* @param a8 8th variable of this for all quantor
* @param a9 9th variable of this for all quantor
* @param a10 10th variable of this for all quantor
* @param a11 11th variable of this for all quantor
* @param a12 12th variable of this for all quantor
* @param a13 13th variable of this for all quantor
* @return a new {@code ForAll13} instance of 13 variables
*/
public ForAll13 forAll(Arbitrary a1, Arbitrary a2, Arbitrary a3, Arbitrary a4, Arbitrary a5, Arbitrary a6, Arbitrary a7, Arbitrary a8, Arbitrary a9, Arbitrary a10, Arbitrary a11, Arbitrary a12, Arbitrary a13) {
return new ForAll13<>(name, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13);
}
/**
* Returns a logical for all quantor of 14 given variables.
*
* @param 1st variable type of this for all quantor
* @param 2nd variable type of this for all quantor
* @param 3rd variable type of this for all quantor
* @param 4th variable type of this for all quantor
* @param 5th variable type of this for all quantor
* @param 6th variable type of this for all quantor
* @param 7th variable type of this for all quantor
* @param 8th variable type of this for all quantor
* @param 9th variable type of this for all quantor
* @param 10th variable type of this for all quantor
* @param 11th variable type of this for all quantor
* @param 12th variable type of this for all quantor
* @param 13th variable type of this for all quantor
* @param 14th variable type of this for all quantor
* @param a1 1st variable of this for all quantor
* @param a2 2nd variable of this for all quantor
* @param a3 3rd variable of this for all quantor
* @param a4 4th variable of this for all quantor
* @param a5 5th variable of this for all quantor
* @param a6 6th variable of this for all quantor
* @param a7 7th variable of this for all quantor
* @param a8 8th variable of this for all quantor
* @param a9 9th variable of this for all quantor
* @param a10 10th variable of this for all quantor
* @param a11 11th variable of this for all quantor
* @param a12 12th variable of this for all quantor
* @param a13 13th variable of this for all quantor
* @param a14 14th variable of this for all quantor
* @return a new {@code ForAll14} instance of 14 variables
*/
public ForAll14 forAll(Arbitrary a1, Arbitrary a2, Arbitrary a3, Arbitrary a4, Arbitrary a5, Arbitrary a6, Arbitrary a7, Arbitrary a8, Arbitrary a9, Arbitrary a10, Arbitrary a11, Arbitrary a12, Arbitrary a13, Arbitrary a14) {
return new ForAll14<>(name, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14);
}
/**
* Returns a logical for all quantor of 15 given variables.
*
* @param 1st variable type of this for all quantor
* @param 2nd variable type of this for all quantor
* @param 3rd variable type of this for all quantor
* @param 4th variable type of this for all quantor
* @param 5th variable type of this for all quantor
* @param 6th variable type of this for all quantor
* @param 7th variable type of this for all quantor
* @param 8th variable type of this for all quantor
* @param 9th variable type of this for all quantor
* @param 10th variable type of this for all quantor
* @param 11th variable type of this for all quantor
* @param 12th variable type of this for all quantor
* @param 13th variable type of this for all quantor
* @param