From 70a8a4249535dc9b19eb5f8efd2330ac90717eb5 Mon Sep 17 00:00:00 2001 From: Denis Nutiu Date: Fri, 13 Dec 2024 14:56:55 +0200 Subject: [PATCH] add unit tests for skip instructions --- src/emulator.rs | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/emulator.rs b/src/emulator.rs index f1933fd..f655034 100644 --- a/src/emulator.rs +++ b/src/emulator.rs @@ -757,4 +757,65 @@ mod tests { assert_eq!(emulator.program_counter, 0xABE); } + + #[test] + fn test_execute_random_number() { + let mut emulator = Emulator::new(TerminalDisplay::new(), TerminalSound, NoInput); + + emulator + .execute_instruction(Instruction::new([0xCA, 0xBC])) + .expect("Failed to execute"); + + assert!(emulator.registers[0xA] <= 0xBC) + } + + #[test] + fn test_execute_skip_equal_vx_data() { + let mut emulator = Emulator::new(TerminalDisplay::new(), TerminalSound, NoInput); + emulator.registers[0xA] = 0xBC; + + emulator + .execute_instruction(Instruction::new([0x3A, 0xBC])) + .expect("Failed to execute"); + + assert_eq!(emulator.program_counter, 2); + } + + #[test] + fn test_execute_skip_not_equal_vx_data() { + let mut emulator = Emulator::new(TerminalDisplay::new(), TerminalSound, NoInput); + emulator.registers[0xA] = 0xB1; + + emulator + .execute_instruction(Instruction::new([0x4A, 0xBC])) + .expect("Failed to execute"); + + assert_eq!(emulator.program_counter, 2); + } + + #[test] + fn test_execute_skip_equal_vx_vy() { + let mut emulator = Emulator::new(TerminalDisplay::new(), TerminalSound, NoInput); + emulator.registers[0xA] = 0xBC; + emulator.registers[0xB] = 0xBC; + + emulator + .execute_instruction(Instruction::new([0x5A, 0xB0])) + .expect("Failed to execute"); + + assert_eq!(emulator.program_counter, 2); + } + + #[test] + fn test_execute_skip_not_equal_vx_vy() { + let mut emulator = Emulator::new(TerminalDisplay::new(), TerminalSound, NoInput); + emulator.registers[0xA] = 0xBD; + emulator.registers[0xB] = 0xBC; + + emulator + .execute_instruction(Instruction::new([0x9A, 0xB0])) + .expect("Failed to execute"); + + assert_eq!(emulator.program_counter, 2); + } }