binary_search_tree: add additional doctest for search_binary_tree_by()

Make sure a start indexes larger or equal to the array size results in a return
value of `None`.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
This commit is contained in:
Christian Ebner 2019-12-17 15:01:21 +01:00 committed by Dietmar Maurer
parent 48f6d67764
commit ebfb2df22b
1 changed files with 12 additions and 0 deletions

View File

@ -132,6 +132,18 @@ pub fn copy_binary_search_tree<F: FnMut(usize, usize)>(
/// let skip_multiples = 1; /// let skip_multiples = 1;
/// let idx = search_binary_tree_by(0, vals.len(), skip_multiples, |idx| find.cmp(&vals[idx])); /// let idx = search_binary_tree_by(0, vals.len(), skip_multiples, |idx| find.cmp(&vals[idx]));
/// assert!(idx.is_none()); /// assert!(idx.is_none());
///
/// let find = 5;
/// let skip_multiples = 0;
/// // if start index is equal to the array length, `None` is returned.
/// let idx = search_binary_tree_by(vals.len(), vals.len(), skip_multiples, |idx| find.cmp(&vals[idx]));
/// assert!(idx.is_none());
///
/// let find = 5;
/// let skip_multiples = 0;
/// // if start index is larger than length, `None` is returned.
/// let idx = search_binary_tree_by(vals.len() + 1, vals.len(), skip_multiples, |idx| find.cmp(&vals[idx]));
/// assert!(idx.is_none());
/// ``` /// ```
pub fn search_binary_tree_by<F: Copy + Fn(usize) -> Ordering>( pub fn search_binary_tree_by<F: Copy + Fn(usize) -> Ordering>(