use of java8.util.concurrent.ThreadLocalRandom in project streamsupport by stefan-zobel.
the class ThreadLocalRandomTest method testUnsizedLongsCountSeq.
/**
* A sequential unsized stream of longs generates at least 100 values
*/
public void testUnsizedLongsCountSeq() {
LongAdder counter = new LongAdder();
ThreadLocalRandom r = ThreadLocalRandom.current();
long size = 100;
r.longs().limit(size).forEach(x -> {
counter.increment();
});
assertEquals(counter.sum(), size);
}
use of java8.util.concurrent.ThreadLocalRandom in project streamsupport by stefan-zobel.
the class ThreadLocalRandomTest method testNextDoubleBadBound.
/**
* nextDouble(bound) throws IllegalArgumentException
*/
public void testNextDoubleBadBound() {
ThreadLocalRandom r = ThreadLocalRandom.current();
executeAndCatchIAE(() -> r.nextDouble(0.0));
executeAndCatchIAE(() -> r.nextDouble(-0.0));
executeAndCatchIAE(() -> r.nextDouble(+0.0));
executeAndCatchIAE(() -> r.nextDouble(-1.0));
executeAndCatchIAE(() -> r.nextDouble(Double.NaN));
executeAndCatchIAE(() -> r.nextDouble(Double.NEGATIVE_INFINITY));
// Returns Double.MAX_VALUE
// executeAndCatchIAE(() -> r.nextDouble(Double.POSITIVE_INFINITY));
}
use of java8.util.concurrent.ThreadLocalRandom in project streamsupport by stefan-zobel.
the class ThreadLocalRandomTest method testBadStreamBounds.
/**
* Invoking bounded ints, long, doubles, with illegal bounds throws
* IllegalArgumentException
*/
public void testBadStreamBounds() {
ThreadLocalRandom r = ThreadLocalRandom.current();
executeAndCatchIAE(() -> r.ints(2, 1));
executeAndCatchIAE(() -> r.ints(10, 42, 42));
executeAndCatchIAE(() -> r.longs(-1L, -1L));
executeAndCatchIAE(() -> r.longs(10, 1L, -2L));
testDoubleBadOriginBound((o, b) -> r.doubles(10, o, b));
}
use of java8.util.concurrent.ThreadLocalRandom in project streamsupport by stefan-zobel.
the class ThreadLocalRandomTest method testUnsizedIntsCountSeq.
/**
* A sequential unsized stream of ints generates at least 100 values
*/
public void testUnsizedIntsCountSeq() {
LongAdder counter = new LongAdder();
ThreadLocalRandom r = ThreadLocalRandom.current();
long size = 100;
r.ints().limit(size).forEach(x -> {
counter.increment();
});
assertEquals(counter.sum(), size);
}
use of java8.util.concurrent.ThreadLocalRandom in project streamsupport by stefan-zobel.
the class Collection8Test method testObjectMethods.
@Test(dataProvider = "Source")
public void testObjectMethods(String description, Supplier<CollectionImplementation> sci) {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
Collection c = sci.get().emptyCollection();
for (int n = rnd.nextInt(3); n-- > 0; ) c.add(sci.get().makeElement(rnd.nextInt()));
assertEquals(c, c);
if (c instanceof List) {
List<?> copy = new ArrayList(c);
assertEquals(copy, c);
assertEquals(c, copy);
assertEquals(copy.hashCode(), c.hashCode());
}
if (c instanceof Set) {
Set<?> copy = new HashSet(c);
assertEquals(copy, c);
assertEquals(c, copy);
assertEquals(copy.hashCode(), c.hashCode());
}
}
Aggregations