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.apache.commons.rng.RestorableUniformRandomProvider;
20 import org.apache.commons.rng.UniformRandomProvider;
21 import org.apache.commons.rng.sampling.RandomAssert;
22 import org.apache.commons.rng.simple.RandomSource;
23 import org.junit.Test;
24
25
26
27
28 public class AhrensDieterExponentialSamplerTest {
29
30
31
32 @Test(expected = IllegalArgumentException.class)
33 public void testConstructorThrowsWithZeroMean() {
34 final RestorableUniformRandomProvider rng =
35 RandomSource.create(RandomSource.SPLIT_MIX_64);
36 final double mean = 0;
37 AhrensDieterExponentialSampler.of(rng, mean);
38 }
39
40
41
42
43 @Test
44 public void testSharedStateSampler() {
45 final UniformRandomProvider rng1 = RandomSource.create(RandomSource.SPLIT_MIX_64, 0L);
46 final UniformRandomProvider rng2 = RandomSource.create(RandomSource.SPLIT_MIX_64, 0L);
47 final double mean = 1.23;
48 final SharedStateContinuousSampler sampler1 =
49 AhrensDieterExponentialSampler.of(rng1, mean);
50 final SharedStateContinuousSampler sampler2 = sampler1.withUniformRandomProvider(rng2);
51 RandomAssert.assertProduceSameSequence(sampler1, sampler2);
52 }
53 }