Basic tests

This commit is contained in:
Reid 'arrdem' McKenzie 2022-12-18 15:20:06 -07:00
parent 518a71d24a
commit da885e3984

View file

@ -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"),
}
}
}