From 2393838fcd790ae83bd4a66f8e248d8f014a9835 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Thu, 8 May 2025 19:35:06 -0600 Subject: [PATCH] Add test --- src/disc.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/disc.rs b/src/disc.rs index 10c744f..2351fe5 100644 --- a/src/disc.rs +++ b/src/disc.rs @@ -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); + } +}