From 66eeb8f2b7975415b3448d9dab3aa9a3cca94570 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Wed, 18 Jan 2023 17:01:48 +0100 Subject: [PATCH] Add tests momery --- src/simulator/machine.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/simulator/machine.rs b/src/simulator/machine.rs index 000a1fe..e71328b 100644 --- a/src/simulator/machine.rs +++ b/src/simulator/machine.rs @@ -308,9 +308,9 @@ impl Machine { }, RISCV_OP_SLT => { if machine.int_reg[inst.rs1 as usize] < machine.int_reg[inst.rs2 as usize] { - machine.int_reg[inst.rd as usize] = 1; + machine.int_reg[inst.rd as usize] = 1; } else { - machine.int_reg[inst.rd as usize] = 0; + machine.int_reg[inst.rd as usize] = 0; } }, RISCV_OP_SLTU => { @@ -410,5 +410,20 @@ impl Machine { #[cfg(test)] mod test { + use crate::simulator::machine::Machine; + #[test] + fn test_read_memory() { + let mut m = Machine::_init_machine(); + m.main_memory[4] = 43; + m.main_memory[5] = 150; + assert_eq!((43 << 8) + 150, Machine::read_memory(&mut m, 2, 4)); + } + + fn test_write_memory() { + let mut m = Machine::_init_machine(); + Machine::write_memory(&mut m, 2, 6, (43 << 8) + 150); + assert_eq!(43, m.main_memory[6]); + assert_eq!(150, m.main_memory[7]); + } }