1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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_set_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]>::create(10).unwrap();
assert!(matches!(map.set(300, list), Ok(_)));
assert!(matches!(map.get(300), Ok(_)));
assert_eq!(map.get(300).unwrap(), list);
}
#[test]
fn queue_push_pop() {
const QUEUE_SIZE: u32 = 10;
let queue = Queue::<u32>::create(QUEUE_SIZE).unwrap();
for i in 0..10 {
assert!(matches!(queue.push(i + 100), Ok(_)));
}
assert!(matches!(queue.push(1000), 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!(matches!(queue.pop(), Err(_)));
}
#[test]
fn array_set_get() {
const ARRAY_SIZE: u32 = 10;
let array = Array::<u32>::create(ARRAY_SIZE).unwrap();
for i in 0..ARRAY_SIZE {
let val = i + 100;
assert!(matches!(array.get(i), Ok(0)));
assert!(matches!(array.set(i, val), Ok(_)));
match array.get(i) {
Ok(v) => assert_eq!(v, val),
Err(e) => panic!("array.get() failed: {}", e),
}
}
}
}