Skip to content

Commit 59001df

Browse files
committed
add tests for jump() and long_jump() to Xoshiro128PlusPlus and Xoshiro128StarStar
1 parent 24e2d95 commit 59001df

2 files changed

Lines changed: 52 additions & 0 deletions

File tree

rand_xoshiro/src/xoshiro128plusplus.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,30 @@ mod tests {
117117
assert_eq!(rng.next_u32(), e);
118118
}
119119
}
120+
121+
#[test]
122+
fn test_jump() {
123+
let mut rng = Xoshiro128PlusPlus::from_seed(
124+
[1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0]);
125+
rng.jump();
126+
// These values were produced by instrumenting the reference implementation:
127+
// http://xoshiro.di.unimi.it/xoshiro128plus.c
128+
assert_eq!(rng.s[0], 2843103750);
129+
assert_eq!(rng.s[1], 2038079848);
130+
assert_eq!(rng.s[2], 1533207345);
131+
assert_eq!(rng.s[3], 44816753);
132+
}
133+
134+
#[test]
135+
fn test_long_jump() {
136+
let mut rng = Xoshiro128PlusPlus::from_seed(
137+
[1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0]);
138+
rng.long_jump();
139+
// These values were produced by instrumenting the reference implementation:
140+
// http://xoshiro.di.unimi.it/xoshiro128plus.c
141+
assert_eq!(rng.s[0], 1611968294);
142+
assert_eq!(rng.s[1], 2125834322);
143+
assert_eq!(rng.s[2], 966769569);
144+
assert_eq!(rng.s[3], 3193880526);
145+
}
120146
}

rand_xoshiro/src/xoshiro128starstar.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,30 @@ mod tests {
117117
assert_eq!(rng.next_u32(), e);
118118
}
119119
}
120+
121+
#[test]
122+
fn test_jump() {
123+
let mut rng = Xoshiro128StarStar::from_seed(
124+
[1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0]);
125+
rng.jump();
126+
// These values were produced by instrumenting the reference implementation:
127+
// http://xoshiro.di.unimi.it/xoshiro128plus.c
128+
assert_eq!(rng.s[0], 2843103750);
129+
assert_eq!(rng.s[1], 2038079848);
130+
assert_eq!(rng.s[2], 1533207345);
131+
assert_eq!(rng.s[3], 44816753);
132+
}
133+
134+
#[test]
135+
fn test_long_jump() {
136+
let mut rng = Xoshiro128StarStar::from_seed(
137+
[1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0]);
138+
rng.long_jump();
139+
// These values were produced by instrumenting the reference implementation:
140+
// http://xoshiro.di.unimi.it/xoshiro128plus.c
141+
assert_eq!(rng.s[0], 1611968294);
142+
assert_eq!(rng.s[1], 2125834322);
143+
assert_eq!(rng.s[2], 966769569);
144+
assert_eq!(rng.s[3], 3193880526);
145+
}
120146
}

0 commit comments

Comments
 (0)