adds smoke tests to everything
adds deflated test examples
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use std::path::Path;
|
||||
mod test_utils;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::Instant;
|
||||
use gemma::chip8::computer::Chip8Computer;
|
||||
use gemma::chip8::computer_manager::Chip8ComputerManager;
|
||||
@@ -6,19 +7,13 @@ use gemma::chip8::quirk_modes::QuirkMode;
|
||||
use gemma::chip8::quirk_modes::QuirkMode::{Chip8, SChipModern, XOChip};
|
||||
use gemma::chip8::registers::Chip8Registers;
|
||||
use gemma::constants::{CHIP8_VIDEO_MEMORY, TESTS_ROOT};
|
||||
use crate::test_utils::{load_compressed_result, load_result, load_rom};
|
||||
|
||||
#[test]
|
||||
fn smoke() {
|
||||
assert!(true)
|
||||
}
|
||||
|
||||
fn load_result(to_load: &str) -> String {
|
||||
std::fs::read_to_string(format!("../resources/test/{}", to_load)).unwrap()
|
||||
}
|
||||
|
||||
fn load_rom(to_load: &str) -> Vec<u8> {
|
||||
std::fs::read(format!("../resources/roms/{}", to_load)).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reset_clears_video() {
|
||||
@@ -88,6 +83,21 @@ fn level3_test() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn level3_compressed_test() {
|
||||
let mut x = Chip8Computer::new();
|
||||
|
||||
x.load_bytes_to_memory(0x200, &load_rom("3-corax+.ch8"));
|
||||
for i in 0..0x180 {
|
||||
x.step_system();
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
x.dump_video_to_string(),
|
||||
load_compressed_result("gemma_integration.corax_plus.deflated")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rps_test() {
|
||||
let mut x = Chip8Computer::new();
|
||||
@@ -97,7 +107,7 @@ fn rps_test() {
|
||||
}
|
||||
assert_eq!(
|
||||
x.dump_video_to_string(),
|
||||
load_result("gemma_integration_rps_stage1.asc")
|
||||
load_compressed_result("gemma_integration_rps_stage1")
|
||||
);
|
||||
x.keypad.push_key(0x01);
|
||||
for _ in 0..0x200 {
|
||||
@@ -105,7 +115,7 @@ fn rps_test() {
|
||||
}
|
||||
assert_eq!(
|
||||
x.dump_video_to_string(),
|
||||
load_result("gemma_integration_rps_stage2.asc")
|
||||
load_compressed_result("gemma_integration_rps_stage2")
|
||||
);
|
||||
}
|
||||
|
||||
@@ -176,11 +186,11 @@ fn quirks_mode_test() {
|
||||
#[test]
|
||||
fn load_rom_allows_starting() {
|
||||
let mut new_manager = Chip8ComputerManager::default();
|
||||
assert_eq!(new_manager.core_should_run, false);
|
||||
assert!(!new_manager.core_should_run);
|
||||
let p = format!("{}/../resources/test/roms/1-chip8-logo.ch8" , std::env::current_dir().unwrap().display());
|
||||
let full_path = Path::new(p.as_str());
|
||||
new_manager.load_new_program_from_disk_to_system_memory(full_path);
|
||||
assert_eq!(new_manager.core_should_run, true)
|
||||
assert!(new_manager.core_should_run)
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -189,5 +199,20 @@ fn reset_clears_run_state() {
|
||||
let p = format!("{}/../resources/test/roms/1-chip8-logo.ch8", std::env::current_dir().unwrap().display());
|
||||
new_manager.load_new_program_from_disk_to_system_memory(Path::new(p.as_str()));
|
||||
new_manager.reset(QuirkMode::Chip8);
|
||||
assert_eq!(new_manager.core_should_run, false);
|
||||
assert!(!new_manager.core_should_run);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tick_when_ready() {
|
||||
let mut new_manager = Chip8ComputerManager::default();
|
||||
new_manager.load_new_program_from_disk_to_system_memory(Path::new(
|
||||
format!("{}/../resources/test/roms/1-chip8-logo.ch8", std::env::current_dir().unwrap().display()).as_str()));
|
||||
assert!(new_manager.core_should_run);
|
||||
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tick_when_not_ready() {}
|
||||
|
||||
#[test]
|
||||
fn tick_one_step_only() {}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
use crate::test_utils::{compress_string, decompress_to_string};
|
||||
|
||||
mod test_utils;
|
||||
|
||||
#[test]
|
||||
fn smoke() {
|
||||
assert!(true)
|
||||
}
|
||||
|
||||
#[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();
|
||||
|
||||
assert_eq!(text_to_process, decompressed);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
use std::fs::File;
|
||||
use std::io::{Read, Write};
|
||||
use std::path::Path;
|
||||
use flate2::Compression;
|
||||
use flate2::read::DeflateDecoder;
|
||||
use flate2::write::{DeflateEncoder};
|
||||
|
||||
use log::debug;
|
||||
|
||||
const TEST_OUTPUT_SAMPLE_DIR: &str = "../resources/test/";
|
||||
|
||||
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 {
|
||||
let full_path = std::env::current_dir().unwrap().display().to_string() + "/" + &*TEST_OUTPUT_SAMPLE_DIR.to_owned() + suffix + ".deflated";
|
||||
println!("LOADING {}", full_path);
|
||||
let mut compressed_file = File::open(full_path).expect(format!("Unable to load test result [{}]", suffix).as_str());
|
||||
let mut compressed_data = Vec::new();
|
||||
compressed_file.read_to_end(&mut compressed_data).expect("Unable to compress data");
|
||||
|
||||
decompress_to_string(&compressed_data).unwrap()
|
||||
}
|
||||
|
||||
pub fn load_compressed_result(suffix: &str) -> String {
|
||||
read_compressed_test_result(suffix)
|
||||
}
|
||||
|
||||
pub fn read_test_result(suffix: &str) -> String {
|
||||
std::fs::read_to_string(TEST_OUTPUT_SAMPLE_DIR.to_owned() + suffix).unwrap()
|
||||
}
|
||||
|
||||
|
||||
pub fn load_result(to_load: &str) -> String {
|
||||
std::fs::read_to_string(format!("../resources/test/{}", to_load)).unwrap()
|
||||
}
|
||||
|
||||
pub fn load_rom(to_load: &str) -> Vec<u8> {
|
||||
std::fs::read(format!("../resources/roms/{}", to_load)).unwrap()
|
||||
}
|
||||
@@ -18,14 +18,9 @@ use log::debug;
|
||||
use rand::random;
|
||||
use serde::Serialize;
|
||||
use gemma::chip8::computer_manager::Chip8ComputerManager;
|
||||
use crate::test_utils::read_test_result;
|
||||
|
||||
const TEST_OUTPUT_SAMPLE_DIR: &str = "../resources/test/";
|
||||
|
||||
fn read_test_result(suffix: &str) -> String {
|
||||
println!("SITTING IN {:?}", std::env::current_dir());
|
||||
println!("ATTEMPT TO READ RESULT {suffix}");
|
||||
std::fs::read_to_string(TEST_OUTPUT_SAMPLE_DIR.to_owned() + suffix).unwrap()
|
||||
}
|
||||
mod test_utils;
|
||||
|
||||
#[test]
|
||||
fn smoke() {
|
||||
|
||||
@@ -21,7 +21,6 @@ fn byte_to_bools() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn bools_to_byte() {
|
||||
let data_set: BTreeMap<u8, [bool; 8]> = BTreeMap::from(
|
||||
|
||||
Reference in New Issue
Block a user