Skip to content

Commit

Permalink
Rng.clone() should not change internal state - issue smol-rs#36
Browse files Browse the repository at this point in the history
  • Loading branch information
ra1u committed Sep 17, 2022
1 parent 6fe2c33 commit bbc727e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,21 @@ impl Clone for Rng {
/// assert_eq!(rng1.u64(..), rng2.u64(..), "the cloned generators are identical");
/// ```
fn clone(&self) -> Rng {
Rng::with_seed(self.gen_u64())
Rng::with_seed(self.get_seed())
}
}

#[cfg(test)]
mod tests {
#[test]
fn test_clone() {
let seed = 0x4d595df4d0f33173;
let rng1 = crate::Rng::with_seed(seed);
let rng2 = rng1.clone();
// clone should keep internal state same
assert_eq!(rng1.get_seed(), seed);
assert_eq!(rng2.get_seed(), seed);
assert_eq!(rng1.u64(..), rng2.u64(..));
}
}

Expand Down

0 comments on commit bbc727e

Please sign in to comment.