diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2025-03-08 01:27:20 -0500 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-08 01:27:20 -0500 | 
| commit | 720eacf08693418940e857379e1593b6891a09c3 (patch) | |
| tree | 39100b87651a41ed803158284aa72f9f7d2a0c68 /library/alloctests/testing/rng.rs | |
| parent | 20f0108ada90e37c2350ad68fdc6afe56f51539d (diff) | |
| parent | 22d0440993d6eab6e9faf35f729e2d52ba6d72a6 (diff) | |
| download | rust-720eacf08693418940e857379e1593b6891a09c3.tar.gz rust-720eacf08693418940e857379e1593b6891a09c3.zip  | |
Rollup merge of #136642 - bjorn3:separate_alloctest_crate, r=cuviper
Put the alloc unit tests in a separate alloctests package Same rationale as https://github.com/rust-lang/rust/pull/135937. This PR has some extra complexity though as a decent amount of tests are testing internal implementation details rather than the public api. As such I opted to include the modules containing the types under test using `#[path]` into the alloctests package. This means that those modules still need `#[cfg(test)]`, but the rest of liballoc no longer need it.
Diffstat (limited to 'library/alloctests/testing/rng.rs')
| -rw-r--r-- | library/alloctests/testing/rng.rs | 28 | 
1 files changed, 28 insertions, 0 deletions
diff --git a/library/alloctests/testing/rng.rs b/library/alloctests/testing/rng.rs new file mode 100644 index 00000000000..77d3348f38a --- /dev/null +++ b/library/alloctests/testing/rng.rs @@ -0,0 +1,28 @@ +/// XorShiftRng +pub(crate) struct DeterministicRng { + count: usize, + x: u32, + y: u32, + z: u32, + w: u32, +} + +impl DeterministicRng { + pub(crate) fn new() -> Self { + DeterministicRng { count: 0, x: 0x193a6754, y: 0xa8a7d469, z: 0x97830e05, w: 0x113ba7bb } + } + + /// Guarantees that each returned number is unique. + pub(crate) fn next(&mut self) -> u32 { + self.count += 1; + assert!(self.count <= 70029); + let x = self.x; + let t = x ^ (x << 11); + self.x = self.y; + self.y = self.z; + self.z = self.w; + let w_ = self.w; + self.w = w_ ^ (w_ >> 19) ^ (t ^ (t >> 8)); + self.w + } +}  | 
