1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.rng.core.source32;
18
19 import org.apache.commons.rng.core.RandomAssert;
20 import org.junit.jupiter.api.Test;
21
22 class XoRoShiRo64StarTest {
23
24 private static final int SEED_SIZE = 2;
25
26 @Test
27 void testReferenceCode() {
28
29
30
31
32 final int[] seed = {
33 0x012de1ba, 0xa5a818b8,
34 };
35
36 final int[] expectedSequence = {
37 0xd72accde, 0x29cbd26c, 0xa00fd44a, 0xa4d612c8,
38 0xf9c7572b, 0xce94c084, 0x47a3d7ee, 0xb64aa982,
39 0x67a9b2a4, 0x0c3d61a8, 0x8f70f7fa, 0xd1edbd63,
40 0xac954b3a, 0xd7fe941e, 0xaa38e658, 0x019ecf61,
41 0xcded7d7c, 0xd6588891, 0x4414454a, 0xb3c3a124,
42 0x4a16fcfe, 0x3fb393c2, 0x4d8d14d6, 0x3a02c906,
43 0x0c82f080, 0x174186c4, 0x1199966b, 0x12b83d6a,
44 0xe697999e, 0x9df4d2f4, 0x5a5a0879, 0xc44ad6b4,
45 0x96a9adc3, 0x4603c20f, 0x3171ca57, 0x66e349c9,
46 0xa77dba19, 0xbe4f279d, 0xf5cd3402, 0x1962933d,
47 };
48
49 RandomAssert.assertEquals(expectedSequence, new XoRoShiRo64Star(seed));
50 }
51
52 @Test
53 void testConstructorWithZeroSeedIsNonFunctional() {
54 RandomAssert.assertNextIntZeroOutput(new XoRoShiRo64Star(new int[SEED_SIZE]), 2 * SEED_SIZE);
55 }
56
57 @Test
58 void testConstructorWithSingleBitSeedIsFunctional() {
59 RandomAssert.assertIntArrayConstructorWithSingleBitSeedIsFunctional(XoRoShiRo64Star.class, SEED_SIZE);
60 }
61
62 @Test
63 void testConstructorWithoutFullLengthSeed() {
64
65 RandomAssert.assertNextLongNonZeroOutput(new XoRoShiRo64Star(new int[] {0x012de1ba}),
66 SEED_SIZE, SEED_SIZE);
67 }
68
69 @Test
70 void testElementConstructor() {
71 final int[] seed = {
72 0x012de1ba, 0xa5a818b8,
73 };
74 final XoRoShiRo64Star rng1 = new XoRoShiRo64Star(seed);
75 final XoRoShiRo64Star rng2 = new XoRoShiRo64Star(seed[0], seed[1]);
76 RandomAssert.assertNextIntEquals(seed.length * 2, rng1, rng2);
77 }
78 }