MCPcopy Index your code
hub / github.com/douchuan/algorithm / tst

Function tst

tests/test_strings.rs:177–234  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

175
176#[test]
177fn tst() {
178 let mut st = TST::default();
179 // test len & empty
180 assert!(st.is_empty());
181 assert_eq!(0, st.len());
182
183 let i = SHELLS_ST;
184 let mut hm = HashMap::new();
185 let a = extract_words(i);
186 for (i, &s) in a.iter().enumerate() {
187 hm.insert(s, i);
188 // test put
189 st.put(s, Some(i));
190 }
191
192 // test len & empty
193 assert!(!st.is_empty());
194 assert_eq!(7, st.len());
195
196 for (&k, v) in hm.iter() {
197 // test get & contains
198 assert_eq!(st.get(k), Some(v));
199 assert!(st.contains(k));
200 }
201
202 // test keys
203 // TST keys contained in HashMap
204 let keys = st.keys();
205 assert_eq!(hm.keys().len(), keys.len());
206 for k in keys.iter() {
207 assert!(hm.contains_key(k.as_str()));
208 }
209 // HashMap keys contained in TST
210 let keys = hm.keys();
211 for &k in keys {
212 assert!(st.contains(k));
213 }
214
215 // test keys_with_prefix
216 let mut matches = st.keys_with_prefix("shor");
217 assert_eq!(1, matches.len());
218 assert_eq!(Some("shore"), matches.dequeue().as_deref());
219
220 // test keys_that_match
221 let mut matches = st.keys_that_match(".he.l.");
222 assert_eq!(Some("shells"), matches.dequeue().as_deref());
223
224 // test longest_prefix_of
225 assert_eq!(Some("shells"), st.longest_prefix_of("shellsort"));
226 assert_eq!(Some("she"), st.longest_prefix_of("shell"));
227 assert_eq!(None, st.longest_prefix_of("quicksort"));
228
229 // test delete
230 assert!(st.contains("shells"));
231 st.put("shells", None);
232 assert_eq!(6, st.len());
233 assert!(!st.contains("shells"));
234}

Callers

nothing calls this directly

Calls 7

extract_wordsFunction · 0.70
iterMethod · 0.45
insertMethod · 0.45
putMethod · 0.45
keysMethod · 0.45
keys_with_prefixMethod · 0.45
keys_that_matchMethod · 0.45

Tested by

no test coverage detected