Add test
This commit is contained in:
parent
a01417e4c8
commit
2393838fcd
32
src/disc.rs
32
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user