]> git.proxmox.com Git - rustc.git/blob - compiler/rustc_data_structures/src/binary_search_util/tests.rs
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / compiler / rustc_data_structures / src / binary_search_util / tests.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 }