@Test public void testGenerateRandomValues() { LinearRestrictions<BigDecimal> restrictions = new LinearRestrictions<>( BigDecimal.ZERO, BigDecimal.valueOf(4), new NumericGranularity(0)); LinearFieldValueSource<BigDecimal> source = new LinearFieldValueSource<>(restrictions, Collections.emptySet()); Stream<BigDecimal> results = source.generateRandomValues(new JavaUtilRandomNumberGenerator()); assertTrue(results.limit(100).allMatch(x -> x.intValue() >= 0 & x.intValue() < 5)); }
@Override public Stream<T> generateRandomValues(RandomNumberGenerator randomNumberGenerator) { return Stream.generate(() -> restrictions.getGranularity() .getRandom( restrictions.getMin(), restrictions.getGranularity().getNext(restrictions.getMax()), randomNumberGenerator)) .filter(this::notInBlacklist); }
LinearFieldValueSource implements FieldValueSource { @Override public Stream<T> generateRandomValues(RandomNumberGenerator randomNumberGenerator) { return Stream.generate(() -> restrictions.getGranularity() .getRandom( restrictions.getMin(), restrictions.getGranularity().getNext(restrictions.getMax()), randomNumberGenerator)) .filter(this::notInBlacklist); } }
LinearFieldValueSource implements FieldValueSource { @Override public Stream<T> generateRandomValues(RandomNumberGenerator randomNumberGenerator) { return Stream.generate(() -> restrictions.getGranularity() .getRandom( restrictions.getMin(), restrictions.getGranularity().getNext(restrictions.getMax()), randomNumberGenerator)) .filter(this::notInBlacklist); } LinearFieldValueSource(LinearRestrictions<T> restrictions, Set<T> blacklist); }
LinearFieldValueSource implements FieldValueSource { @Override public Stream<T> generateRandomValues(RandomNumberGenerator randomNumberGenerator) { return Stream.generate(() -> restrictions.getGranularity() .getRandom( restrictions.getMin(), restrictions.getGranularity().getNext(restrictions.getMax()), randomNumberGenerator)) .filter(this::notInBlacklist); } LinearFieldValueSource(LinearRestrictions<T> restrictions, Set<T> blacklist); @Override Stream<T> generateAllValues(); @Override Stream<T> generateRandomValues(RandomNumberGenerator randomNumberGenerator); @Override boolean equals(Object obj); @Override int hashCode(); }
LinearFieldValueSource implements FieldValueSource { @Override public Stream<T> generateRandomValues(RandomNumberGenerator randomNumberGenerator) { return Stream.generate(() -> restrictions.getGranularity() .getRandom( restrictions.getMin(), restrictions.getGranularity().getNext(restrictions.getMax()), randomNumberGenerator)) .filter(this::notInBlacklist); } LinearFieldValueSource(LinearRestrictions<T> restrictions, Set<T> blacklist); @Override Stream<T> generateAllValues(); @Override Stream<T> generateRandomValues(RandomNumberGenerator randomNumberGenerator); @Override boolean equals(Object obj); @Override int hashCode();  }