use ciphers::{Affine, Cipher, CipherInputError};
#[test]
fn encipher_small() {
let affine = Affine::new(7, 11);
let ctext = affine.encipher("DEFENDTHEEASTWALLOFTHECASTLE");
assert_eq!(ctext.unwrap(), "GNUNYGOINNLHOJLKKFUOINZLHOKN");
}
#[test]
fn decipher_small() {
let affine = Affine::new(7, 11);
let ptext = affine.decipher("GNUNYGOINNLHOJLKKFUOINZLHOKN");
assert_eq!(ptext.unwrap(), "DEFENDTHEEASTWALLOFTHECASTLE");
}
#[test]
fn encipher_large() {
let affine = Affine::new(3, 13);
let ctext = affine.encipher("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ");
assert_eq!(
ctext.unwrap(),
"NQTWZCFILORUXADGJMPSVYBEHKNQTWZCFILORUXADGJMPSVYBEHK"
);
}
#[test]
fn decipher_large() {
let affine = Affine::new(3, 13);
let ptext = affine.decipher("NQTWZCFILORUXADGJMPSVYBEHKNQTWZCFILORUXADGJMPSVYBEHK");
assert_eq!(
ptext.unwrap(),
"ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
);
}
#[test]
fn encipher_lowercase() {
let affine = Affine::new(7, 11);
let ctext = affine.encipher("defendtheeastwallofthecastle");
assert_eq!(ctext.unwrap(), "GNUNYGOINNLHOJLKKFUOINZLHOKN");
}
#[test]
fn decipher_lowercase() {
let affine = Affine::new(7, 11);
let ptext = affine.decipher("gnunygoinnlhojlkkfuoinzlhokn");
assert_eq!(ptext.unwrap(), "DEFENDTHEEASTWALLOFTHECASTLE");
}
#[test]
#[should_panic]
fn a_leq_0() {
Affine::new(0, 11);
}
#[test]
#[should_panic]
fn a_geq_26() {
Affine::new(26, 11);
}
#[test]
#[should_panic]
fn b_less_0() {
Affine::new(7, -1);
}
#[test]
#[should_panic]
fn b_geq_26() {
Affine::new(7, 26);
}
#[test]
#[should_panic]
fn a_not_relatively_prime() {
Affine::new(2, 11);
}
#[test]
fn ptext_non_alpha() {
let affine = Affine::new(7, 11);
let ctext = affine.encipher("d3fendtheeastwallofthecastle");
assert_eq!(ctext, Err(CipherInputError::NotAlphabetic));
}
#[test]
fn ctext_non_alpha() {
let affine = Affine::new(7, 11);
let ptext = affine.decipher("6nunygo1nnlhojlkkfuoinzlhokn");
assert_eq!(ptext, Err(CipherInputError::NotAlphabetic));
}