From 354bef2f9383433a381a973dac03785498906244 Mon Sep 17 00:00:00 2001 From: Brent Pedersen Date: Mon, 22 Jan 2024 10:34:09 +0100 Subject: [PATCH] clippy and intersection.report inverse tests --- src/intersections.rs | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/intersections.rs b/src/intersections.rs index 1de91e4..3762c31 100644 --- a/src/intersections.rs +++ b/src/intersections.rs @@ -211,8 +211,8 @@ impl Intersections { } } } - if a_mode.contains(IntersectionMode::Not) && self.overlapping.len() == 0 { - self.push_overlap_fragments(&mut result, &vec![], a_part, b_part, usize::MAX); + if a_mode.contains(IntersectionMode::Not) && self.overlapping.is_empty() { + self.push_overlap_fragments(&mut result, &[], a_part, b_part, usize::MAX); } Report::new(result) @@ -494,6 +494,44 @@ mod tests { eprintln!("{:?}", r); } + #[test] + fn test_a_not() { + let intersections = make_example("a: 1-10\nb: 3-4, 6-7, 8-12\nb:9-20"); + let r = intersections.report( + &IntersectionMode::Not, + &IntersectionMode::Default, + &IntersectionPart::Whole, + &IntersectionPart::Whole, + &OverlapAmount::Bases(1), + &OverlapAmount::Bases(1), + ); + assert!(r.len() == 0); + let r = intersections.report( + &IntersectionMode::Not, + &IntersectionMode::Default, + &IntersectionPart::Whole, + &IntersectionPart::Whole, + &OverlapAmount::Bases(6), + &OverlapAmount::Bases(1), + ); + assert_eq!(r.len(), 2); + } + + #[test] + fn test_a_not_with_empty() { + let intersections = make_example("a: 1-10"); + let r = intersections.report( + &IntersectionMode::Not, + &IntersectionMode::Default, + &IntersectionPart::Whole, + &IntersectionPart::Whole, + &OverlapAmount::Bases(1), + &OverlapAmount::Bases(1), + ); + assert_eq!(1, r.len()); + assert_eq!(r[0].id, usize::MAX); + } + #[test] fn test_b_inverse() { let intersections = make_example("a: 1-10\nb: 3-4, 6-7, 8-12\nb:9-20");