update tests

This commit is contained in:
2025-06-12 14:33:43 -04:00
parent 703ae38814
commit 0b11b91fe4
6 changed files with 52 additions and 28 deletions
+12 -2
View File
@@ -2,13 +2,13 @@ use trevors_utilities::data_to_text::DataToText;
fn read_bin(source: &str) -> Vec<u8> {
let full_path = format!("/home/tmerritt/Projects/trevors_utilities/resources/data_to_text/{}.bin", source);
println!("FULL PATH BIN: [{}]", full_path);
// println!("FULL PATH BIN: [{}]", full_path);
std::fs::read(full_path).unwrap()
}
fn read_display(source: &str) -> String {
let full_path = format!("/home/tmerritt/Projects/trevors_utilities/resources/data_to_text/{}.display", source);
println!("FULL PATH DIS: [{}]", full_path);
// println!("FULL PATH DIS: [{}]", full_path);
std::fs::read_to_string(full_path).unwrap()
}
@@ -46,3 +46,13 @@ fn quickbrownfoxtest() {
);
}
}
#[test]
fn data_to_text_window_all() {
let bin_data = read_bin("quickbrownfox");
let formatted = DataToText::data_to_text_window(&bin_data, 0, bin_data.len());
let expected = read_display("quickbrownfox");
assert_eq!(
formatted, expected
);
}
+26 -1
View File
@@ -136,4 +136,29 @@ fn compress_file_to_array() {
}
#[test]
fn decompress_to_array() {}
fn decompress_to_array() {
let original_text = "The quick brown fox jumps over the lazy dog.";
let compressed_data = TestCompression::compress_string(original_text);
// Write the compressed data to a temp file
let mut temp_file = NamedTempFile::new().expect("Failed to create temp file");
temp_file
.write_all(&compressed_data)
.expect("Failed to write compressed data to file");
// Run the method under test
let decompressed_data = TestCompression::decompress_file_to_array(temp_file.path());
// Convert to string to compare
let decompressed_text = String::from_utf8(decompressed_data)
.expect("Decompressed bytes were not valid UTF-8");
assert_eq!(decompressed_text, original_text);
}
#[test]
#[should_panic(expected = "No such file or directory")]
fn decompress_file_panics_on_missing_path() {
let bad_path = std::path::Path::new("/definitely/invalid/path");
TestCompression::decompress_file_to_array(bad_path);
}