Fix a bug with cut_range_bounds returning invalid RangeBounds

This commit is contained in:
ripytide 2023-01-05 13:30:18 +00:00
parent 9e48363cc1
commit c80c4459fb
No known key found for this signature in database
GPG Key ID: B2629F9EC7C2FE8C
3 changed files with 38 additions and 3 deletions

2
Cargo.lock generated
View File

@ -108,7 +108,7 @@ dependencies = [
[[package]]
name = "range_bounds_map"
version = "0.1.0"
version = "0.1.1"
dependencies = [
"either",
"itertools",

View File

@ -1,6 +1,6 @@
[package]
name = "range_bounds_map"
version = "0.1.0"
version = "0.1.1"
authors = ["James Forster <james.forsterer@gmail.com>"]
edition = "2021"
description = """

View File

@ -1952,7 +1952,18 @@ where
}
}
return result;
//only return valid range_bounds
return CutResult {
before_cut: result
.before_cut
.filter(|x| is_valid_range_bounds::<(Bound<&I>, Bound<&I>), I>(x)),
inside_cut: result
.inside_cut
.filter(|x| is_valid_range_bounds::<(Bound<&I>, Bound<&I>), I>(x)),
after_cut: result
.after_cut
.filter(|x| is_valid_range_bounds::<(Bound<&I>, Bound<&I>), I>(x)),
};
}
#[trivial]
@ -2932,6 +2943,30 @@ mod tests {
None => false,
}
}
#[test]
fn cut_range_bounds_should_return_valid_ranges() {
let result = cut_range_bounds(&(3..8), &(5..8));
if let Some(x) = result.before_cut {
assert!(is_valid_range_bounds(&cloned_bounds(x)));
}
if let Some(x) = result.inside_cut {
assert!(is_valid_range_bounds(&cloned_bounds(x)));
}
if let Some(x) = result.after_cut {
assert!(is_valid_range_bounds(&cloned_bounds(x)));
}
let result = cut_range_bounds(&(3..8), &(3..5));
if let Some(x) = result.before_cut {
assert!(is_valid_range_bounds(&cloned_bounds(x)));
}
if let Some(x) = result.inside_cut {
assert!(is_valid_range_bounds(&cloned_bounds(x)));
}
if let Some(x) = result.after_cut {
assert!(is_valid_range_bounds(&cloned_bounds(x)));
}
}
#[test]
fn touches_tests() {