aboutsummaryrefslogtreecommitdiff
path: root/rand/rand_pcg/tests
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2020-01-02 08:32:06 -0800
committerDaniel Mueller <deso@posteo.net>2020-01-02 08:32:06 -0800
commitfd091b04316db9dc5fafadbd6bdbe60b127408a9 (patch)
treef202270f7ae5cedc513be03833a26148d9b5e219 /rand/rand_pcg/tests
parent8161cdb26f98e65b39c603ddf7a614cc87c77a1c (diff)
downloadnitrocli-fd091b04316db9dc5fafadbd6bdbe60b127408a9.tar.gz
nitrocli-fd091b04316db9dc5fafadbd6bdbe60b127408a9.tar.bz2
Update nitrokey crate to 0.4.0
This change finally updates the version of the nitrokey crate that we consume to 0.4.0. Along with that we update rand_core, one of its dependencies, to 0.5.1. Further more we add cfg-if in version 0.1.10 and getrandom in version 0.1.13, both of which are now new (non-development) dependencies. Import subrepo nitrokey/:nitrokey at e81057037e9b4f370b64c0a030a725bc6bdfb870 Import subrepo cfg-if/:cfg-if at 4484a6faf816ff8058088ad857b0c6bb2f4b02b2 Import subrepo getrandom/:getrandom at d661aa7e1b8cc80b47dabe3d2135b3b47d2858af Import subrepo rand/:rand at d877ed528248b52d947e0484364a4e1ae59ca502
Diffstat (limited to 'rand/rand_pcg/tests')
-rw-r--r--rand/rand_pcg/tests/lcg128xsl64.rs55
-rw-r--r--rand/rand_pcg/tests/lcg64xsh32.rs4
-rw-r--r--rand/rand_pcg/tests/mcg128xsl64.rs5
3 files changed, 55 insertions, 9 deletions
diff --git a/rand/rand_pcg/tests/lcg128xsl64.rs b/rand/rand_pcg/tests/lcg128xsl64.rs
new file mode 100644
index 0000000..efc72ff
--- /dev/null
+++ b/rand/rand_pcg/tests/lcg128xsl64.rs
@@ -0,0 +1,55 @@
+use rand_core::{RngCore, SeedableRng};
+use rand_pcg::{Lcg128Xsl64, Pcg64};
+
+#[test]
+fn test_lcg128xsl64_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,
+ 17,18,19,20, 21,22,23,24, 25,26,27,28, 29,30,31,32];
+ let mut rng1 = Lcg128Xsl64::from_seed(seed);
+ assert_eq!(rng1.next_u64(), 8740028313290271629);
+
+ let mut rng2 = Lcg128Xsl64::from_rng(&mut rng1).unwrap();
+ assert_eq!(rng2.next_u64(), 1922280315005786345);
+
+ let mut rng3 = Lcg128Xsl64::seed_from_u64(0);
+ assert_eq!(rng3.next_u64(), 2354861276966075475);
+
+ // This is the same as Lcg128Xsl64, so we only have a single test:
+ let mut rng4 = Pcg64::seed_from_u64(0);
+ assert_eq!(rng4.next_u64(), 2354861276966075475);
+}
+
+#[test]
+fn test_lcg128xsl64_true_values() {
+ // Numbers copied from official test suite (C version).
+ let mut rng = Lcg128Xsl64::new(42, 54);
+
+ let mut results = [0u64; 6];
+ for i in results.iter_mut() { *i = rng.next_u64(); }
+ let expected: [u64; 6] = [0x86b1da1d72062b68, 0x1304aa46c9853d39,
+ 0xa3670e9e0dd50358, 0xf9090e529a7dae00, 0xc85b9fd837996f2c, 0x606121f8e3919196];
+ assert_eq!(results, expected);
+}
+
+#[cfg(feature="serde1")]
+#[test]
+fn test_lcg128xsl64_serde() {
+ use bincode;
+ use std::io::{BufWriter, BufReader};
+
+ let mut rng = Lcg128Xsl64::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: Lcg128Xsl64 = bincode::deserialize_from(&mut read)
+ .expect("Could not deserialize");
+
+ for _ in 0..16 {
+ assert_eq!(rng.next_u64(), deserialized.next_u64());
+ }
+}
diff --git a/rand/rand_pcg/tests/lcg64xsh32.rs b/rand/rand_pcg/tests/lcg64xsh32.rs
index 775b12c..e05bcc1 100644
--- a/rand/rand_pcg/tests/lcg64xsh32.rs
+++ b/rand/rand_pcg/tests/lcg64xsh32.rs
@@ -1,7 +1,3 @@
-extern crate rand_pcg;
-extern crate rand_core;
-#[cfg(all(feature="serde1", test))] extern crate bincode;
-
use rand_core::{RngCore, SeedableRng};
use rand_pcg::{Lcg64Xsh32, Pcg32};
diff --git a/rand/rand_pcg/tests/mcg128xsl64.rs b/rand/rand_pcg/tests/mcg128xsl64.rs
index 3279536..d58fa75 100644
--- a/rand/rand_pcg/tests/mcg128xsl64.rs
+++ b/rand/rand_pcg/tests/mcg128xsl64.rs
@@ -1,8 +1,3 @@
-#![cfg(rustc_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};