Skip to content

Commit

Permalink
do-core: memory: Add unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
  • Loading branch information
Samuel Ortiz authored and Samuel Ortiz committed Mar 21, 2022
1 parent 7f28b0c commit fec06d0
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions do-core/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}

0 comments on commit fec06d0

Please sign in to comment.