forked from Jouzo/vsdb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.rs
114 lines (104 loc) · 3.05 KB
/
test.rs
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use super::{Mapx, ValueEnDe};
use ruc::*;
#[test]
fn test_insert() {
let mut hdr: Mapx<usize, usize> = Mapx::new();
let max = 100;
(0..max)
.map(|i: usize| (i, (max + i)))
.for_each(|(key, value)| {
assert!(hdr.get(&key).is_none());
hdr.set_value(&key, &value);
assert!(hdr.insert(&key, &value).is_some());
assert!(hdr.contains_key(&key));
assert_eq!(pnk!(hdr.get(&key)), value);
assert_eq!(pnk!(hdr.remove(&key)), value);
assert!(hdr.get(&key).is_none());
});
hdr.clear();
(0..max).map(|i: usize| i).for_each(|key| {
assert!(hdr.get(&key).is_none());
});
assert!(hdr.is_empty());
}
#[test]
fn test_len() {
let mut hdr: Mapx<usize, usize> = Mapx::new();
let max = 100;
(0..max)
.map(|i: usize| (i, (max + i)))
.for_each(|(key, value)| {
assert!(hdr.insert(&key, &value).is_none());
});
assert_eq!(100, hdr.len());
for key in 0..max {
assert!(hdr.remove(&key).is_some());
}
assert_eq!(0, hdr.len());
}
#[test]
fn xx_test_valueende() {
let cnt = 100;
let dehdr = {
let mut hdr: Mapx<usize, usize> = Mapx::new();
(0..cnt).map(|i: usize| (i, i)).for_each(|(key, value)| {
assert!(hdr.insert(&key, &value).is_none());
});
hdr.encode()
};
let mut reloaded = pnk!(<Mapx<usize, usize> as ValueEnDe>::decode(&dehdr));
assert_eq!(cnt, reloaded.len());
(0..cnt).map(|i: usize| i).for_each(|i| {
assert_eq!(i, reloaded.get(&i).unwrap());
});
}
#[test]
fn test_iter() {
let mut hdr: Mapx<usize, usize> = Mapx::new();
let max = 100;
(0..max).map(|i: usize| (i, i)).for_each(|(key, value)| {
assert!(hdr.insert(&key, &value).is_none());
});
for (key, value) in hdr.iter().collect::<Vec<_>>().into_iter() {
assert_eq!(key, value);
hdr.unset_value(&key);
}
assert_eq!(0, hdr.len());
}
#[test]
fn test_first_last() {
let mut hdr: Mapx<usize, usize> = Mapx::new();
let max = 100;
(0..max).map(|i: usize| (i, i)).for_each(|(key, value)| {
assert!(hdr.insert(&key, &value).is_none());
});
let (key, value) = pnk!(hdr.iter().next());
assert_eq!(key, value);
assert_eq!(0, key);
let (key, value) = pnk!(hdr.iter().next_back());
assert_eq!(key, value);
assert_eq!(max - 1, key);
}
#[test]
fn test_values() {
let mut hdr: Mapx<usize, usize> = Mapx::new();
let max = 100usize;
(0..max).map(|i| (i, i)).for_each(|(key, value)| {
assert!(hdr.insert(&key, &value).is_none());
});
for (k, v) in hdr.iter() {
assert_eq!(k, v);
}
}
#[test]
fn test_values_first_last() {
let mut hdr: Mapx<usize, usize> = Mapx::new();
let max = 100;
(0..max).map(|i: usize| (i, i)).for_each(|(key, value)| {
assert!(hdr.insert(&key, &value).is_none());
});
let value = pnk!(hdr.values().next());
assert_eq!(0, value);
let value = pnk!(hdr.values().next_back());
assert_eq!(max - 1, value);
}