View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.rng.simple;
18  
19  import org.junit.Assert;
20  import org.junit.Test;
21  
22  /**
23   * Tests for {@link RandomSource}.
24   */
25  public class RandomSourceTest {
26      @Test
27      public void testCreateInt() {
28          final int n = 4;
29          for (int i = 0; i < n; i++) {
30              // Can fail, but unlikely given the range.
31              Assert.assertNotEquals(RandomSource.createInt(),
32                                     RandomSource.createInt());
33          }
34      }
35  
36      @Test
37      public void testCreateLong() {
38          final int n = 6;
39          for (int i = 0; i < n; i++) {
40              // Can fail, but unlikely given the range.
41              Assert.assertNotEquals(RandomSource.createLong(),
42                                     RandomSource.createLong());
43          }
44      }
45  
46      @Test
47      public void testCreateIntArray() {
48          final int n = 13;
49          final int[] seed = RandomSource.createIntArray(n);
50          Assert.assertEquals(n, seed.length);
51  
52          for (int i = 1; i < n; i++) {
53              // Can fail, but unlikely given the range.
54              Assert.assertNotEquals(seed[i - 1], seed[i]);
55          }
56      }
57  
58      @Test
59      public void testCreateLongArray() {
60          final int n = 9;
61          final long[] seed = RandomSource.createLongArray(n);
62          Assert.assertEquals(n, seed.length);
63  
64          for (int i = 1; i < n; i++) {
65              // Can fail, but unlikely given the range.
66              Assert.assertNotEquals(seed[i - 1], seed[i]);
67          }
68      }
69  
70      @Test
71      public void testIsJumpable() {
72          Assert.assertFalse("JDK is not Jumpable", RandomSource.JDK.isJumpable());
73          Assert.assertTrue("XOR_SHIFT_1024_S_PHI is Jumpable", RandomSource.XOR_SHIFT_1024_S_PHI.isJumpable());
74          Assert.assertTrue("XO_SHI_RO_256_SS is Jumpable", RandomSource.XO_SHI_RO_256_SS.isJumpable());
75      }
76  
77      @Test
78      public void testIsLongJumpable() {
79          Assert.assertFalse("JDK is not LongJumpable", RandomSource.JDK.isLongJumpable());
80          Assert.assertFalse("XOR_SHIFT_1024_S_PHI is not LongJumpable", RandomSource.XOR_SHIFT_1024_S_PHI.isLongJumpable());
81          Assert.assertTrue("XO_SHI_RO_256_SS is LongJumpable", RandomSource.XO_SHI_RO_256_SS.isLongJumpable());
82      }
83  }