Debian Codegraph @

debian/missing-sources/time/tests/integration/rand.rs

raw
1 use rand08::Rng as _;
2 use rand09::Rng as _;
3 use time::{Date, Duration, Month, OffsetDateTime, PrimitiveDateTime, Time, UtcOffset, Weekday};
4
5 #[test]
6 fn support08() {
7 // Work around rust-random/rand#1020.
8 let mut rng = rand08::rngs::mock::StepRng::new(0, 656_175_560);
9
10 for _ in 0..7 {
11 let _ = rng.r#gen::<Weekday>();
12 }
13 for _ in 0..12 {
14 let _ = rng.r#gen::<Month>();
15 }
16 let _ = rng.r#gen::<Time>();
17 let _ = rng.r#gen::<Date>();
18 let _ = rng.r#gen::<UtcOffset>();
19 let _ = rng.r#gen::<PrimitiveDateTime>();
20 let _ = rng.r#gen::<OffsetDateTime>();
21 let _ = rng.r#gen::<Duration>();
22 }
23
24 #[test]
25 fn support09() {
26 // Work around rust-random/rand#1020.
27 let mut rng = StepRng::new(0, 656_175_560);
28
29 for _ in 0..7 {
30 let _ = rng.random::<Weekday>();
31 }
32 for _ in 0..12 {
33 let _ = rng.random::<Month>();
34 }
35 let _ = rng.random::<Time>();
36 let _ = rng.random::<Date>();
37 let _ = rng.random::<UtcOffset>();
38 let _ = rng.random::<PrimitiveDateTime>();
39 let _ = rng.random::<OffsetDateTime>();
40 let _ = rng.random::<Duration>();
41 }
42
43 // copy of `StepRng` from rand 0.8 to avoid deprecation warnings
44 #[derive(Debug, Clone)]
45 struct StepRng {
46 v: u64,
47 a: u64,
48 }
49
50 impl StepRng {
51 fn new(initial: u64, increment: u64) -> Self {
52 Self {
53 v: initial,
54 a: increment,
55 }
56 }
57 }
58
59 impl rand09::RngCore for StepRng {
60 fn next_u32(&mut self) -> u32 {
61 self.next_u64() as u32
62 }
63
64 fn next_u64(&mut self) -> u64 {
65 let res = self.v;
66 self.v = self.v.wrapping_add(self.a);
67 res
68 }
69
70 fn fill_bytes(&mut self, dst: &mut [u8]) {
71 rand09::rand_core::impls::fill_bytes_via_next(self, dst)
72 }
73 }