From 05ea1488a5f852fcf5d09daee45b1e9d759b21a6 Mon Sep 17 00:00:00 2001 From: Denis Nutiu Date: Fri, 13 Dec 2024 14:26:00 +0200 Subject: [PATCH] add unit tests for call & return --- src/emulator.rs | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/src/emulator.rs b/src/emulator.rs index 95badc8..c7d00f6 100644 --- a/src/emulator.rs +++ b/src/emulator.rs @@ -548,7 +548,7 @@ mod tests { } #[test] - fn test_set_register() { + fn test_execute_set_register() { let mut emulator = Emulator::new(TerminalDisplay::new(), TerminalSound, NoInput); for i in 0x0..=0xF { @@ -561,7 +561,7 @@ mod tests { } #[test] - fn test_add_value_to_register() { + fn test_execute_add_value_to_register() { let mut emulator = Emulator::new(TerminalDisplay::new(), TerminalSound, NoInput); emulator @@ -581,7 +581,7 @@ mod tests { } #[test] - fn test_set_index_register() { + fn test_execute_set_index_register() { let mut emulator = Emulator::new(TerminalDisplay::new(), TerminalSound, NoInput); emulator @@ -592,7 +592,7 @@ mod tests { } #[test] - fn test_draw() { + fn test_execute_draw() { let mut emulator = Emulator::new(TerminalDisplay::new(), TerminalSound, NoInput); emulator.index_register = 0xF0; @@ -605,4 +605,29 @@ mod tests { [true, true, true, true, false, false] ) } + + #[test] + fn test_execute_call() { + let mut emulator = Emulator::new(TerminalDisplay::new(), TerminalSound, NoInput); + emulator.program_counter = 0x200; + + emulator + .execute_instruction(Instruction::new([0x2A, 0xBC])) + .expect("Failed to execute"); + + assert_eq!(emulator.program_counter, 0xABC); + assert_eq!(emulator.stack.peek().unwrap(), &0x200); + } + + #[test] + fn test_execute_return() { + let mut emulator = Emulator::new(TerminalDisplay::new(), TerminalSound, NoInput); + emulator.stack.push(0x269); + + emulator + .execute_instruction(Instruction::new([0x00, 0xEE])) + .expect("Failed to execute"); + + assert_eq!(emulator.program_counter, 0x269); + } }