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