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  
18  package org.apache.commons.rng.core.source32;
19  
20  import org.apache.commons.rng.core.RandomAssert;
21  import org.junit.Test;
22  
23  public class PcgXshRs32Test {
24      @Test
25      public void testReferenceCode() {
26          /*
27           * Tested with respect to pcg_engines::setseq_xsh_rs_64_32 from the C++ implementation.
28           * See : http://www.pcg-random.org/download.html#cpp-implementation
29           */
30          final int[] expectedSequence = {
31              0xba4138b8, 0xd329a393, 0x75d68d3f, 0xbb7572ca,
32              0x7a48d2f2, 0xcb3c1e37, 0xc1374a97, 0x7c2c5bfa,
33              0x8a1c8695, 0x30db4fea, 0x95f9a901, 0x72ebfa48,
34              0x6a284dbf, 0x0ef11286, 0x37330e11, 0xfeb53893,
35              0x77e3adda, 0x64dc86bd, 0xc8d762d7, 0xbf3fb80c,
36              0x732dfd12, 0x6088e86d, 0xbc4e79e5, 0x56ece5b1,
37              0xe706ac72, 0xee798018, 0xef73de74, 0x3de1f966,
38              0x7a36db53, 0x1e921eb2, 0x55e35484, 0x2577c6f2,
39              0x0a006e21, 0x8cb811b7, 0x5f26c916, 0x3990837f,
40              0x15f2983d, 0x546ccb4a, 0x4eda8716, 0xb8666a25,
41          };
42          RandomAssert.assertEquals(expectedSequence, new PcgXshRs32(new long[] {
43              0x012de1babb3c4104L, 0xc8161b4202294965L
44          }));
45      }
46  }