From fec06d000b885e57c5dca058f47a259849b9bb7c Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Thu, 11 Mar 2021 20:09:31 +0100 Subject: [PATCH] do-core: memory: Add unit tests Signed-off-by: Samuel Ortiz --- do-core/src/memory.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/do-core/src/memory.rs b/do-core/src/memory.rs index 4412c63..d69f483 100644 --- a/do-core/src/memory.rs +++ b/do-core/src/memory.rs @@ -31,3 +31,28 @@ impl Memory { Ok(()) } } + +#[cfg(test)] +mod tests { + use crate::memory::Memory; + use crate::Error; + + #[test] + fn test_memory_store_load() -> Result<(), Error> { + let mut memory = Memory::new(4096); + + memory.store(0x100, 0xf)?; + assert_eq!(memory.load(0x100)?, 0xf); + + Ok(()) + } + + #[test] + fn test_memory_overflow() -> Result<(), Error> { + let mut memory = Memory::new(4096); + + assert!(memory.store(0x2000, 0xf).is_err()); + + Ok(()) + } +}