Skip to content

Commit

Permalink
add tests for jump() and long_jump() to Xoshiro128PlusPlus and Xoshir…
Browse files Browse the repository at this point in the history
…o128StarStar
  • Loading branch information
walterdejong committed Jul 4, 2022
1 parent 24e2d95 commit 59001df
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
26 changes: 26 additions & 0 deletions rand_xoshiro/src/xoshiro128plusplus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,30 @@ mod tests {
assert_eq!(rng.next_u32(), e);
}
}

#[test]
fn test_jump() {
let mut rng = Xoshiro128PlusPlus::from_seed(
[1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0]);
rng.jump();
// These values were produced by instrumenting the reference implementation:
// http://xoshiro.di.unimi.it/xoshiro128plus.c
assert_eq!(rng.s[0], 2843103750);
assert_eq!(rng.s[1], 2038079848);
assert_eq!(rng.s[2], 1533207345);
assert_eq!(rng.s[3], 44816753);
}

#[test]
fn test_long_jump() {
let mut rng = Xoshiro128PlusPlus::from_seed(
[1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0]);
rng.long_jump();
// These values were produced by instrumenting the reference implementation:
// http://xoshiro.di.unimi.it/xoshiro128plus.c
assert_eq!(rng.s[0], 1611968294);
assert_eq!(rng.s[1], 2125834322);
assert_eq!(rng.s[2], 966769569);
assert_eq!(rng.s[3], 3193880526);
}
}
26 changes: 26 additions & 0 deletions rand_xoshiro/src/xoshiro128starstar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,30 @@ mod tests {
assert_eq!(rng.next_u32(), e);
}
}

#[test]
fn test_jump() {
let mut rng = Xoshiro128StarStar::from_seed(
[1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0]);
rng.jump();
// These values were produced by instrumenting the reference implementation:
// http://xoshiro.di.unimi.it/xoshiro128plus.c
assert_eq!(rng.s[0], 2843103750);
assert_eq!(rng.s[1], 2038079848);
assert_eq!(rng.s[2], 1533207345);
assert_eq!(rng.s[3], 44816753);
}

#[test]
fn test_long_jump() {
let mut rng = Xoshiro128StarStar::from_seed(
[1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0]);
rng.long_jump();
// These values were produced by instrumenting the reference implementation:
// http://xoshiro.di.unimi.it/xoshiro128plus.c
assert_eq!(rng.s[0], 1611968294);
assert_eq!(rng.s[1], 2125834322);
assert_eq!(rng.s[2], 966769569);
assert_eq!(rng.s[3], 3193880526);
}
}

0 comments on commit 59001df

Please sign in to comment.