]> git.lizzy.rs Git - rust.git/blob - src/librustc_data_structures/binary_search_util/test.rs
d74febb5c0fc4a13e2530de71982520e3a944fcf
[rust.git] / src / librustc_data_structures / binary_search_util / test.rs
1 use super::*;
2
3 type Element = (usize, &'static str);
4
5 fn test_map() -> Vec<Element> {
6     let mut data = vec![(3, "three-a"), (0, "zero"), (3, "three-b"), (22, "twenty-two")];
7     data.sort_by_key(get_key);
8     data
9 }
10
11 fn get_key(data: &Element) -> usize {
12     data.0
13 }
14
15 #[test]
16 fn binary_search_slice_test() {
17     let map = test_map();
18     assert_eq!(binary_search_slice(&map, get_key, &0), &[(0, "zero")]);
19     assert_eq!(binary_search_slice(&map, get_key, &1), &[]);
20     assert_eq!(binary_search_slice(&map, get_key, &3), &[(3, "three-a"), (3, "three-b")]);
21     assert_eq!(binary_search_slice(&map, get_key, &22), &[(22, "twenty-two")]);
22     assert_eq!(binary_search_slice(&map, get_key, &23), &[]);
23 }