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 RejectionInversionZipfSamplerTest {
29
30
31
32 @Test(expected = IllegalArgumentException.class)
33 public void testConstructorThrowsWithZeroNumberOfElements() {
34 final RestorableUniformRandomProvider rng =
35 RandomSource.create(RandomSource.SPLIT_MIX_64);
36 final int numberOfElements = 0;
37 final double exponent = 1;
38 RejectionInversionZipfSampler.of(rng, numberOfElements, exponent);
39 }
40
41
42
43
44 @Test(expected = IllegalArgumentException.class)
45 public void testConstructorThrowsWithZeroExponent() {
46 final RestorableUniformRandomProvider rng =
47 RandomSource.create(RandomSource.SPLIT_MIX_64);
48 final int numberOfElements = 1;
49 final double exponent = 0;
50 RejectionInversionZipfSampler.of(rng, numberOfElements, exponent);
51 }
52
53
54
55
56 @Test
57 public void testSharedStateSampler() {
58 final UniformRandomProvider rng1 = RandomSource.create(RandomSource.SPLIT_MIX_64, 0L);
59 final UniformRandomProvider rng2 = RandomSource.create(RandomSource.SPLIT_MIX_64, 0L);
60 final int numberOfElements = 7;
61 final double exponent = 1.23;
62 final SharedStateDiscreteSampler sampler1 =
63 RejectionInversionZipfSampler.of(rng1, numberOfElements, exponent);
64 final SharedStateDiscreteSampler sampler2 = sampler1.withUniformRandomProvider(rng2);
65 RandomAssert.assertProduceSameSequence(sampler1, sampler2);
66 }
67 }