Doubles { static Gen<Double> between(double min, double max) { ArgumentAssertions.checkArguments(min <= max, "Cannot have the maximum (%s) smaller than the min (%s)", max, min); double adjustedMax = max - min; return fromZeroToOne().map(d -> (d * adjustedMax) + min); }    }
@Test public void generatesLimitsWithinPositiveRange() { Gen<Double> testee = Doubles.between(0, Double.MAX_VALUE); assertThatGenerator(testee).generatesTheMinAndMax(0d, Double.MAX_VALUE); }
@Test public void generatesLimitsWithinNegativeRange() { Gen<Double> testee = Doubles.between(-42.0d, -1.0d); assertThatGenerator(testee).generatesTheMinAndMax(-42.0d, -1.0d); }
@Test public void generatesLimitsWithinRangeSpanningZero() { Gen<Double> testee = Doubles.between(-42.0d, 42.0d); assertThatGenerator(testee).generatesTheMinAndMax(-42.0d, 42.0d); }
@Test public void generatesValuesAcrossPositiveRange() { Gen<Double> testee = Doubles.between(10d, 1000d); List<Double> vals = generateValues(testee, 100); assertThat(vals.stream().filter( d -> d < 100d).count()).isGreaterThan(5); assertThat(vals.stream().filter( d -> d > 500d).count()).isGreaterThan(40); assertThat(vals.stream().filter( d -> d > 900d).count()).isLessThan(10); }
@Test public void generatesValuesAcrossRangeSpanningZero() { Gen<Double> testee = Doubles.between(-10d, 10d); List<Double> vals = generateValues(testee, 100); assertThat(vals.stream().filter( d -> d < 0d).count()).isGreaterThan(40); assertThat(vals.stream().filter( d -> d < -5d).count()).isLessThan(25); assertThat(vals.stream().filter( d -> d > 0d).count()).isGreaterThan(40); assertThat(vals.stream().filter( d -> d > 5d).count()).isLessThan(25); }
@Test(expected = IllegalArgumentException.class) public void doesNotAllowInvalidRanges() { Doubles.between(1d, 0d); }