Skip to content

Commit 2926fdc

Browse files
committed
Split API and engine
fixes pholser#254
1 parent cc40e74 commit 2926fdc

File tree

194 files changed

+645
-254
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+645
-254
lines changed

core-api/pom.xml

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
4+
<parent>
5+
<groupId>com.pholser</groupId>
6+
<artifactId>junit-quickcheck</artifactId>
7+
<version>0.10-SNAPSHOT</version>
8+
</parent>
9+
10+
<artifactId>junit-quickcheck-core-api</artifactId>
11+
<version>0.10-SNAPSHOT</version>
12+
<packaging>jar</packaging>
13+
<name>junit-quickcheck-core-api</name>
14+
<description>Property-based testing, JUnit-style: core functionality</description>
15+
<url>http://github.com/pholser/junit-quickcheck</url>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.javaruntype</groupId>
20+
<artifactId>javaruntype</artifactId>
21+
</dependency>
22+
23+
<dependency>
24+
<groupId>junit</groupId>
25+
<artifactId>junit</artifactId>
26+
<scope>test</scope>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.hamcrest</groupId>
30+
<artifactId>hamcrest-core</artifactId>
31+
<scope>test</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.hamcrest</groupId>
35+
<artifactId>hamcrest-library</artifactId>
36+
<scope>test</scope>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.mockito</groupId>
40+
<artifactId>mockito-all</artifactId>
41+
<scope>test</scope>
42+
</dependency>
43+
<dependency>
44+
<groupId>ch.qos.logback</groupId>
45+
<artifactId>logback-classic</artifactId>
46+
<scope>test</scope>
47+
</dependency>
48+
</dependencies>
49+
50+
<build>
51+
<plugins>
52+
<plugin>
53+
<groupId>org.apache.maven.plugins</groupId>
54+
<artifactId>maven-release-plugin</artifactId>
55+
</plugin>
56+
<plugin>
57+
<groupId>org.apache.maven.plugins</groupId>
58+
<artifactId>maven-compiler-plugin</artifactId>
59+
</plugin>
60+
<plugin>
61+
<groupId>org.jacoco</groupId>
62+
<artifactId>jacoco-maven-plugin</artifactId>
63+
</plugin>
64+
<plugin>
65+
<groupId>org.apache.maven.plugins</groupId>
66+
<artifactId>maven-checkstyle-plugin</artifactId>
67+
</plugin>
68+
<plugin>
69+
<groupId>org.apache.maven.plugins</groupId>
70+
<artifactId>maven-pmd-plugin</artifactId>
71+
</plugin>
72+
<plugin>
73+
<groupId>org.codehaus.mojo</groupId>
74+
<artifactId>findbugs-maven-plugin</artifactId>
75+
</plugin>
76+
</plugins>
77+
</build>
78+
</project>

core/src/main/java/com/pholser/junit/quickcheck/From.java renamed to core-api/src/main/java/com/pholser/junit/quickcheck/From.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ a copy of this software and associated documentation files (the
2929
import java.lang.annotation.Retention;
3030
import java.lang.annotation.Target;
3131

32-
import com.pholser.junit.quickcheck.generator.Generator;
33-
3432
import static java.lang.annotation.ElementType.*;
3533
import static java.lang.annotation.RetentionPolicy.*;
3634

35+
import com.pholser.junit.quickcheck.generator.Generator;
36+
3737
/**
3838
* <p>Mark a parameter of a {@link Property} method with this annotation to
3939
* have random values supplied to it via the specified

core/src/main/java/com/pholser/junit/quickcheck/Mode.java renamed to core-api/src/main/java/com/pholser/junit/quickcheck/Mode.java

+2-16
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ a copy of this software and associated documentation files (the
2525

2626
package com.pholser.junit.quickcheck;
2727

28-
import com.pholser.junit.quickcheck.internal.ParameterSampler;
29-
import com.pholser.junit.quickcheck.internal.sampling.ExhaustiveParameterSampler;
30-
import com.pholser.junit.quickcheck.internal.sampling.TupleParameterSampler;
31-
3228
/**
3329
* Represents different modes of execution of property-based tests.
3430
*
@@ -40,23 +36,13 @@ public enum Mode {
4036
* Verify {@link Property#trials()} tuples of arguments for a property's
4137
* parameters.
4238
*/
43-
SAMPLING {
44-
@Override ParameterSampler sampler(int defaultSampleSize) {
45-
return new TupleParameterSampler(defaultSampleSize);
46-
}
47-
},
39+
SAMPLING,
4840

4941
/**
5042
* Generate {@link Property#trials()} arguments for each parameter
5143
* property, and verify the cross-products of those sets of arguments.
5244
* This behavior mirrors that of the JUnit
5345
* {@link org.junit.experimental.theories.Theories} runner.
5446
*/
55-
EXHAUSTIVE {
56-
@Override ParameterSampler sampler(int defaultSampleSize) {
57-
return new ExhaustiveParameterSampler(defaultSampleSize);
58-
}
59-
};
60-
61-
abstract ParameterSampler sampler(int defaultSampleSize);
47+
EXHAUSTIVE;
6248
}

