From 69141aaa0d43379a8f06ad7216f671584ce74249 Mon Sep 17 00:00:00 2001 From: Narthana Epa Date: Fri, 27 Sep 2024 17:44:45 +1000 Subject: [PATCH] Use pretty-assertions crate in tests --- Cargo.lock | 23 +++++++++++++++++++++++ Cargo.toml | 1 + src/passphrase.rs | 7 +++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ae3688f..8ad3b59 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -157,6 +157,12 @@ version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" +[[package]] +name = "diff" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" + [[package]] name = "either" version = "1.9.0" @@ -320,6 +326,16 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" +[[package]] +name = "pretty_assertions" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ae130e2f271fbc2ac3a40fb1d07180839cdbbe443c7a27e1e3c13c5cac0116d" +dependencies = [ + "diff", + "yansi", +] + [[package]] name = "proc-macro2" version = "1.0.78" @@ -440,6 +456,7 @@ dependencies = [ "clap", "eyre", "itertools", + "pretty_assertions", "rand", "rand_chacha", "rayon", @@ -608,3 +625,9 @@ name = "windows_x86_64_msvc" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + +[[package]] +name = "yansi" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" diff --git a/Cargo.toml b/Cargo.toml index 5fbeb41..6725184 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ rand = "0.8.5" regex = "1.10.6" [dev-dependencies] +pretty_assertions = "1.4.1" rand_chacha = "0.3.1" rayon = "1.10.0" statrs = "0.17.1" diff --git a/src/passphrase.rs b/src/passphrase.rs index 91b87d7..2beeb5e 100644 --- a/src/passphrase.rs +++ b/src/passphrase.rs @@ -26,12 +26,15 @@ pub fn new( .join(separator)) } +#[cfg(test)] mod test { - #[test] + use crate::{passphrase, words}; + use pretty_assertions::assert_eq; + // Uses [Pearson's chi-squared test](https://en.wikipedia.org/wiki/Chi-squared_test#Pearson's_chi-squared_test) // to test that the passphrases are uniformly distributed. + #[test] fn chi_squared() { - use crate::{passphrase, words}; use itertools::Itertools; use rand_chacha::{rand_core::SeedableRng, ChaCha8Rng}; use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator};