rusty-diceware

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit fa2f62411abe9d45c70cd62ff97eca94edb6e676
parent a492e5e63d172c464f2957a9e32751ffc82f33b2
Author: Yuval Langer <yuvallangerontheroad@gmail.com>
Date:   Thu, 20 Oct 2022 21:32:50 +0300

Move tests into their own tests directories.

Diffstat:
MCHANGELOG.md | 9+++++++++
MCargo.lock | 5+++--
MCargo.toml | 3++-
Mdiceware_wordlists/CHANGELOG.md | 4++++
Mdiceware_wordlists/Cargo.toml | 2+-
Mdiceware_wordlists/src/lib.rs | 198-------------------------------------------------------------------------------
Adiceware_wordlists/tests/tests.rs | 197+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/main.rs | 62--------------------------------------------------------------
Atests/tests.rs | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9 files changed, 280 insertions(+), 264 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -1,3 +1,12 @@ +# v0.5.8 + +* Move tests into tests directory. +* Use a reproducible `rand_chacha::ChaCha12Rng` instead of an `rand::prelude::StdRng`. In the current `rand` version, `0.8.5`, `StdRng` is `ChaCha12Rng`, but it may change in the future, as written in <https://docs.rs/rand/0.8.5/rand/rngs/struct.StdRng.html>. + +# v0.5.7 + +Bumping `diceware_wordlists` version in the dependencies. + ## v0.5.4 to v0.5.6 * Move wordlists to their own permissively licensed `diceware_wordlists` crate. diff --git a/Cargo.lock b/Cargo.lock @@ -10,16 +10,17 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "diceware" -version = "0.5.7" +version = "0.5.8" dependencies = [ "diceware_wordlists", "getopts", "rand", + "rand_chacha", ] [[package]] name = "diceware_wordlists" -version = "1.1.0" +version = "1.1.1" dependencies = [ "serde", ] diff --git a/Cargo.toml b/Cargo.toml @@ -4,7 +4,7 @@ members = ["diceware_wordlists"] [package] name = "diceware" -version = "0.5.7" +version = "0.5.8" authors = ["Yuval Langer <yuvallangerontheroad@gmail.com>"] license = "AGPL-3.0" repository = "https://gitlab.com/yuvallanger/rusty-diceware" @@ -17,4 +17,5 @@ edition = "2021" [dependencies] getopts = "^0.2" rand = "^0.8" +rand_chacha = "^0.3" diceware_wordlists = { path = "diceware_wordlists", version = "^1" } diff --git a/diceware_wordlists/CHANGELOG.md b/diceware_wordlists/CHANGELOG.md @@ -1,3 +1,7 @@ +## v1.1.1 + +Moving tests into tests directory. Sorry for the spam. + ## v1.1.0 Add tests. diff --git a/diceware_wordlists/Cargo.toml b/diceware_wordlists/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "diceware_wordlists" -version = "1.1.0" +version = "1.1.1" authors = ["Yuval Langer <yuvallangerontheroad@gmail.com>"] license = "MIT OR Apache-2.0" repository = "https://gitlab.com/yuvallanger/rusty-diceware" diff --git a/diceware_wordlists/src/lib.rs b/diceware_wordlists/src/lib.rs @@ -47,201 +47,3 @@ impl Default for Wordlist { Self::EffLong } } - -macro_rules! create_test { - ( - $wordlist_name: ident, - $test_name: ident, - $expected_indices: expr, - $expected_values: expr, - ) => { - #[test] - fn $test_name() { - use crate::$wordlist_name; - - let wanted: Vec<&str> = $expected_values.into_iter().collect(); - - let got: Vec<&str> = $expected_indices - .into_iter() - .map(|i| $wordlist_name[i]) - .collect(); - - assert_eq!(got, wanted); - } - }; -} - -create_test!( - BEALE_WORDLIST, - beale_test, - vec![ - 0, - BEALE_WORDLIST.len() - 1, - 490, - 811, - 970, - 1187, - 1726, - 2158, - 2492, - 3005, - 3713, - 4143, - 4289, - ], - vec![ - "a", "@", "balls", "boor", "bunts", "cherub", "dime", "ezra", "fuzzy", "hire", "leeway", - "mills", "ms", - ], -); - -create_test!( - REINHOLD_WORDLIST, - reinhold_test, - vec![ - 0, - REINHOLD_WORDLIST.len() - 1, - 490, - 811, - 970, - 1187, - 1726, - 2158, - 2492, - 3005, - 3713, - 4143, - 4289, - ], - vec![ - "a", "@", "balk", "bony", "bum", "charm", "dice", "excess", "fuchs", "hg", "le", "mercy", - "morsel", - ], -); - -create_test!( - MINILOCK_WORDLIST, - minilock_test, - vec![ - 0, - MINILOCK_WORDLIST.len() - 1, - 7625, - 9287, - 18137, - 26351, - 27726, - 32096, - 37667, - 38151, - 46685, - 47351, - 52997, - ], - vec![ - "aardvark", - "zulus", - "censer", - "colonels", - "exonerate", - "infringe", - "jaunts", - "miserliness", - "platitudes", - "pontoon", - "skua", - "snuggles", - "tributes", - ], -); - -create_test!( - EFF_LONG_WORDLIST, - eff_long_test, - vec![ - 0, - EFF_LONG_WORDLIST.len() - 1, - 490, - 811, - 970, - 1187, - 1726, - 2158, - 2492, - 3005, - 3713, - 4143, - 4289, - ], - vec![ - "abacus", - "zoom", - "barbecue", - "candle", - "charbroil", - "commodity", - "deserving", - "eleven", - "fame", - "grew", - "limpness", - "nifty", - "outer", - ], -); -create_test!( - EFF_SHORT_WORDLIST_1, - eff_short_1_test, - vec![ - 0, - EFF_SHORT_WORDLIST_1.len() - 1, - 201, - 250, - 371, - 400, - 565, - 606, - 826, - 890, - 909, - 922, - 966, - ], - vec![ - "acid", "zoom", "clerk", "crook", "elbow", "faced", "hut", "kilt", "putt", "rover", - "sandy", "scary", "shove", - ], -); -create_test!( - EFF_SHORT_WORDLIST_2_0, - eff_short_2_0_test, - vec![ - 0, - EFF_SHORT_WORDLIST_2_0.len() - 1, - 201, - 250, - 371, - 400, - 565, - 606, - 826, - 890, - 909, - 922, - 966, - ], - vec![ - "aardvark", - "zucchini", - "circle", - "cytoplasm", - "enforcer", - "etiquette", - "hybrid", - "jamboree", - "omnivorous", - "plywood", - "pry", - "puzzle", - "riches", - ], -); diff --git a/diceware_wordlists/tests/tests.rs b/diceware_wordlists/tests/tests.rs @@ -0,0 +1,197 @@ +macro_rules! create_test { + ( + $wordlist_name: ident, + $test_name: ident, + $expected_indices: expr, + $expected_values: expr, + ) => { + #[test] + fn $test_name() { + use diceware_wordlists::$wordlist_name; + + let wanted: Vec<&str> = $expected_values.into_iter().collect(); + + let got: Vec<&str> = $expected_indices + .into_iter() + .map(|i| $wordlist_name[i]) + .collect(); + + assert_eq!(got, wanted); + } + }; +} + +create_test!( + BEALE_WORDLIST, + beale_test, + vec![ + 0, + BEALE_WORDLIST.len() - 1, + 490, + 811, + 970, + 1187, + 1726, + 2158, + 2492, + 3005, + 3713, + 4143, + 4289, + ], + vec![ + "a", "@", "balls", "boor", "bunts", "cherub", "dime", "ezra", "fuzzy", "hire", "leeway", + "mills", "ms", + ], +); + +create_test!( + REINHOLD_WORDLIST, + reinhold_test, + vec![ + 0, + REINHOLD_WORDLIST.len() - 1, + 490, + 811, + 970, + 1187, + 1726, + 2158, + 2492, + 3005, + 3713, + 4143, + 4289, + ], + vec![ + "a", "@", "balk", "bony", "bum", "charm", "dice", "excess", "fuchs", "hg", "le", "mercy", + "morsel", + ], +); + +create_test!( + MINILOCK_WORDLIST, + minilock_test, + vec![ + 0, + MINILOCK_WORDLIST.len() - 1, + 7625, + 9287, + 18137, + 26351, + 27726, + 32096, + 37667, + 38151, + 46685, + 47351, + 52997, + ], + vec![ + "aardvark", + "zulus", + "censer", + "colonels", + "exonerate", + "infringe", + "jaunts", + "miserliness", + "platitudes", + "pontoon", + "skua", + "snuggles", + "tributes", + ], +); + +create_test!( + EFF_LONG_WORDLIST, + eff_long_test, + vec![ + 0, + EFF_LONG_WORDLIST.len() - 1, + 490, + 811, + 970, + 1187, + 1726, + 2158, + 2492, + 3005, + 3713, + 4143, + 4289, + ], + vec![ + "abacus", + "zoom", + "barbecue", + "candle", + "charbroil", + "commodity", + "deserving", + "eleven", + "fame", + "grew", + "limpness", + "nifty", + "outer", + ], +); +create_test!( + EFF_SHORT_WORDLIST_1, + eff_short_1_test, + vec![ + 0, + EFF_SHORT_WORDLIST_1.len() - 1, + 201, + 250, + 371, + 400, + 565, + 606, + 826, + 890, + 909, + 922, + 966, + ], + vec![ + "acid", "zoom", "clerk", "crook", "elbow", "faced", "hut", "kilt", "putt", "rover", + "sandy", "scary", "shove", + ], +); +create_test!( + EFF_SHORT_WORDLIST_2_0, + eff_short_2_0_test, + vec![ + 0, + EFF_SHORT_WORDLIST_2_0.len() - 1, + 201, + 250, + 371, + 400, + 565, + 606, + 826, + 890, + 909, + 922, + 966, + ], + vec![ + "aardvark", + "zucchini", + "circle", + "cytoplasm", + "enforcer", + "etiquette", + "hybrid", + "jamboree", + "omnivorous", + "plywood", + "pry", + "puzzle", + "riches", + ], +); diff --git a/src/main.rs b/src/main.rs @@ -292,65 +292,3 @@ fn main() { }; }; } - -macro_rules! create_test { - ( $wordlist_name: ident, $test_name: ident, $expected: expr ) => { - #[test] - fn $test_name() { - use diceware_wordlists::$wordlist_name; - use rand::prelude::SeedableRng; - use rand::prelude::StdRng; - - fn make_vektor<'a>() -> Vec<&'a str> { - let seed: [u8; 32] = [0; 32]; - let mut rng: StdRng = SeedableRng::from_seed(seed); - - let mut vector: Vec<&str> = vec![]; - for _ in 0..4 { - let word: &str = $wordlist_name.choose(&mut rng).unwrap(); - vector.push(word); - } - vector - } - let wanted: Vec<&str> = $expected.into_iter().collect(); - - let got = make_vektor(); - - assert_eq!(got, wanted); - } - }; -} - -create_test!( - BEALE_WORDLIST, - beale_rng_test, - vec!["io", "gavel", "beam", "time"] -); - -create_test!( - REINHOLD_WORDLIST, - reinhold_rng_test, - vec!["india", "gamma", "bcd", "theme"] -); - -create_test!( - MINILOCK_WORDLIST, - minilock_rng_test, - vec!["hoed", "femininity", "bedsit", "stabbings"] -); - -create_test!( - EFF_LONG_WORDLIST, - eff_long_rng_test, - vec!["helpless", "fever", "blooming", "sublease"] -); -create_test!( - EFF_SHORT_WORDLIST_1, - eff_short_1_rng_test, - vec!["five", "boat", "shape", "bony"] -); -create_test!( - EFF_SHORT_WORDLIST_2_0, - eff_short_2_0_rng_test, - vec!["family", "aseptic", "renovator", "atlas"] -); diff --git a/tests/tests.rs b/tests/tests.rs @@ -0,0 +1,64 @@ +use rand_chacha; + +macro_rules! create_test { + ( $wordlist_name: ident, $test_name: ident, $expected: expr ) => { + #[test] + fn $test_name() { + use diceware_wordlists::$wordlist_name; + use rand::prelude::SeedableRng; + use rand::prelude::SliceRandom; + use rand_chacha::ChaCha12Rng; + + fn make_vektor<'a>() -> Vec<&'a str> { + let seed: [u8; 32] = [0; 32]; + let mut rng: ChaCha12Rng = SeedableRng::from_seed(seed); + + let mut vector: Vec<&str> = vec![]; + for _ in 0..4 { + let word: &str = $wordlist_name.choose(&mut rng).unwrap(); + vector.push(word); + } + vector + } + let wanted: Vec<&str> = $expected.into_iter().collect(); + + let got = make_vektor(); + + assert_eq!(got, wanted); + } + }; +} + +create_test!( + BEALE_WORDLIST, + beale_rng_test, + vec!["io", "gavel", "beam", "time"] +); + +create_test!( + REINHOLD_WORDLIST, + reinhold_rng_test, + vec!["india", "gamma", "bcd", "theme"] +); + +create_test!( + MINILOCK_WORDLIST, + minilock_rng_test, + vec!["hoed", "femininity", "bedsit", "stabbings"] +); + +create_test!( + EFF_LONG_WORDLIST, + eff_long_rng_test, + vec!["helpless", "fever", "blooming", "sublease"] +); +create_test!( + EFF_SHORT_WORDLIST_1, + eff_short_1_rng_test, + vec!["five", "boat", "shape", "bony"] +); +create_test!( + EFF_SHORT_WORDLIST_2_0, + eff_short_2_0_rng_test, + vec!["family", "aseptic", "renovator", "atlas"] +);