core/src/main/java/com/pholser/junit/quickcheck/Pair.java renamed to core-api/src/main/java/com/pholser/junit/quickcheck/Pair.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,16 @@ a copy of this software and associated documentation files (the
2525

2626
package com.pholser.junit.quickcheck;
2727

28+
import com.pholser.junit.quickcheck.generator.Gen;
29+
2830
import java.util.Objects;
2931

3032
/**
3133
* Typed pair of elements.
3234
*
3335
* @param <F> type of first element of pair
3436
* @param <S> type of second element of pair
35-
* @see com.pholser.junit.quickcheck.generator.Gen#frequency(Pair, Pair[])
37+
* @see Gen#frequency(Pair, Pair[])
3638
*/
3739
public final class Pair<F, S> {
3840
public final F first;

core/src/main/java/com/pholser/junit/quickcheck/Produced.java renamed to core-api/src/main/java/com/pholser/junit/quickcheck/Produced.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ a copy of this software and associated documentation files (the
3131
import static java.lang.annotation.ElementType.*;
3232
import static java.lang.annotation.RetentionPolicy.*;
3333

34+
import com.pholser.junit.quickcheck.generator.Generator;
35+
3436
/**
3537
* <p>Mark a parameter of a {@link Property} method with this annotation to
3638
* have random values supplied to it via one of the
37-
* {@link com.pholser.junit.quickcheck.generator.Generator}s specified by the
39+
* {@link Generator}s specified by the
3840
* aggregated {@link From} annotations.</p>
3941
*
4042
* <p>Alternatively, you can specify many generators via many repetitions of

core/src/main/java/com/pholser/junit/quickcheck/internal/generator/NullAllowed.java renamed to core-api/src/main/java/com/pholser/junit/quickcheck/generator/NullAllowed.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.pholser.junit.quickcheck.internal.generator;
1+
package com.pholser.junit.quickcheck.generator;
22

33
import java.lang.annotation.Retention;
44
import java.lang.annotation.Target;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
package com.pholser.junit.quickcheck.random;
2+
3+
import java.math.BigInteger;
4+
import java.time.Duration;
5+
import java.time.Instant;
6+
import java.util.Collection;
7+
import java.util.Random;
8+
9+
public interface SourceOfRandomness {
10+
/**
11+
* <p>Gives a JDK source of randomness, with the same internal state as
12+
* this source of randomness.</p>
13+
*
14+
* @return a JDK "clone" of self
15+
*/
16+
Random toJDKRandom();
17+
18+
/**
19+
* @return a uniformly distributed boolean value
20+
* @see Random#nextBoolean()
21+
*/
22+
boolean nextBoolean();
23+
24+
/**
25+
* @param bytes a byte array to fill with random values
26+
* @see Random#nextBytes(byte[])
27+
*/
28+
void nextBytes(byte[] bytes);
29+
30+
/**
31+
* Gives an array of a given length containing random bytes.
32+
*
33+
* @param count the desired length of the random byte array
34+
* @return random bytes
35+
* @see Random#nextBytes(byte[])
36+
*/
37+
byte[] nextBytes(int count);
38+
39+
/**
40+
* @return a uniformly distributed random {@code double} value in the
41+
* interval {@code [0.0, 1.0)}
42+
* @see Random#nextDouble()
43+
*/
44+
double nextDouble();
45+
46+
/**
47+
* @return a uniformly distributed random {@code float} value in the
48+
* interval {@code [0.0, 1.0)}
49+
* @see Random#nextFloat()
50+
*/
51+
float nextFloat();
52+
53+
/**
54+
* @return a Gaussian-distributed random double value
55+
* @see Random#nextGaussian()
56+
*/
57+
double nextGaussian();
58+
59+
/**
60+
* @return a uniformly distributed random {@code int} value
61+
* @see Random#nextInt()
62+
*/
63+
int nextInt();
64+
65+
/**
66+
* @param n upper bound
67+
* @return a uniformly distributed random {@code int} value in the interval
68+
* {@code [0, n)}
69+
* @see Random#nextInt(int)
70+
*/
71+
int nextInt(int n);
72+
73+
/**
74+
* @return a uniformly distributed random {@code long} value
75+
* @see Random#nextLong()
76+
*/
77+
long nextLong();
78+
79+
/**
80+
* @param seed value with which to seed this source of randomness
81+
* @see Random#setSeed(long)
82+
*/
83+
void setSeed(long seed);
84+
85+
/**
86+
* @return the value used to initially seed this source of randomness
87+
*/
88+
long seed();
89+
90+
/**
91+
* Gives a random {@code byte} value, uniformly distributed across the
92+
* interval {@code [min, max]}.
93+
*
94+
* @param min lower bound of the desired interval
95+
* @param max upper bound of the desired interval
96+
* @return a random value
97+
*/
98+
byte nextByte(byte min, byte max);
99+
100+
/**
101+
* Gives a random {@code char} value, uniformly distributed across the
102+
* interval {@code [min, max]}.
103+
*
104+
* @param min lower bound of the desired interval
105+
* @param max upper bound of the desired interval
106+
* @return a random value
107+
*/
108+
char nextChar(char min, char max);
109+
110+
/**
111+
* <p>Gives a random {@code double} value in the interval
112+
* {@code [min, max)}.</p>
113+
*
114+
* <p>This naive implementation takes a random {@code double} value from
115+
* {@link Random#nextDouble()} and scales/shifts the value into the desired
116+
* interval. This may give surprising results for large ranges.</p>
117+
*
118+
* @param min lower bound of the desired interval
119+
* @param max upper bound of the desired interval
120+
* @return a random value
121+
*/
122+
double nextDouble(double min, double max);
123+
124+
/**
125+
* <p>Gives a random {@code float} value in the interval
126+
* {@code [min, max)}.</p>
127+
*
128+
* <p>This naive implementation takes a random {@code float} value from
129+
* {@link Random#nextFloat()} and scales/shifts the value into the desired
130+
* interval. This may give surprising results for large ranges.</p>
131+
*
132+
* @param min lower bound of the desired interval
133+
* @param max upper bound of the desired interval
134+
* @return a random value
135+
*/
136+
float nextFloat(float min, float max);
137+
138+
/**
139+
* Gives a random {@code int} value, uniformly distributed across the
140+
* interval {@code [min, max]}.
141+
*
142+
* @param min lower bound of the desired interval
143+
* @param max upper bound of the desired interval
144+
* @return a random value
145+
*/
146+
int nextInt(int min, int max);
147+
148+
/**
149+
* Gives a random {@code long} value, uniformly distributed across the
150+
* interval {@code [min, max]}.
151+
*
152+
* @param min lower bound of the desired interval
153+
* @param max upper bound of the desired interval
154+
* @return a random value
155+
*/
156+
long nextLong(long min, long max);
157+
158+
/**
159+
* Gives a random {@code short} value, uniformly distributed across the
160+
* interval {@code [min, max]}.
161+
*
162+
* @param min lower bound of the desired interval
163+
* @param max upper bound of the desired interval
164+
* @return a random value
165+
*/
166+
short nextShort(short min, short max);
167+
168+
/**
169+
* Gives a random {@code BigInteger} representable by the given number
170+
* of bits.
171+
*
172+
* @param numberOfBits the desired number of bits
173+
* @return a random {@code BigInteger}
174+
* @see BigInteger#BigInteger(int, Random)
175+
*/
176+
BigInteger nextBigInteger(int numberOfBits);
177+
178+
/**
179+
* Gives a random {@code Instant} value, uniformly distributed across the
180+
* interval {@code [min, max]}.
181+
*
182+
* @param min lower bound of the desired interval
183+
* @param max upper bound of the desired interval
184+
* @return a random value
185+
*/
186+
Instant nextInstant(Instant min, Instant max);
187+
188+
/**
189+
* Gives a random {@code Duration} value, uniformly distributed across the
190+
* interval {@code [min, max]}.
191+
*
192+
* @param min lower bound of the desired interval
193+
* @param max upper bound of the desired interval
194+
* @return a random value
195+
*/
196+
Duration nextDuration(Duration min, Duration max);
197+
198+
/**
199+
* Gives a random element of the given collection.
200+
*
201+
* @param <T> type of items in the collection
202+
* @param items a collection
203+
* @return a randomly chosen element from the collection
204+
*/
205+
<T> T choose(Collection<T> items);
206+
207+
/**
208+
* Gives a random element of the given array.
209+
*
210+
* @param <T> type of items in the array
211+
* @param items an array
212+
* @return a randomly chosen element from the array
213+
*/
214+
<T> T choose(T[] items);
215+
}

0 commit comments

Comments
 (0)