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 {
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"
Original file line number Diff line number Diff 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) ]
You can’t perform that action at this time.
0 commit comments