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.simple.RandomSource;
21 import org.junit.Assert;
22 import org.junit.Test;
23
24
25
26
27
28 public class SamplerBaseTest {
29
30
31
32 @SuppressWarnings("deprecation")
33 private static class SimpleSampler extends SamplerBase {
34 SimpleSampler(UniformRandomProvider rng) {
35 super(rng);
36 }
37
38 @Override
39 public double nextDouble() {
40 return super.nextDouble();
41 }
42
43 @Override
44 public int nextInt() {
45 return super.nextInt();
46 }
47
48 @Override
49 public int nextInt(int max) {
50 return super.nextInt(max);
51 }
52
53 @Override
54 public long nextLong() {
55 return super.nextLong();
56 }
57 }
58
59 @Test
60 public void testNextMethods() {
61 final UniformRandomProvider rng1 = RandomSource.create(RandomSource.SPLIT_MIX_64, 0L);
62 final UniformRandomProvider rng2 = RandomSource.create(RandomSource.SPLIT_MIX_64, 0L);
63 final SimpleSampler sampler = new SimpleSampler(rng2);
64 final int n = 256;
65 for (int i = 0; i < 3; i++) {
66 Assert.assertEquals(rng1.nextDouble(), sampler.nextDouble(), 0);
67 Assert.assertEquals(rng1.nextInt(), sampler.nextInt());
68 Assert.assertEquals(rng1.nextInt(n), sampler.nextInt(n));
69 Assert.assertEquals(rng1.nextLong(), sampler.nextLong());
70 }
71 }
72
73 @Test
74 public void testToString() {
75 final UniformRandomProvider rng = RandomSource.create(RandomSource.SPLIT_MIX_64, 0L);
76 final SimpleSampler sampler = new SimpleSampler(rng);
77 Assert.assertTrue(sampler.toString().contains("rng"));
78 }
79 }