Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/string/burrows_wheeler_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions src/string/run_length_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ 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);
let is_numeric: bool = character_count.parse::<i32>().is_ok();

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()),
Expand All @@ -48,7 +48,7 @@ pub fn run_length_decoding(target: String) -> String {
}
}

encoded_target
decoded_target
}

#[cfg(test)]
Expand Down