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.UniformRandomProvider;
20 import org.apache.commons.rng.sampling.RandomAssert;
21 import org.junit.jupiter.api.Assertions;
22 import org.junit.jupiter.api.Test;
23
24
25
26
27 class ChengBetaSamplerTest {
28
29
30
31 @Test
32 void testConstructorThrowsWithZeroAlpha() {
33 final UniformRandomProvider rng = RandomAssert.seededRNG();
34 final double alpha = 0;
35 final double beta = 1;
36 Assertions.assertThrows(IllegalArgumentException.class,
37 () -> ChengBetaSampler.of(rng, alpha, beta));
38 }
39
40
41
42
43 @Test
44 void testConstructorThrowsWithZeroBeta() {
45 final UniformRandomProvider rng = RandomAssert.seededRNG();
46 final double alpha = 1;
47 final double beta = 0;
48 Assertions.assertThrows(IllegalArgumentException.class,
49 () -> ChengBetaSampler.of(rng, alpha, beta));
50 }
51
52
53
54
55 @Test
56 void testSharedStateSamplerWithAlphaAndBetaAbove1AndAlphaBelowBeta() {
57 testSharedStateSampler(1.23, 4.56);
58 }
59
60
61
62
63 @Test
64 void testSharedStateSamplerWithAlphaAndBetaAbove1AndAlphaAboveBeta() {
65 testSharedStateSampler(4.56, 1.23);
66 }
67
68
69
70
71 @Test
72 void testSharedStateSamplerWithAlphaOrBetaBelow1AndAlphaBelowBeta() {
73 testSharedStateSampler(0.23, 4.56);
74 }
75
76
77
78
79 @Test
80 void testSharedStateSamplerWithAlphaOrBetaBelow1AndAlphaAboveBeta() {
81 testSharedStateSampler(4.56, 0.23);
82 }
83
84
85
86
87
88
89
90 private static void testSharedStateSampler(double alpha, double beta) {
91 final UniformRandomProvider rng1 = RandomAssert.seededRNG();
92 final UniformRandomProvider rng2 = RandomAssert.seededRNG();
93
94 final SharedStateContinuousSampler sampler1 =
95 new ChengBetaSampler(rng1, alpha, beta);
96 final SharedStateContinuousSampler sampler2 = sampler1.withUniformRandomProvider(rng2);
97 RandomAssert.assertProduceSameSequence(sampler1, sampler2);
98 }
99
100
101
102
103
104 @Test
105 void testToString() {
106 final UniformRandomProvider rng = RandomAssert.seededRNG();
107 Assertions.assertTrue(new ChengBetaSampler(rng, 1.0, 2.0).toString()
108 .toLowerCase().contains("beta"));
109 }
110 }