File tree Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,35 @@ mod tests {
43
43
use super :: * ;
44
44
45
45
#[ 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 ( ) {
47
75
assert_eq ! (
48
76
inv_burrows_wheeler_transform( burrows_wheeler_transform( "CARROT" . to_string( ) ) ) ,
49
77
"CARROT"
Original file line number Diff line number Diff line change @@ -31,15 +31,15 @@ pub fn run_length_decoding(target: String) -> String {
31
31
}
32
32
33
33
let mut character_count: String = String :: new ( ) ;
34
- let mut encoded_target = String :: new ( ) ;
34
+ let mut decoded_target = String :: new ( ) ;
35
35
36
36
for c in target. as_str ( ) . chars ( ) {
37
37
character_count. push ( c) ;
38
38
let is_numeric: bool = character_count. parse :: < i32 > ( ) . is_ok ( ) ;
39
39
40
40
if !is_numeric {
41
41
let pop_char: char = character_count. pop ( ) . unwrap ( ) ;
42
- encoded_target . push_str (
42
+ decoded_target . push_str (
43
43
& pop_char
44
44
. to_string ( )
45
45
. repeat ( character_count. parse ( ) . unwrap ( ) ) ,
@@ -48,7 +48,7 @@ pub fn run_length_decoding(target: String) -> String {
48
48
}
49
49
}
50
50
51
- encoded_target
51
+ decoded_target
52
52
}
53
53
54
54
#[ cfg( test) ]
You can’t perform that action at this time.
0 commit comments