use of java8.lang.Doubles in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testBadStreamBounds.
/**
* Invoking bounded ints, long, doubles, with illegal bounds throws
* IllegalArgumentException
*/
@SuppressWarnings("unused")
public void testBadStreamBounds() {
SplittableRandom r = new SplittableRandom();
Runnable[] throwingActions = { () -> {
java8.util.stream.IntStream x = r.ints(2, 1);
}, () -> {
java8.util.stream.IntStream x = r.ints(10, 42, 42);
}, () -> {
java8.util.stream.LongStream x = r.longs(-1L, -1L);
}, () -> {
java8.util.stream.LongStream x = r.longs(10, 1L, -2L);
}, () -> {
java8.util.stream.DoubleStream x = r.doubles(0.0, 0.0);
}, () -> {
java8.util.stream.DoubleStream x = r.doubles(10, .5, .4);
} };
assertThrows(IllegalArgumentException.class, throwingActions);
}
use of java8.lang.Doubles in project streamsupport by stefan-zobel.
the class ThreadLocalRandom8Test method testBadStreamBounds.
/**
* Invoking bounded ints, long, doubles, with illegal bounds throws
* IllegalArgumentException
*/
public void testBadStreamBounds() {
ThreadLocalRandom r = ThreadLocalRandom.current();
Runnable[] throwingActions = { () -> r.ints(2, 1), () -> r.ints(10, 42, 42), () -> r.longs(-1L, -1L), () -> r.longs(10, 1L, -2L), () -> r.doubles(0.0, 0.0), () -> r.doubles(10, .5, .4) };
assertThrows(IllegalArgumentException.class, throwingActions);
}
use of java8.lang.Doubles in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testDoublesCount.
/**
* A parallel sized stream of doubles generates the given number of values
*/
public void testDoublesCount() {
final LongAdder counter = new LongAdder();
SplittableRandom r = new SplittableRandom();
long size = 0;
for (int reps = 0; reps < REPS; ++reps) {
counter.reset();
r.doubles(size).parallel().forEach(new DoubleConsumer() {
@Override
public void accept(double x) {
counter.increment();
}
});
assertEquals(counter.sum(), size);
size += 524959;
}
}
use of java8.lang.Doubles in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testBoundedDoubles.
/**
* Each of a parallel sized stream of bounded doubles is within bounds
*/
public void testBoundedDoubles() {
final AtomicInteger fails = new AtomicInteger(0);
SplittableRandom r = new SplittableRandom();
long size = 456;
for (double least = 0.00011; least < 1.0e20; least *= 9) {
for (double bound = least * 1.0011; bound < 1.0e20; bound *= 17) {
final double lo = least, hi = bound;
r.doubles(size, lo, hi).parallel().forEach(new DoubleConsumer() {
@Override
public void accept(double x) {
if (x < lo || x >= hi)
fails.getAndIncrement();
}
});
}
}
assertEquals(fails.get(), 0);
}
use of java8.lang.Doubles in project streamsupport by stefan-zobel.
the class SplittableRandomTest method testBadStreamBounds.
/**
* Invoking bounded ints, long, doubles, with illegal bounds throws
* IllegalArgumentException
*/
public void testBadStreamBounds() {
final SplittableRandom r = new SplittableRandom();
executeAndCatchIAE(new Runnable() {
@Override
public void run() {
r.ints(2, 1);
}
});
executeAndCatchIAE(new Runnable() {
@Override
public void run() {
r.ints(10, 42, 42);
}
});
executeAndCatchIAE(new Runnable() {
@Override
public void run() {
r.longs(-1L, -1L);
}
});
executeAndCatchIAE(new Runnable() {
@Override
public void run() {
r.longs(10, 1L, -2L);
}
});
testDoubleBadOriginBound(new BiConsumer<Double, Double>() {
@Override
public void accept(Double o, Double b) {
r.doubles(10, o, b);
}
});
}
Aggregations