Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ final class UniformDoubleGenerator extends UniformIntersectionRestrictableGenera
*/
public UniformDoubleGenerator(Generators g, double lo, double hi) {
super(g, lo, hi);
if (Double.compare(lo, hi) >= 0) {
throw new EmptyGeneratorException();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ final class UniformFloatGenerator extends UniformIntersectionRestrictableGenerat
*/
public UniformFloatGenerator(Generators g, float lo, float hi) {
super(g, lo, hi);
if (Float.compare(lo, hi) >= 0) {
throw new EmptyGeneratorException();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,13 @@ static void testEmptyGenerators() {

Asserts.assertThrows(EmptyGeneratorException.class, () -> G.uniformDoubles(1, 0));
Asserts.assertNotNull(G.uniformDoubles(0, 1));
Asserts.assertNotNull(G.uniformDoubles(0, 0));
Asserts.assertThrows(EmptyGeneratorException.class, () -> G.uniformDoubles(0, 0));
Asserts.assertThrows(EmptyGeneratorException.class, () -> G.uniformDoubles(0, 1).restricted(1.1d, 2.4d));
Asserts.assertNotNull(G.uniformDoubles(0, 1).restricted(0.9d, 2.4d));

Asserts.assertThrows(EmptyGeneratorException.class, () -> G.uniformFloats(1, 0));
Asserts.assertNotNull(G.uniformFloats(0, 1));
Asserts.assertNotNull(G.uniformFloats(0, 0));
Asserts.assertThrows(EmptyGeneratorException.class, () -> G.uniformFloats(0, 0));
Asserts.assertThrows(EmptyGeneratorException.class, () -> G.uniformFloats(0, 1).restricted(1.1f, 2.4f));
Asserts.assertNotNull(G.uniformFloats(0, 1).restricted(0.9f, 2.4f));

Expand Down Expand Up @@ -592,8 +592,13 @@ static void testFuzzy() {

var floatBoundGen = G.uniformFloats();
for (int j = 0; j < 500; j++) {
float a = floatBoundGen.next(), b = floatBoundGen.next();
float lo = Math.min(a, b), hi = Math.max(a, b);
float lo = 1, hi = 0;
// Failure of a single round is very rare, repeated failure even rarer.
while (lo >= hi) {
float a = floatBoundGen.next(), b = floatBoundGen.next();
lo = Math.min(a, b);
hi = Math.max(a, b);
}
var gb = G.uniformFloats(lo, hi);
for (int i = 0; i < 10_000; i++) {
float x = gb.next();
Expand All @@ -604,8 +609,13 @@ static void testFuzzy() {

var doubleBoundGen = G.uniformDoubles();
for (int j = 0; j < 500; j++) {
double a = doubleBoundGen.next(), b = doubleBoundGen.next();
double lo = Math.min(a, b), hi = Math.max(a, b);
double lo = 1, hi = 0;
// Failure of a single round is very rare, repeated failure even rarer.
while (lo >= hi) {
double a = doubleBoundGen.next(), b = doubleBoundGen.next();
lo = Math.min(a, b);
hi = Math.max(a, b);
}
var gb = G.uniformDoubles(lo, hi);
for (int i = 0; i < 10_000; i++) {
double x = gb.next();
Expand Down