Commit 1d56e6db authored by Arthur Carlsson's avatar Arthur Carlsson

Fixed tests

parent 65376d14
Pipeline #5189639 passed with stage
in 2 minutes and 25 seconds
...@@ -24,3 +24,39 @@ impl<T> MMap<T> { ...@@ -24,3 +24,39 @@ impl<T> MMap<T> {
} }
} }
} }
#[cfg(test)]
mod tests {
use super::*;
#[derive(Debug, PartialEq)]
enum MyAddr {
A(PhysicalAddr)
}
fn mmap() -> MMap<MyAddr> {
MMap::new(1234..5678, Box::new(MyAddr::A))
}
#[test]
fn test_read_word() {
assert_eq!(Some(MyAddr::A(6)), mmap().map_addr(1240));
}
#[test]
fn test_read_word_no_match() {
assert_eq!(None, mmap().map_addr(11000));
}
#[test]
fn test_read_word_address_map() {
assert_eq!(Some(MyAddr::A(1)), mmap().map_addr(1235));
}
#[test]
fn test_read_word_edge() {
assert_eq!(None, mmap().map_addr(5678));
assert_eq!(Some(MyAddr::A(0)), mmap().map_addr(1234));
}
}
...@@ -26,47 +26,3 @@ impl Bus { ...@@ -26,47 +26,3 @@ impl Bus {
.map(|mm| mm.unwrap()) .map(|mm| mm.unwrap())
} }
} }
#[cfg(test)]
mod tests {
use super::*;
use mem::MMap;
#[test]
fn test_read_word() {
let bus = Bus::new(vec![
MMap::new(1234..5678, Box::new(|_| 1))
]);
assert_eq!(Some(1), bus.read_word(4678))
}
#[test]
fn test_read_word_no_match() {
let bus = Bus::new(vec![
MMap::new(1234..5678, Box::new(|_| 1))
]);
assert_eq!(None, bus.read_word(9123))
}
#[test]
fn test_read_word_address_map() {
let bus = Bus::new(vec![
MMap::new(1234..5678, Box::new(|addr| addr as u32))
]);
assert_eq!(Some(1), bus.read_word(1235))
}
#[test]
fn test_read_word_edge() {
let bus = Bus::new(vec![
MMap::new(1234..5678, Box::new(|_| 1))
]);
assert_eq!(None, bus.read_word(5678));
assert_eq!(Some(1), bus.read_word(1234));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment