working on moving the 'TestCompression' code into its own crate
This commit is contained in:
@@ -92,7 +92,7 @@ fn level3_compressed_test() {
|
||||
|
||||
assert_eq!(
|
||||
x.dump_video_to_string(),
|
||||
load_compressed_result("gemma_integration.corax_plus")
|
||||
load_compressed_result("gemma_integration_corax_plus")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -132,7 +132,6 @@ fn level4_test() {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn partial_eq_chip8computer() {
|
||||
let x = Chip8Computer::new();
|
||||
@@ -140,6 +139,19 @@ fn partial_eq_chip8computer() {
|
||||
assert_eq!(x, y)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn state_to_json() {
|
||||
let x = Chip8Computer::new();
|
||||
|
||||
let expected = load_compressed_result("gemma_integration_state_to_json1");
|
||||
let actual = x.dump_state_to_json();
|
||||
println!("ACTUAL:: [{}]", actual);
|
||||
|
||||
assert_eq!(
|
||||
actual,
|
||||
expected
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tick_when_not_ready() {}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
mod test_utils;
|
||||
use gemma::chip8::keypad::Keypad;
|
||||
use crate::test_utils::read_compressed_test_result;
|
||||
use gemma::chip8::keypad::Keypad;
|
||||
|
||||
#[test]
|
||||
fn keypad_keys_check() {
|
||||
@@ -20,17 +20,12 @@ fn keypad_keys_check() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn keypad_string_format_test() {
|
||||
let k = Keypad::new();
|
||||
|
||||
let expected_result = read_compressed_test_result("gemma_keypad_string_result");
|
||||
let actual_result = k.format_as_string();
|
||||
|
||||
let actual_result = Keypad::new().format_as_string();
|
||||
|
||||
println!("EXPECTING [{}]", expected_result);
|
||||
println!("GOT [{}]", actual_result);
|
||||
assert_eq!(
|
||||
k.format_as_string(),
|
||||
read_compressed_test_result("gemma_keypad_string_result")
|
||||
);
|
||||
assert_eq!(actual_result, expected_result);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use crate::test_utils::{compress_string, decompress_to_string};
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
use tempfile::{NamedTempFile, tempfile};
|
||||
use gemma::test_compression::TestCompression;
|
||||
|
||||
mod test_utils;
|
||||
|
||||
@@ -10,9 +13,42 @@ fn smoke() {
|
||||
#[test]
|
||||
fn round_trip() {
|
||||
let text_to_process = "The quick brown fox jumps over the lazy dog.";
|
||||
let compressed = compress_string(text_to_process);
|
||||
let decompressed = decompress_to_string(&compressed).unwrap();
|
||||
let compressed = TestCompression::compress_string(text_to_process);
|
||||
let decompressed = TestCompression::decompress_to_string(&compressed).unwrap();
|
||||
|
||||
assert_eq!(text_to_process, decompressed);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compress_file_to_array() {
|
||||
// create a file with plain text...
|
||||
|
||||
// ...compress it to in-memory data
|
||||
|
||||
// ...confirm that matches predefined data
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compress_file() {
|
||||
// create a file with plain text...
|
||||
|
||||
// ...compress it to a temp file...
|
||||
|
||||
// ...read the compressed data...
|
||||
|
||||
// ...verify it matches initial plain text
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decompress_file_to_array() {
|
||||
// crate a file with plain text...
|
||||
|
||||
// ...write the compressed version
|
||||
|
||||
// ...
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decompress_file() {
|
||||
|
||||
}
|
||||
@@ -4,28 +4,16 @@ use flate2::Compression;
|
||||
use std::fs::File;
|
||||
use std::io::{Read, Write};
|
||||
use tempfile::tempfile;
|
||||
const TEST_OUTPUT_SAMPLE_DIR: &str = "../resources/test/";
|
||||
use gemma::test_compression::TestCompression;
|
||||
|
||||
const TEST_OUTPUT_SAMPLE_DIR: &str = "../resources/test/";
|
||||
const TEST_ROMS_SAMPLE_DIR: &str = "../resources/roms/";
|
||||
|
||||
#[test]
|
||||
fn smoke() {
|
||||
assert!(true)
|
||||
}
|
||||
|
||||
pub fn compress_string(input: &str) -> Vec<u8> {
|
||||
let mut encoder = DeflateEncoder::new(Vec::new(), Compression::default());
|
||||
encoder
|
||||
.write_all(input.as_bytes())
|
||||
.expect("Failed to write data");
|
||||
encoder.finish().expect("Failed to finish compression")
|
||||
}
|
||||
pub fn decompress_to_string(compressed_data: &[u8]) -> Result<String, std::io::Error> {
|
||||
let mut decoder = DeflateDecoder::new(compressed_data);
|
||||
let mut decompressed = String::new();
|
||||
decoder.read_to_string(&mut decompressed)?;
|
||||
Ok(decompressed)
|
||||
}
|
||||
|
||||
/// Read a compressed test result and return the expected result
|
||||
/// as a string
|
||||
pub fn read_compressed_test_result(suffix: &str) -> String {
|
||||
@@ -42,7 +30,7 @@ pub fn read_compressed_test_result(suffix: &str) -> String {
|
||||
.read_to_end(&mut compressed_data)
|
||||
.expect("Unable to compress data");
|
||||
|
||||
decompress_to_string(&compressed_data).unwrap()
|
||||
TestCompression::decompress_to_string(&compressed_data).unwrap()
|
||||
}
|
||||
|
||||
pub fn load_compressed_result(suffix: &str) -> String {
|
||||
@@ -50,39 +38,5 @@ pub fn load_compressed_result(suffix: &str) -> String {
|
||||
}
|
||||
|
||||
pub fn load_rom(to_load: &str) -> Vec<u8> {
|
||||
std::fs::read(format!("../resources/roms/{}.ch8", to_load)).unwrap()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn smoke() {
|
||||
assert!(true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn compression_round_trip() {
|
||||
let to_compress = "The quick brown fox jumps over the lazy dog.";
|
||||
|
||||
let compressed_text = compress_string(to_compress);
|
||||
let decompressed_text = decompress_to_string(&compressed_text).unwrap();
|
||||
assert_eq!(to_compress, decompressed_text);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn file_compression_round_trip() {
|
||||
// compress string to file...
|
||||
let string_to_compress = "The quick brown fox jumps over the lazy dog.";
|
||||
let compressed_string = compress_string(string_to_compress);
|
||||
let temp_target = tempfile().unwrap();
|
||||
|
||||
//
|
||||
// ...decompress from file...
|
||||
//
|
||||
// ...verify its the same.
|
||||
}
|
||||
|
||||
|
||||
std::fs::read(format!("{}{}.ch8", TEST_ROMS_SAMPLE_DIR, to_load)).unwrap()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user