use ciphers::{Beaufort, Cipher, CipherInputError};
#[test]
fn encipher_small() {
let beaufort = Beaufort::new("FORTIFICATION");
let ctext = beaufort.encipher("DEFENDTHEEASTWALLOFTHECASTLE");
assert_eq!(ctext.unwrap(), "CKMPVCPVWPIWUJOGIUAPVWRIWUUK");
}
#[test]
fn decipher_small() {
let beaufort = Beaufort::new("FORTIFICATION");
let ptext = beaufort.decipher("CKMPVCPVWPIWUJOGIUAPVWRIWUUK");
assert_eq!(ptext.unwrap(), "DEFENDTHEEASTWALLOFTHECASTLE");
}
#[test]
fn encipher_large() {
let beaufort = Beaufort::new("ZYXWVUTSRQPON");
let ctext = beaufort.encipher("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ");
assert_eq!(
ctext.unwrap(),
"ZXVTRPNLJHFDBMKIGECAYWUSQOZXVTRPNLJHFDBMKIGECAYWUSQO"
);
}
#[test]
fn decipher_large() {
let beaufort = Beaufort::new("ZYXWVUTSRQPON");
let ptext = beaufort.decipher("ZXVTRPNLJHFDBMKIGECAYWUSQOZXVTRPNLJHFDBMKIGECAYWUSQO");
assert_eq!(
ptext.unwrap(),
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
);
}
#[test]
fn encipher_lowercase() {
let beaufort = Beaufort::new("fortification");
let ctext = beaufort.encipher("defendtheeastwallofthecastle");
assert_eq!(ctext.unwrap(), "CKMPVCPVWPIWUJOGIUAPVWRIWUUK");
}
#[test]
fn decipher_lowercase() {
let beaufort = Beaufort::new("fortification");
let ptext = beaufort.decipher("ckmpvcpvwpiwujogiuapvwriwuuk");
assert_eq!(ptext.unwrap(), "DEFENDTHEEASTWALLOFTHECASTLE");
}
#[test]
#[should_panic]
fn key_non_alpha() {
Beaufort::new("f0rtification");
}
#[test]
fn ptext_non_alpha() {
let beaufort = Beaufort::new("fortification");
let ctext = beaufort.encipher("d3f3ndtheeastwallofthecastle");
assert_eq!(ctext, Err(CipherInputError::NotAlphabetic));
}