Closed diveshpremdeep closed 6 years ago
No and yes.
There is no way to avoid a Gen generating duplicate values, but this doesn't actually matter as quicktheories will only assess each value combination (at most) once.
So for the simple case of a Gen
Thanks for your reply.
I don't understand the this doesn't actually matter as quicktheories will only assess each value combination (at most) once
bit though.
For example
public class RandomTest implements WithQuickTheories {
@Test
public void doesNotRepeat() {
qt()
.forAll(arbitrary().pick(1,2,3))
.checkAssert( i -> System.out.println(i));
}
@Test
public void doesNotRepeatCombination() {
qt()
.forAll(arbitrary().pick(1,2,3), arbitrary().pick("a", "b", "c"))
.checkAssert( (i,s) -> System.out.println(i + " : " + s));
}
}
Gives the output
1
3
2
1 : a
3 : c
1 : c
3 : a
3 : b
2 : a
1 : b
2 : b
2 : c
Only three output values are possible for each Gen. QuickTheories discards all duplicate combinations.
Cheers, I understand now.
Is there any way I can configure a
Gen<T>
to provide unique values (i.e. do not provide a value that has already been generated)?Simplest case, is there any way I can configure a
Gen<String>
to always provide me unique strings?