Package at.jku.ssw.fp.sect11_3.check4j
Class Gens
- java.lang.Object
-
- at.jku.ssw.fp.sect11_3.check4j.Gens
-
public class Gens extends Object
Class with variables and methods providing various generators.- Author:
- Herbert Praehofer
-
-
Field Summary
Fields Modifier and Type Field Description static Gen<Integer>
allInts
A generator for in values int values in the full range of int.private static List<Character>
alphabet
List of letters from 'a' to 'z'static Gen<Boolean>
bools
A generator for Boolean value with equal probability.static Gen<FList<Integer>>
intLists
A generator for list of integers from 0 to 9static Gen<Integer>
intRands
A generator for integer values (in full range of integer)static Gen<Character>
letters
A generator for creating letters from 'a' to 'z' with same probability.static Gen<Double>
percents
Creates a generator for percentage values.static Gen<Integer>
posInts
A generator of positive int values(package private) Gen<Integer>
primes100
A generator for prime numbers from2
to100
.private static Random
RAND
A random number generator used for creating random valuesstatic Gen<Double>
rands
A generator for double values (in full range of double)
-
Constructor Summary
Constructors Constructor Description Gens()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Gen<Integer>
intsFromTo(int from, int to)
Creates a generator for int values betweenfrom
andto
.static Gen<Integer>
intsTo(int to)
Creates a generator for int values between0
andto
.private static boolean
isPrime(int n)
static <A> Gen<List<A>>
lists(int maxLength, A... elems)
Creates a generator for generating lists from given elements of given maximum length.static <A> Gen<FList<A>>
lists(int maxLength, Gen<A> elemGen)
Creates a generator for generating lists of given maximum length.static <A> Gen<A>
oneOf(A... as)
Creates a generator which creates values from the given set of values with equal probability.static <A> Gen<A>
oneOf(List<A> as)
Creates a generator which creates values from the given set of values with equal probability.static <A,B>
Gen<Pair<A,B>>pair(Gen<A> aGen, Gen<B> bGen)
A generator of pairs of values.static Gen<Double>
randsFromTo(double from, double to)
Creates a generator for double values betweenfrom
andto
static <A> Gen<A>
single(A a)
Creates a generator which is capable to create a single value.static <A,B>
Gen<Tuple2<A,B>>tuple2(Gen<A> aGen, Gen<B> bGen)
A generator of tuples of two values.static <A,B,C>
Gen<Tuple3<A,B,C>>tuple3(Gen<A> aGen, Gen<B> bGen, Gen<C> cGen)
A generator of tuples of three values.static Gen<Boolean>
withProb(double prob)
Creates generator for Boolean values wheretrue
values are created with the given probability.static Gen<String>
words(int maxLength)
Creates a generator for generating words from random letters of given maximum length.
-
-
-
Field Detail
-
RAND
private static final Random RAND
A random number generator used for creating random values
-
intRands
public static Gen<Integer> intRands
A generator for integer values (in full range of integer)
-
allInts
public static Gen<Integer> allInts
A generator for in values int values in the full range of int.
-
letters
public static Gen<Character> letters
A generator for creating letters from 'a' to 'z' with same probability.
-
-
Method Detail
-
randsFromTo
public static Gen<Double> randsFromTo(double from, double to)
Creates a generator for double values betweenfrom
andto
- Parameters:
from
- the lower valueto
- the upper value- Returns:
- the generator for integer values between
from
andto
-
intsFromTo
public static Gen<Integer> intsFromTo(int from, int to)
Creates a generator for int values betweenfrom
andto
.- Parameters:
from
- the lower value (inclusive)to
- the upper value (exclusive)- Returns:
- the generator for integer values between
from
andto
-
intsTo
public static Gen<Integer> intsTo(int to)
Creates a generator for int values between0
andto
.- Parameters:
to
- the upper limit (exclusive)- Returns:
- the generator for integer values between
0
andto
-
withProb
public static Gen<Boolean> withProb(double prob)
Creates generator for Boolean values wheretrue
values are created with the given probability.- Parameters:
prob
- the probability fortrue
- Returns:
- the generator of Boolean values
-
oneOf
public static <A> Gen<A> oneOf(A... as)
Creates a generator which creates values from the given set of values with equal probability.- Type Parameters:
A
- the type of value- Parameters:
as
- the values- Returns:
- the generator for the values
-
oneOf
public static <A> Gen<A> oneOf(List<A> as)
Creates a generator which creates values from the given set of values with equal probability.- Type Parameters:
A
- the type of value- Parameters:
as
- the list of values- Returns:
- the generator for the values
-
single
public static <A> Gen<A> single(A a)
Creates a generator which is capable to create a single value. For every call tosample
the same value is returned.- Type Parameters:
A
- the type of the value- Parameters:
a
- the constant value- Returns:
- the generator creating the same value
-
words
public static Gen<String> words(int maxLength)
Creates a generator for generating words from random letters of given maximum length.- Parameters:
maxLength
- the maximum length- Returns:
- the generator for words
-
lists
public static <A> Gen<List<A>> lists(int maxLength, A... elems)
Creates a generator for generating lists from given elements of given maximum length.- Type Parameters:
A
- the element type- Parameters:
maxLength
- the maximum lengthelems
- the elements- Returns:
- the generator for lists
-
lists
public static <A> Gen<FList<A>> lists(int maxLength, Gen<A> elemGen)
Creates a generator for generating lists of given maximum length. The elements are generated by the given generator.- Type Parameters:
A
- the element type- Parameters:
maxLength
- the maximum lengthelemGen
- the generator for elements- Returns:
- the generator for lists
-
pair
public static <A,B> Gen<Pair<A,B>> pair(Gen<A> aGen, Gen<B> bGen)
A generator of pairs of values. The values are generated by two given generators.- Type Parameters:
A
- the type of the elements of the first generatorB
- the type of the elements of the second generator- Parameters:
aGen
- the first generatorbGen
- the second generator- Returns:
- the generator of pairs of values
-
tuple2
public static <A,B> Gen<Tuple2<A,B>> tuple2(Gen<A> aGen, Gen<B> bGen)
A generator of tuples of two values. The values are generated by two given generators.- Type Parameters:
A
- the type of the elements of the first generatorB
- the type of the elements of the second generator- Parameters:
aGen
- the first generatorbGen
- the second generator- Returns:
- the generator of tuple of two values
-
tuple3
public static <A,B,C> Gen<Tuple3<A,B,C>> tuple3(Gen<A> aGen, Gen<B> bGen, Gen<C> cGen)
A generator of tuples of three values. The values are generated by two given generators.- Type Parameters:
A
- the type of the elements of the first generatorB
- the type of the elements of the second generatorC
- the type of the elements of the third generator- Parameters:
aGen
- the first generatorbGen
- the second generatorcGen
- the third generator- Returns:
- the generator of tuple of three values
-
isPrime
private static boolean isPrime(int n)
-
-