Add doctest example

This commit is contained in:
Timothy Warren 2019-03-06 11:43:38 -05:00
parent ab1c58ad9b
commit b428ce3d10
3 changed files with 31 additions and 1 deletions

View File

@ -80,7 +80,7 @@ fn test_parse_complex() {
/// ///
/// `bounds` is a pair giving the width and height of the image in pixels. /// `bounds` is a pair giving the width and height of the image in pixels.
/// `pixel` is a (column, row) pair indicating a particular pixel in that image. /// `pixel` is a (column, row) pair indicating a particular pixel in that image.
/// The `upper_left` and `lower_right` parameters are pionts on the complex /// The `upper_left` and `lower_right` parameters are points on the complex
/// plain designating the area our image covers /// plain designating the area our image covers
fn pixel_to_point( fn pixel_to_point(
bounds: (usize, usize), bounds: (usize, usize),

7
ranges/Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[package]
name = "ranges"
version = "0.1.0"
authors = ["Timothy Warren <twarren@nabancard.com>"]
edition = "2018"
[dependencies]

23
ranges/src/lib.rs Normal file
View File

@ -0,0 +1,23 @@
use std::ops::Range;
/// Return true if two ranges overlap
///
/// assert_eq!(ranges::overlap(0..7, 3..10), true);
/// assert_eq!(ranges::overlap(1..5, 101..105), false);
///
/// If either range is empty, they don't count as overlapping.
///
/// assert_eq!(ranges::overlap(0..0, 0..10), false);
///
pub fn overlap(r1: Range<usize>, r2: Range<usize>) -> bool {
r1.start < r1.end && r2.start < r2.end &&
r1.start < r2.end && r2.start < r1.end
}
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
}