pub mod collections;
pub mod error;
pub mod probes;
pub mod prog;
mod platform;
#[cfg(test)]
mod tests {
use crate::collections::{Array, HashMap, Queue};
#[test]
fn hashmap_insert_get() {
let list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
let map = HashMap::<u32, [u8; 16]>::with_capacity(10).unwrap();
assert!(map.insert(300, list).is_ok());
assert!(map.get(300).is_ok());
assert_eq!(map.get(300).unwrap(), list);
}
#[test]
fn queue_push_pop() {
const QUEUE_SIZE: u32 = 10;
let queue = Queue::<u32>::with_capacity(QUEUE_SIZE).unwrap();
for i in 0..10 {
assert!(queue.push(i + 100).is_ok());
}
assert!(queue.push(1000).is_err());
assert!(matches!(queue.front(), Ok(100)));
assert!(matches!(queue.front(), Ok(100)));
for i in 0..10 {
match queue.pop() {
Ok(val) => assert_eq!(val, i + 100),
Err(e) => panic!("queue.pop() failed: {}", e),
}
}
assert!(queue.pop().is_err());
}
#[test]
fn array_set_get() {
const ARRAY_SIZE: u32 = 10;
let array = Array::<u32>::with_capacity(ARRAY_SIZE).unwrap();
for i in 0..ARRAY_SIZE {
let val = i + 100;
assert!(matches!(array.get(i), Ok(0)));
assert!(array.set(i, val).is_ok());
match array.get(i) {
Ok(v) => assert_eq!(v, val),
Err(e) => panic!("array.get() failed: {}", e),
}
}
}
}