Skip to content

Commit a59a423

Browse files
authored
Add tests for burrows_wheeler_transform (TheAlgorithms#380)
1 parent d26cbb1 commit a59a423

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

src/string/burrows_wheeler_transform.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,35 @@ mod tests {
4343
use super::*;
4444

4545
#[test]
46-
fn basic() {
46+
//Ensure function stand-alone legitimacy
47+
fn stand_alone_function() {
48+
assert_eq!(
49+
burrows_wheeler_transform("CARROT".to_string()),
50+
("CTRRAO".to_string(), 1usize)
51+
);
52+
assert_eq!(
53+
inv_burrows_wheeler_transform(("CTRRAO".to_string(), 1usize)),
54+
("CARROT".to_string())
55+
);
56+
assert_eq!(
57+
burrows_wheeler_transform("THEALGORITHMS".to_string()),
58+
("EHLTTRAHGOMSI".to_string(), 11usize)
59+
);
60+
assert_eq!(
61+
inv_burrows_wheeler_transform(("EHLTTRAHGOMSI".to_string(), 11usize)),
62+
("THEALGORITHMS".to_string())
63+
);
64+
assert_eq!(
65+
burrows_wheeler_transform("!.!.!??.=::".to_string()),
66+
(":..!!?:=.?!".to_string(), 0usize)
67+
);
68+
assert_eq!(
69+
inv_burrows_wheeler_transform((":..!!?:=.?!".to_string(), 0usize)),
70+
"!.!.!??.=::"
71+
);
72+
}
73+
#[test]
74+
fn basic_characters() {
4775
assert_eq!(
4876
inv_burrows_wheeler_transform(burrows_wheeler_transform("CARROT".to_string())),
4977
"CARROT"

src/string/run_length_encoding.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ pub fn run_length_decoding(target: String) -> String {
3131
}
3232

3333
let mut character_count: String = String::new();
34-
let mut encoded_target = String::new();
34+
let mut decoded_target = String::new();
3535

3636
for c in target.as_str().chars() {
3737
character_count.push(c);
3838
let is_numeric: bool = character_count.parse::<i32>().is_ok();
3939

4040
if !is_numeric {
4141
let pop_char: char = character_count.pop().unwrap();
42-
encoded_target.push_str(
42+
decoded_target.push_str(
4343
&pop_char
4444
.to_string()
4545
.repeat(character_count.parse().unwrap()),
@@ -48,7 +48,7 @@ pub fn run_length_decoding(target: String) -> String {
4848
}
4949
}
5050

51-
encoded_target
51+
decoded_target
5252
}
5353

5454
#[cfg(test)]

0 commit comments

Comments
 (0)