aboutsummaryrefslogtreecommitdiff
path: root/rand/rand_pcg/tests/mcg128xsl64.rs
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2019-01-02 21:14:10 -0800
committerDaniel Mueller <deso@posteo.net>2019-01-02 21:14:10 -0800
commitecf3474223ca3d16a10f12dc2272e3b0ed72c1bb (patch)
tree03134a683791176b49ef5c92e8d6acd24c3b5a9b /rand/rand_pcg/tests/mcg128xsl64.rs
parent686f61b75055ecb02baf9d9449525ae447a3bed1 (diff)
downloadnitrocli-ecf3474223ca3d16a10f12dc2272e3b0ed72c1bb.tar.gz
nitrocli-ecf3474223ca3d16a10f12dc2272e3b0ed72c1bb.tar.bz2
Update nitrokey crate to 0.2.3
This change updates the nitrokey crate to version 0.2.3. This version bumps the rand crate used to 0.6.1, which in turn requires an additional set of dependencies. Import subrepo nitrokey/:nitrokey at b3e2adc5bb1300441ca74cc7672617c042f3ea31 Import subrepo rand/:rand at 73613ff903512e9503e41cc8ba9eae76269dc598 Import subrepo rustc_version/:rustc_version at 0294f2ba2018bf7be672abd53db351ce5055fa02 Import subrepo semver-parser/:semver-parser at 750da9b11a04125231b1fb293866ca036845acee Import subrepo semver/:semver at 5eb6db94fa03f4d5c64a625a56188f496be47598
Diffstat (limited to 'rand/rand_pcg/tests/mcg128xsl64.rs')
-rw-r--r--rand/rand_pcg/tests/mcg128xsl64.rs59
1 files changed, 59 insertions, 0 deletions
diff --git a/rand/rand_pcg/tests/mcg128xsl64.rs b/rand/rand_pcg/tests/mcg128xsl64.rs
new file mode 100644
index 0000000..2508917
--- /dev/null
+++ b/rand/rand_pcg/tests/mcg128xsl64.rs
@@ -0,0 +1,59 @@
+#![cfg(rust_1_26)]
+extern crate rand_pcg;
+extern crate rand_core;
+#[cfg(all(feature="serde1", test))] extern crate bincode;
+
+use rand_core::{RngCore, SeedableRng};
+use rand_pcg::{Mcg128Xsl64, Pcg64Mcg};
+
+#[test]
+fn test_mcg128xsl64_construction() {
+ // Test that various construction techniques produce a working RNG.
+ let seed = [1,2,3,4, 5,6,7,8, 9,10,11,12, 13,14,15,16];
+ let mut rng1 = Mcg128Xsl64::from_seed(seed);
+ assert_eq!(rng1.next_u64(), 7071994460355047496);
+
+ let mut rng2 = Mcg128Xsl64::from_rng(&mut rng1).unwrap();
+ assert_eq!(rng2.next_u64(), 12300796107712034932);
+
+ let mut rng3 = Mcg128Xsl64::seed_from_u64(0);
+ assert_eq!(rng3.next_u64(), 6198063878555692194);
+
+ // This is the same as Mcg128Xsl64, so we only have a single test:
+ let mut rng4 = Pcg64Mcg::seed_from_u64(0);
+ assert_eq!(rng4.next_u64(), 6198063878555692194);
+}
+
+#[test]
+fn test_mcg128xsl64_true_values() {
+ // Numbers copied from official test suite (C version).
+ let mut rng = Mcg128Xsl64::new(42);
+
+ let mut results = [0u64; 6];
+ for i in results.iter_mut() { *i = rng.next_u64(); }
+ let expected: [u64; 6] = [0x63b4a3a813ce700a, 0x382954200617ab24,
+ 0xa7fd85ae3fe950ce, 0xd715286aa2887737, 0x60c92fee2e59f32c, 0x84c4e96beff30017];
+ assert_eq!(results, expected);
+}
+
+#[cfg(feature="serde1")]
+#[test]
+fn test_mcg128xsl64_serde() {
+ use bincode;
+ use std::io::{BufWriter, BufReader};
+
+ let mut rng = Mcg128Xsl64::seed_from_u64(0);
+
+ let buf: Vec<u8> = Vec::new();
+ let mut buf = BufWriter::new(buf);
+ bincode::serialize_into(&mut buf, &rng).expect("Could not serialize");
+
+ let buf = buf.into_inner().unwrap();
+ let mut read = BufReader::new(&buf[..]);
+ let mut deserialized: Mcg128Xsl64 = bincode::deserialize_from(&mut read)
+ .expect("Could not deserialize");
+
+ for _ in 0..16 {
+ assert_eq!(rng.next_u64(), deserialized.next_u64());
+ }
+}