1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.rng.sampling.distribution;
18
19 import org.junit.Assert;
20 import org.junit.Test;
21 import org.apache.commons.rng.simple.RandomSource;
22 import org.apache.commons.rng.UniformRandomProvider;
23
24
25
26
27 public class ZigguratNormalizedGaussianSamplerTest {
28
29 @Test(expected = StackOverflowError.class)
30 public void testInfiniteLoop() {
31
32
33 final UniformRandomProvider bad = new UniformRandomProvider() {
34 public long nextLong(long n) { return 0; }
35 public long nextLong() { return Long.MAX_VALUE; }
36 public int nextInt(int n) { return 0; }
37 public int nextInt() { return Integer.MAX_VALUE; }
38 public float nextFloat() { return 1; }
39 public double nextDouble() { return 1;}
40 public void nextBytes(byte[] bytes, int start, int len) {}
41 public void nextBytes(byte[] bytes) {}
42 public boolean nextBoolean() { return false; }
43 };
44
45
46 new ZigguratNormalizedGaussianSampler(bad).sample();
47 }
48 }