diff --git a/src/string/burrows_wheeler_transform.rs b/src/string/burrows_wheeler_transform.rs index e89e8611166..656fd2a1098 100644 --- a/src/string/burrows_wheeler_transform.rs +++ b/src/string/burrows_wheeler_transform.rs @@ -43,7 +43,35 @@ mod tests { use super::*; #[test] - fn basic() { + //Ensure function stand-alone legitimacy + fn stand_alone_function() { + assert_eq!( + burrows_wheeler_transform("CARROT".to_string()), + ("CTRRAO".to_string(), 1usize) + ); + assert_eq!( + inv_burrows_wheeler_transform(("CTRRAO".to_string(), 1usize)), + ("CARROT".to_string()) + ); + assert_eq!( + burrows_wheeler_transform("THEALGORITHMS".to_string()), + ("EHLTTRAHGOMSI".to_string(), 11usize) + ); + assert_eq!( + inv_burrows_wheeler_transform(("EHLTTRAHGOMSI".to_string(), 11usize)), + ("THEALGORITHMS".to_string()) + ); + assert_eq!( + burrows_wheeler_transform("!.!.!??.=::".to_string()), + (":..!!?:=.?!".to_string(), 0usize) + ); + assert_eq!( + inv_burrows_wheeler_transform((":..!!?:=.?!".to_string(), 0usize)), + "!.!.!??.=::" + ); + } + #[test] + fn basic_characters() { assert_eq!( inv_burrows_wheeler_transform(burrows_wheeler_transform("CARROT".to_string())), "CARROT" diff --git a/src/string/run_length_encoding.rs b/src/string/run_length_encoding.rs index e42e5810c32..631444616de 100644 --- a/src/string/run_length_encoding.rs +++ b/src/string/run_length_encoding.rs @@ -31,7 +31,7 @@ pub fn run_length_decoding(target: String) -> String { } let mut character_count: String = String::new(); - let mut encoded_target = String::new(); + let mut decoded_target = String::new(); for c in target.as_str().chars() { character_count.push(c); @@ -39,7 +39,7 @@ pub fn run_length_decoding(target: String) -> String { if !is_numeric { let pop_char: char = character_count.pop().unwrap(); - encoded_target.push_str( + decoded_target.push_str( &pop_char .to_string() .repeat(character_count.parse().unwrap()), @@ -48,7 +48,7 @@ pub fn run_length_decoding(target: String) -> String { } } - encoded_target + decoded_target } #[cfg(test)]