From 233c36ce7ee96e69b9c064bc04c6fc921ea26b14 Mon Sep 17 00:00:00 2001 From: Andrew Keeton Date: Thu, 13 Nov 2014 19:52:10 -0500 Subject: [PATCH] Add compare_test(). --- src/machine.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/src/machine.rs b/src/machine.rs index e36093c..4848ae2 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -1030,3 +1030,53 @@ fn branch_if_overflow_set_test() { machine.branch_if_overflow_set(Address(0xABCD)); assert_eq!(machine.registers.program_counter, Address(0xABCD)); } + +#[test] +fn compare_test() { + let mut machine = Machine::new(); + + machine.execute_instruction( + (instruction::LDA, instruction::UseImmediate(127)) + ); + + machine.compare(127); + assert!( machine.registers.status.contains(PS_ZERO )); + assert!( machine.registers.status.contains(PS_CARRY )); + assert!(!machine.registers.status.contains(PS_NEGATIVE)); + + machine.execute_instruction( + (instruction::LDA, instruction::UseImmediate(127)) + ); + + machine.compare(1); + assert!(!machine.registers.status.contains(PS_ZERO )); + assert!( machine.registers.status.contains(PS_CARRY )); + assert!(!machine.registers.status.contains(PS_NEGATIVE)); + + machine.execute_instruction( + (instruction::LDA, instruction::UseImmediate(1)) + ); + + machine.compare(2); + assert!(!machine.registers.status.contains(PS_ZERO )); + assert!(!machine.registers.status.contains(PS_CARRY )); + assert!(!machine.registers.status.contains(PS_NEGATIVE)); + + machine.execute_instruction( + (instruction::LDA, instruction::UseImmediate(1)) + ); + + machine.compare(2); + assert!(!machine.registers.status.contains(PS_ZERO )); + assert!(!machine.registers.status.contains(PS_CARRY )); + assert!( machine.registers.status.contains(PS_NEGATIVE)); + + machine.execute_instruction( + (instruction::LDA, instruction::UseImmediate(20)) + ); + + machine.compare(-50); + assert!(!machine.registers.status.contains(PS_ZERO )); + assert!( machine.registers.status.contains(PS_CARRY )); + assert!(!machine.registers.status.contains(PS_NEGATIVE)); +} \ No newline at end of file