rusty-diceware

Commandline diceware, with or without dice, written in Rustlang.
git clone https://kaka.farm/~git/rusty-diceware
Log | Files | Refs | README | LICENSE

tests.rs (1592B)


      1 macro_rules! create_test {
      2     ( $wordlist_name: ident, $test_name: ident, $expected: expr ) => {
      3         #[test]
      4         fn $test_name() {
      5             use diceware_wordlists::$wordlist_name;
      6             use rand::prelude::SeedableRng;
      7             use rand::prelude::SliceRandom;
      8             use rand_chacha::ChaCha12Rng;
      9 
     10             fn make_vektor<'a>() -> Vec<&'a str> {
     11                 let seed: [u8; 32] = [0; 32];
     12                 let mut rng: ChaCha12Rng = SeedableRng::from_seed(seed);
     13 
     14                 let mut vector: Vec<&str> = vec![];
     15                 for _ in 0..4 {
     16                     let word: &str = $wordlist_name.choose(&mut rng).unwrap();
     17                     vector.push(word);
     18                 }
     19                 vector
     20             }
     21             let wanted: Vec<&str> = $expected.into_iter().collect();
     22 
     23             let got = make_vektor();
     24 
     25             assert_eq!(got, wanted);
     26         }
     27     };
     28 }
     29 
     30 create_test!(
     31     BEALE_WORDLIST,
     32     beale_rng_test,
     33     vec!["io", "gavel", "beam", "time"]
     34 );
     35 
     36 create_test!(
     37     REINHOLD_WORDLIST,
     38     reinhold_rng_test,
     39     vec!["india", "gamma", "bcd", "theme"]
     40 );
     41 
     42 create_test!(
     43     MINILOCK_WORDLIST,
     44     minilock_rng_test,
     45     vec!["hoed", "femininity", "bedsit", "stabbings"]
     46 );
     47 
     48 create_test!(
     49     EFF_LONG_WORDLIST,
     50     eff_long_rng_test,
     51     vec!["helpless", "fever", "blooming", "sublease"]
     52 );
     53 create_test!(
     54     EFF_SHORT_WORDLIST_1,
     55     eff_short_1_rng_test,
     56     vec!["five", "boat", "shape", "bony"]
     57 );
     58 create_test!(
     59     EFF_SHORT_WORDLIST_2_0,
     60     eff_short_2_0_rng_test,
     61     vec!["family", "aseptic", "renovator", "atlas"]
     62 );