下面列出了java.util.concurrent.ThreadLocalRandom#longs ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Invoking sized ints, long, doubles, with negative sizes throws
* IllegalArgumentException
*/
public void testBadStreamSize() {
ThreadLocalRandom r = ThreadLocalRandom.current();
Runnable[] throwingActions = {
() -> r.ints(-1L),
() -> r.ints(-1L, 2, 3),
() -> r.longs(-1L),
() -> r.longs(-1L, -1L, 1L),
() -> r.doubles(-1L),
() -> r.doubles(-1L, .5, .6),
};
assertThrows(IllegalArgumentException.class, throwingActions);
}
/**
* 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);
}
/**
* Invoking sized ints, long, doubles, with negative sizes throws
* IllegalArgumentException
*/
public void testBadStreamSize() {
ThreadLocalRandom r = ThreadLocalRandom.current();
Runnable[] throwingActions = {
() -> r.ints(-1L),
() -> r.ints(-1L, 2, 3),
() -> r.longs(-1L),
() -> r.longs(-1L, -1L, 1L),
() -> r.doubles(-1L),
() -> r.doubles(-1L, .5, .6),
};
assertThrows(IllegalArgumentException.class, throwingActions);
}
/**
* 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);
}