Minimum size annotation is not respected for sets
johnwright opened this issue · 4 comments
When setting e.g. Size(min = 2, max = 5)
on a java.util.Set
, the minimum size can sometimes be 1 instead of 2.
Adding @Distinct
is a workaround, but it's not obvious that a set will be generated with a size less than the specified min.
It's easy to see when testing with enums. Here's a small tweak to SizeConstrainedSetPropertyParameterTypesTest
that shows the behaviour:
public enum TestEnum {
E1, E2, E3, E4, E5
}
@RunWith(JUnitQuickcheck.class)
public static class SizeConstrainedSets {
@Property public void shouldHold(@Size(min = 2, max = 5) Set<TestEnum> items) {
assertThat(items.size(), lessThanOrEqualTo(5));
assertThat(items.size(), greaterThanOrEqualTo(2));
}
}
@johnwright Thanks for noting this. Will investigate.
I think the simplest fix would be to override configure(Size)
in SetGenerator
, something like this (not tested!):
@Override public void configure(@Size size) {
super.configure(size);
this.distinct = true;
}
@johnwright I believe I've got this corrected in 0.9.3. Have a look at your convenience, and let me know how it goes. Thanks again!
Haven't heard back ... I'm assuming this is working OK in 0.9.3. Feel free to reopen if such isn't the case. Thanks!