Lines Matching full:cache
5 let mut cache = LruCache::new(2); in test_put_and_get() localVariable
6 cache.insert(1, 10); in test_put_and_get()
7 cache.insert(2, 20); in test_put_and_get()
8 assert_eq!(cache.get_mut(&1), Some(&mut 10)); in test_put_and_get()
9 assert_eq!(cache.get_mut(&2), Some(&mut 20)); in test_put_and_get()
10 assert_eq!(cache.len(), 2); in test_put_and_get()
15 let mut cache = LruCache::new(1); in test_put_update() localVariable
16 cache.insert("1", 10); in test_put_update()
17 cache.insert("1", 19); in test_put_update()
18 assert_eq!(cache.get_mut("1"), Some(&mut 19)); in test_put_update()
19 assert_eq!(cache.len(), 1); in test_put_update()
24 let mut cache = LruCache::new(1); in test_contains_key() localVariable
25 cache.insert("1", 10); in test_contains_key()
26 assert_eq!(cache.contains_key("1"), true); in test_contains_key()
31 let mut cache = LruCache::new(2); in test_expire_lru() localVariable
32 cache.insert("foo1", "bar1"); in test_expire_lru()
33 cache.insert("foo2", "bar2"); in test_expire_lru()
34 cache.insert("foo3", "bar3"); in test_expire_lru()
35 assert!(cache.get_mut("foo1").is_none()); in test_expire_lru()
36 cache.insert("foo2", "bar2update"); in test_expire_lru()
37 cache.insert("foo4", "bar4"); in test_expire_lru()
38 assert!(cache.get_mut("foo3").is_none()); in test_expire_lru()
43 let mut cache = LruCache::new(2); in test_pop() localVariable
44 cache.insert(1, 10); in test_pop()
45 cache.insert(2, 20); in test_pop()
46 assert_eq!(cache.len(), 2); in test_pop()
47 let opt1 = cache.remove(&1); in test_pop()
50 assert!(cache.get_mut(&1).is_none()); in test_pop()
51 assert_eq!(cache.len(), 1); in test_pop()
56 let mut cache = LruCache::new(2); in test_change_capacity() localVariable
57 assert_eq!(cache.capacity(), 2); in test_change_capacity()
58 cache.insert(1, 10); in test_change_capacity()
59 cache.insert(2, 20); in test_change_capacity()
60 cache.set_capacity(1); in test_change_capacity()
61 assert!(cache.get_mut(&1).is_none()); in test_change_capacity()
62 assert_eq!(cache.capacity(), 1); in test_change_capacity()
67 let mut cache = LruCache::new(3); in test_remove() localVariable
68 cache.insert(1, 10); in test_remove()
69 cache.insert(2, 20); in test_remove()
70 cache.insert(3, 30); in test_remove()
71 cache.insert(4, 40); in test_remove()
72 cache.insert(5, 50); in test_remove()
73 cache.remove(&3); in test_remove()
74 cache.remove(&4); in test_remove()
75 assert!(cache.get_mut(&3).is_none()); in test_remove()
76 assert!(cache.get_mut(&4).is_none()); in test_remove()
77 cache.insert(6, 60); in test_remove()
78 cache.insert(7, 70); in test_remove()
79 cache.insert(8, 80); in test_remove()
80 assert!(cache.get_mut(&5).is_none()); in test_remove()
81 assert_eq!(cache.get_mut(&6), Some(&mut 60)); in test_remove()
82 assert_eq!(cache.get_mut(&7), Some(&mut 70)); in test_remove()
83 assert_eq!(cache.get_mut(&8), Some(&mut 80)); in test_remove()
88 let mut cache = LruCache::new(2); in test_clear() localVariable
89 cache.insert(1, 10); in test_clear()
90 cache.insert(2, 20); in test_clear()
91 cache.clear(); in test_clear()
92 assert!(cache.get_mut(&1).is_none()); in test_clear()
93 assert!(cache.get_mut(&2).is_none()); in test_clear()
94 assert!(cache.is_empty()) in test_clear()
99 let mut cache = LruCache::new(3); in test_iter() localVariable
100 cache.insert(1, 10); in test_iter()
101 cache.insert(2, 20); in test_iter()
102 cache.insert(3, 30); in test_iter()
103 cache.insert(4, 40); in test_iter()
104 cache.insert(5, 50); in test_iter()
106 cache.iter().collect::<Vec<_>>(), in test_iter()
110 cache.iter_mut().collect::<Vec<_>>(), in test_iter()
114 cache.iter().rev().collect::<Vec<_>>(), in test_iter()
118 cache.iter_mut().rev().collect::<Vec<_>>(), in test_iter()
125 let mut cache = LruCache::new_unbounded(); in test_peek() localVariable
126 cache.insert(1, 10); in test_peek()
127 cache.insert(2, 20); in test_peek()
128 cache.insert(3, 30); in test_peek()
129 cache.insert(4, 40); in test_peek()
130 cache.insert(5, 50); in test_peek()
131 cache.insert(6, 60); in test_peek()
133 assert_eq!(cache.remove_lru(), Some((1, 10))); in test_peek()
134 assert_eq!(cache.peek(&2), Some(&20)); in test_peek()
135 assert_eq!(cache.remove_lru(), Some((2, 20))); in test_peek()
136 assert_eq!(cache.peek_mut(&3), Some(&mut 30)); in test_peek()
137 assert_eq!(cache.remove_lru(), Some((3, 30))); in test_peek()
138 assert_eq!(cache.get(&4), Some(&40)); in test_peek()
139 assert_eq!(cache.remove_lru(), Some((5, 50))); in test_peek()
144 let mut cache = LruCache::new(4); in test_entry() localVariable
146 cache.insert(1, 10); in test_entry()
147 cache.insert(2, 20); in test_entry()
148 cache.insert(3, 30); in test_entry()
149 cache.insert(4, 40); in test_entry()
150 cache.insert(5, 50); in test_entry()
151 cache.insert(6, 60); in test_entry()
153 assert_eq!(cache.len(), 4); in test_entry()
155 cache.entry(7).or_insert(70); in test_entry()
156 cache.entry(8).or_insert(80); in test_entry()
157 cache.entry(9).or_insert(90); in test_entry()
159 assert!(cache.len() <= 5); in test_entry()
161 cache.raw_entry_mut().from_key(&10).or_insert(10, 100); in test_entry()
162 cache.raw_entry_mut().from_key(&11).or_insert(11, 110); in test_entry()
163 cache.raw_entry_mut().from_key(&12).or_insert(12, 120); in test_entry()
165 assert!(cache.len() <= 5); in test_entry()