trevors_chip8_toy/gemma/tests/computer_tests.rs

161 lines
3.6 KiB
Rust

mod test_utils;
use crate::test_utils::load_compressed_result;
use crate::test_utils::load_rom;
use gemma::chip8::computer::Chip8Computer;
use gemma::chip8::computer_manager::Chip8ComputerManager;
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, TEST_ROM_ROOT};
use std::path::Path;
#[test]
fn smoke() {
assert!(true)
}
#[test]
fn reset_clears_video() {
let mut x = Chip8Computer::new();
for i in 0..CHIP8_VIDEO_MEMORY {
x.video_memory.poke(i as u16, i % 2 == 0);
}
x.reset(gemma::chip8::quirk_modes::QuirkMode::Chip8);
x.video_memory.reset();
assert_eq!(x.dump_video_to_string(), x.video_memory.format_as_string());
for i in 0..CHIP8_VIDEO_MEMORY {
assert!(!x.video_memory.peek(i as u16));
}
}
#[test]
fn level1_test() {
let mut x = Chip8Computer::new();
let level_1_rom = load_rom("1-chip8-logo");
x.load_bytes_to_memory(0x200, &level_1_rom);
// run for 0x40 cycles
while x.num_cycles < 0x40 {
x.step_system();
}
assert_eq!(
x.dump_video_to_string(),
load_compressed_result("gemma_integration_level_1_test")
);
}
#[test]
fn level2_test() {
let mut x = Chip8Computer::new();
// Load the IBM rom and run it.
// it takes 39 cycles to get to the end so lets run it 40.
x.load_bytes_to_memory(0x200, &load_rom("2-ibm-logo"));
for _ in 0..40 {
x.step_system();
}
// ...then verify that the current video memory of the chip-8
// simulator matches what we expect it to be
assert_eq!(
x.dump_video_to_string(),
load_compressed_result("gemma_integration_ibm_rom_output")
);
}
#[test]
fn level3_test() {
let mut x = Chip8Computer::new();
x.load_bytes_to_memory(0x200, &load_rom("3-corax+"));
for _ in 0..0x180 {
x.step_system();
}
assert_eq!(
x.dump_video_to_string(),
load_compressed_result("gemma_integration_corax_plus")
);
}
#[test]
fn level3_compressed_test() {
let mut x = Chip8Computer::new();
x.load_bytes_to_memory(0x200, &load_rom("3-corax+"));
for _ in 0..0x180 {
x.step_system();
}
assert_eq!(
x.dump_video_to_string(),
load_compressed_result("gemma_integration_corax_plus")
);
}
#[test]
fn rps_test() {
let mut x = Chip8Computer::new();
x.load_bytes_to_memory(0x200, &load_rom("RPS"));
for _ in 0..0xF0 {
x.step_system();
}
assert_eq!(
x.dump_video_to_string(),
load_compressed_result("gemma_integration_rps_stage1")
);
x.keypad.push_key(0x01);
for _ in 0..0x200 {
x.step_system();
}
assert_eq!(
x.dump_video_to_string(),
load_compressed_result("gemma_integration_rps_stage2")
);
}
#[test]
fn level4_test() {
// flags
let mut x = Chip8Computer::new();
x.load_bytes_to_memory(0x200, &load_rom("4-flags"));
for _ in 0..0x400 {
x.step_system();
}
assert_eq!(
x.dump_video_to_string(),
load_compressed_result("gemma_integration_flags")
);
}
#[test]
fn partial_eq_chip8computer() {
let x = Chip8Computer::new();
let y = Chip8Computer::new();
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() {}
#[test]
fn tick_one_step_only() {}