This commit is contained in:
Joey Hines 2025-05-08 19:35:06 -06:00
parent a01417e4c8
commit 2393838fcd
Signed by: joeyahines
GPG Key ID: 38BA6F25C94C9382

View File

@ -109,3 +109,35 @@ impl DecoderState {
return char;
}
}
#[cfg(test)]
mod test {
use crate::disc::DecoderState;
#[test]
pub fn test_encode() {
let inner_disc = ['a', 't', 'o', 'v', 'w', 'r', '7', '4', 'h', 'f', 'k', 'n', '9', 'b', '2', 'x', 'i', 'd', 'u', '1', 'e', '6', 'g', 's', 'l', 'p', 'j', '8', 'z', '3', 'm', '5', 'q', 'c', '0', 'y'];
let outer_disc = ['9', 'z', '2', '7', 'h', 'w', '6', 'u', 'b', 'o', '4', 'm', '0', '3', 'j', 't', 'd', 'r', 'n', 'g', '1', 'i', '8', 'k', 'l', 'x', 'y', 'p', 's', 'v', 'e', 'a', 'c', 'q', '5', 'f'];
let mut decoder = DecoderState::new(inner_disc.to_vec(), outer_disc.to_vec());
decoder.set_index(2);
let input_msg = "hello1";
let expected_output_msg = "4ksvby";
let mut output_msg = Vec::new();
for l in input_msg.chars() {
let new_l = decoder.encode(l);
output_msg.push(new_l);
decoder.change_index(1);
}
let output_msg: String = output_msg.iter().collect();
assert_eq!(output_msg, expected_output_msg);
}
}