use ciphers::{Cipher, CipherInputError, Substitution};
#[test]
fn encipher_small() {
let substitution = Substitution::new("PHQGIUMEAYLNOFDXJKRCVSTZWB");
let ctext = substitution.encipher("DEFENDTHEEASTWALLOFTHECASTLE");
assert_eq!(ctext.unwrap(), "GIUIFGCEIIPRCTPNNDUCEIQPRCNI");
}
#[test]
fn decipher_small() {
let substitution = Substitution::new("PHQGIUMEAYLNOFDXJKRCVSTZWB");
let ptext = substitution.decipher("GIUIFGCEIIPRCTPNNDUCEIQPRCNI");
assert_eq!(ptext.unwrap(), "DEFENDTHEEASTWALLOFTHECASTLE");
}
#[test]
fn encipher_large() {
let substitution = Substitution::new("PHQGIUMEAYLNOFDXJKRCVSTZWB");
let ctext = substitution.encipher("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ");
assert_eq!(
ctext.unwrap(),
"PHQGIUMEAYLNOFDXJKRCVSTZWBPHQGIUMEAYLNOFDXJKRCVSTZWB"
);
}
#[test]
fn decipher_large() {
let substitution = Substitution::new("PHQGIUMEAYLNOFDXJKRCVSTZWB");
let ptext = substitution.decipher("PHQGIUMEAYLNOFDXJKRCVSTZWBPHQGIUMEAYLNOFDXJKRCVSTZWB");
assert_eq!(
ptext.unwrap(),
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
);
}
#[test]
fn encipher_lowercase() {
let substitution = Substitution::new("phqgiumeaylnofdxjkrcvstzwb");
let ctext = substitution.encipher("defendtheeastwallofthecastle");
assert_eq!(ctext.unwrap(), "GIUIFGCEIIPRCTPNNDUCEIQPRCNI");
}
#[test]
fn decipher_lowercase() {
let substitution = Substitution::new("phqgiumeaylnofdxjkrcvstzwb");
let ptext = substitution.decipher("giuifgceiiprctpnnduceiqprcni");
assert_eq!(ptext.unwrap(), "DEFENDTHEEASTWALLOFTHECASTLE");
}
#[test]
#[should_panic]
fn key_not_26_chars() {
Substitution::new("phqgiumeaylnofdxjkrcvstzw");
}
#[test]
#[should_panic]
fn key_non_alpha() {
Substitution::new("phqg1umeaylnofdxjkrcvstzwb");
}
#[test]
#[should_panic]
fn key_repeated_chars() {
Substitution::new("phqgiumeaylnofdxikrcvstzwb");
}
#[test]
fn ptext_non_alpha() {
let substitution = Substitution::new("phqgiumeaylnofdxjkrcvstzwb");
let ctext = substitution.encipher("defendth33astwallofthec4stle");
assert_eq!(ctext, Err(CipherInputError::NotAlphabetic));
}
#[test]
fn ctext_non_alpha() {
let substitution = Substitution::new("phqgiumeaylnofdxjkrcvstzwb");
let ptext = substitution.decipher("giuifgce11prctpnnduceiqprcni");
assert_eq!(ptext, Err(CipherInputError::NotAlphabetic));
}