From da885e398427ae74a33239f8175e8ba7b348bea7 Mon Sep 17 00:00:00 2001 From: Reid 'arrdem' McKenzie Date: Sun, 18 Dec 2022 15:20:06 -0700 Subject: [PATCH] Basic tests --- src/memory.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/memory.rs b/src/memory.rs index e6f8e08..534364c 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -62,3 +62,56 @@ impl Memory for TrivialMemory { } } } + +#[cfg(test)] +mod mem_test { + use super::*; + + #[test] + fn test_set1_get1() { + let mut mem = TrivialMemory::new(); + let idx = 0xFAFBu16; + match mem.set1(idx, 0xFF) { + Ok(_) => (), + Err(_) => assert!(false, "failed poking memory"), + } + match mem.get1(idx) { + Ok(v) => assert_eq!(v, 0xFF), + Err(_) => assert!(false, "get1 raised"), + } + } + + #[test] + fn test_set2_get2() { + let mut mem = TrivialMemory::new(); + let idx = 0xFAFBu16; + match mem.set2(idx, 0xFF00) { + Ok(_) => (), + Err(_) => assert!(false, "failed poking memory"), + } + match mem.get2(idx) { + Ok(v) => assert_eq!(v, 0xFF00), + Err(_) => assert!(false, "get1 raised"), + } + } + + #[test] + fn test_set2_get1_get1() { + let mut mem = TrivialMemory::new(); + let idx = 0xFAFBu16; + match mem.set2(idx, 0xFF00) { + Ok(_) => (), + Err(_) => assert!(false, "failed poking memory"), + } + + match mem.get1(idx) { + Ok(v) => assert_eq!(v, 0xFF), + Err(_) => assert!(false, "get1 raised"), + } + + match mem.get1(idx + 1) { + Ok(v) => assert_eq!(v, 0x00), + Err(_) => assert!(false, "get1 raised"), + } + } +}