MCPcopy Create free account
hub / github.com/douchuan/algorithm / binary_search

Function binary_search

tests/test_search.rs:4–18  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2
3#[test]
4fn binary_search() {
5 //empty array
6 assert_eq!(search::binary::search(&[], 0), None);
7
8 let xs = vec![1, 2, 3, 4, 5, 6, 7, 8];
9 for (v, p) in vec![
10 (1, Some(0)),
11 (4, Some(3)),
12 (8, Some(7)),
13 (100, None),
14 (-1, None),
15 ] {
16 assert_eq!(search::binary::search(&xs, v), p);
17 }
18}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected