added partialord tests for StartBound and finished overlapping test
This commit is contained in:
parent
9254e32b09
commit
5706f65ea3
@ -6,7 +6,7 @@ pub enum StartBound<T> {
|
||||
Included(T),
|
||||
Excluded(T),
|
||||
Unbounded,
|
||||
//a workaround type used only for allowing bounded-unbounded range searches
|
||||
//a workaround type used only for allowing end-unbounded range searches
|
||||
//in overlapping()
|
||||
ReverseUnbounded,
|
||||
}
|
||||
@ -108,3 +108,55 @@ impl<T> From<StartBound<T>> for Bound<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[test]
|
||||
fn mass_start_bound_partial_ord_test() {
|
||||
assert!(StartBound::Included(2) == StartBound::Included(2));
|
||||
assert!(StartBound::Included(2) <= StartBound::Included(2));
|
||||
assert!(StartBound::Included(2) >= StartBound::Included(2));
|
||||
assert!(StartBound::Included(0) < StartBound::Included(2));
|
||||
assert!(StartBound::Included(2) > StartBound::Included(0));
|
||||
|
||||
assert!(StartBound::Included(2) < StartBound::Excluded(2));
|
||||
assert!(StartBound::Included(0) < StartBound::Excluded(2));
|
||||
assert!(StartBound::Included(2) > StartBound::Excluded(0));
|
||||
|
||||
assert!(StartBound::Excluded(2) > StartBound::Included(2));
|
||||
assert!(StartBound::Excluded(2) > StartBound::Included(0));
|
||||
assert!(StartBound::Excluded(0) < StartBound::Included(2));
|
||||
|
||||
assert!(StartBound::Excluded(2) == StartBound::Excluded(2));
|
||||
assert!(StartBound::Excluded(2) <= StartBound::Excluded(2));
|
||||
assert!(StartBound::Excluded(2) >= StartBound::Excluded(2));
|
||||
assert!(StartBound::Excluded(0) < StartBound::Excluded(2));
|
||||
assert!(StartBound::Excluded(2) > StartBound::Excluded(0));
|
||||
|
||||
assert!(StartBound::Included(2) > StartBound::Unbounded);
|
||||
assert!(StartBound::Excluded(2) > StartBound::Unbounded);
|
||||
|
||||
assert!(StartBound::Unbounded < StartBound::Included(2));
|
||||
assert!(StartBound::Unbounded < StartBound::Excluded(2));
|
||||
|
||||
assert!(StartBound::Included(2) < StartBound::ReverseUnbounded);
|
||||
assert!(StartBound::Excluded(2) < StartBound::ReverseUnbounded);
|
||||
|
||||
assert!(StartBound::ReverseUnbounded > StartBound::Included(2));
|
||||
assert!(StartBound::ReverseUnbounded > StartBound::Excluded(2));
|
||||
|
||||
assert!(StartBound::Unbounded::<u8> == StartBound::Unbounded);
|
||||
assert!(StartBound::Unbounded::<u8> <= StartBound::Unbounded);
|
||||
assert!(StartBound::Unbounded::<u8> >= StartBound::Unbounded);
|
||||
|
||||
assert!(StartBound::ReverseUnbounded::<u8> == StartBound::ReverseUnbounded);
|
||||
assert!(StartBound::ReverseUnbounded::<u8> <= StartBound::ReverseUnbounded);
|
||||
assert!(StartBound::ReverseUnbounded::<u8> >= StartBound::ReverseUnbounded);
|
||||
|
||||
assert!(StartBound::Unbounded::<u8> < StartBound::ReverseUnbounded);
|
||||
assert!(StartBound::ReverseUnbounded::<u8> > StartBound::Unbounded);
|
||||
}
|
||||
}
|
||||
|
@ -134,57 +134,90 @@ mod tests {
|
||||
//if that works everything is likely to work so there are only
|
||||
//tests for overlapping()
|
||||
|
||||
use crate::range_bounds_ext::RangeBoundsExt;
|
||||
use crate::test_helpers::{all_valid_test_bounds, TestBounds};
|
||||
use crate::RangeBoundsMap;
|
||||
use crate::RangeBoundsSet;
|
||||
|
||||
//fn mass_overlapping_test() {
|
||||
////case zero
|
||||
//for overlap_range in all_valid_test_bounds() {
|
||||
//RangeBoundsMap::new().o
|
||||
//}
|
||||
#[test]
|
||||
fn mass_overlapping_test() {
|
||||
//case zero
|
||||
for overlap_range in all_valid_test_bounds() {
|
||||
//you can't overlap nothing
|
||||
assert!(
|
||||
RangeBoundsSet::new()
|
||||
.overlapping(&overlap_range)
|
||||
.next()
|
||||
.is_none()
|
||||
);
|
||||
}
|
||||
|
||||
////case one
|
||||
//for overlap_range in all_valid_test_bounds() {
|
||||
//for inside_range in all_valid_test_bounds() {
|
||||
//let mut range_bounds_set = Vec::new();
|
||||
//range_bounds_set.push(inside_range);
|
||||
//output.push(OverlappingTestCase {
|
||||
//range_bounds_set,
|
||||
//overlap_range,
|
||||
//})
|
||||
//}
|
||||
//}
|
||||
//case one
|
||||
for overlap_range in all_valid_test_bounds() {
|
||||
for inside_range in all_valid_test_bounds() {
|
||||
let mut range_bounds_set = RangeBoundsSet::new();
|
||||
range_bounds_set.insert(inside_range).unwrap();
|
||||
|
||||
////case two
|
||||
//for overlap_range in all_valid_test_bounds() {
|
||||
//for (test_bounds1, test_bounds2) in
|
||||
//all_non_overlapping_test_bound_pairs()
|
||||
//{
|
||||
//let mut range_bounds_set = Vec::new();
|
||||
//range_bounds_set.push(test_bounds1);
|
||||
//range_bounds_set.push(test_bounds2);
|
||||
//output.push(OverlappingTestCase {
|
||||
//range_bounds_set,
|
||||
//overlap_range,
|
||||
//})
|
||||
//}
|
||||
//}
|
||||
let expected_answer = overlap_range.overlaps(&inside_range);
|
||||
let answer = range_bounds_set
|
||||
.overlapping(&overlap_range)
|
||||
.next()
|
||||
.is_some_and(|overlapped_range| {
|
||||
*overlapped_range == inside_range
|
||||
});
|
||||
|
||||
//return output;
|
||||
//}
|
||||
if answer != expected_answer {
|
||||
dbg!(overlap_range, inside_range);
|
||||
dbg!(answer, expected_answer);
|
||||
panic!(
|
||||
"Discrepency in .overlapping() with single inside range detected!"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//fn all_non_overlapping_test_bound_pairs() -> Vec<(TestBounds, TestBounds)> {
|
||||
//let mut output = Vec::new();
|
||||
//for test_bounds1 in all_valid_test_bounds() {
|
||||
//for test_bounds2 in all_valid_test_bounds() {
|
||||
//if !GenericRange::from(test_bounds1)
|
||||
//.is_overlapping(&GenericRange::from(test_bounds2))
|
||||
//{
|
||||
//output.push((test_bounds1, test_bounds2));
|
||||
//}
|
||||
//}
|
||||
//}
|
||||
//case two
|
||||
for overlap_range in all_valid_test_bounds() {
|
||||
for (inside_range1, inside_range2) in
|
||||
all_non_overlapping_test_bound_pairs()
|
||||
{
|
||||
let mut range_bounds_set = RangeBoundsSet::new();
|
||||
range_bounds_set.insert(inside_range1).unwrap();
|
||||
range_bounds_set.insert(inside_range2).unwrap();
|
||||
|
||||
//return output;
|
||||
//}
|
||||
let mut expected_overlapping = Vec::new();
|
||||
if overlap_range.overlaps(&inside_range1) {
|
||||
expected_overlapping.push(inside_range1);
|
||||
}
|
||||
if overlap_range.overlaps(&inside_range2) {
|
||||
expected_overlapping.push(inside_range2);
|
||||
}
|
||||
|
||||
let overlapping = range_bounds_set
|
||||
.overlapping(&overlap_range)
|
||||
.copied()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if overlapping != expected_overlapping {
|
||||
dbg!(overlap_range, inside_range1, inside_range2);
|
||||
dbg!(overlapping, expected_overlapping);
|
||||
panic!(
|
||||
"Discrepency in .overlapping() with two inside ranges detected!"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn all_non_overlapping_test_bound_pairs() -> Vec<(TestBounds, TestBounds)> {
|
||||
let mut output = Vec::new();
|
||||
for test_bounds1 in all_valid_test_bounds() {
|
||||
for test_bounds2 in all_valid_test_bounds() {
|
||||
if !test_bounds1.overlaps(&test_bounds2) {
|
||||
output.push((test_bounds1, test_bounds2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,8 @@ pub fn all_valid_test_bounds() -> Vec<TestBounds> {
|
||||
return output;
|
||||
}
|
||||
|
||||
//only every other number to allow mathematical_overlapping_definition
|
||||
//to test between bounds in finite using smaller intervalled finite
|
||||
pub const NUMBERS: &'static [u8] = &[2, 4, 6, 8, 10];
|
||||
//go a bit around on either side to compensate for Unbounded
|
||||
pub const NUMBERS_DOMAIN: &'static [u8] =
|
||||
|
Loading…
x
Reference in New Issue
Block a user