added final test and passing for touches()

This commit is contained in:
ripytide
2022-12-07 18:54:44 +00:00
parent bc8e0791ed
commit 87ed4ad4e3
+29 -3
View File
@@ -25,7 +25,7 @@ use std::ops::{Bound, RangeBounds};
use either::Either;
use itertools::Itertools;
use labels::{tested, trivial, untested};
use labels::{tested, trivial};
use serde::{Deserialize, Serialize};
use crate::bounds::StartBound;
@@ -1340,7 +1340,7 @@ where
}
}
#[untested]
#[tested]
fn touches<I, A, B>(a: &A, b: &B) -> bool
where
A: RangeBounds<I>,
@@ -1797,7 +1797,7 @@ mod tests {
if our_answer != mathematical_definition_of_overlap {
dbg!(range_bounds1, range_bounds2);
dbg!(mathematical_definition_of_overlap, our_answer);
panic!("Discrepency in .overlaps() detected!");
panic!("Discrepency in overlaps() detected!");
}
}
}
@@ -1851,6 +1851,32 @@ mod tests {
}
}
#[test]
fn touches_tests() {
for range_bounds1 in all_valid_test_bounds() {
for range_bounds2 in all_valid_test_bounds() {
let our_answer = touches(&range_bounds1, &range_bounds2);
let mathematical_definition_of_touches =
NUMBERS_DOMAIN.iter().tuple_windows().any(|(x1, x2)| {
(range_bounds1.contains(x1)
&& !range_bounds1.contains(x2)
&& range_bounds2.contains(x2)
&& !range_bounds2.contains(x1))
|| (range_bounds1.contains(x2)
&& !range_bounds1.contains(x1) && range_bounds2
.contains(x1) && !range_bounds2.contains(x2))
});
if our_answer != mathematical_definition_of_touches {
dbg!(range_bounds1, range_bounds2);
dbg!(mathematical_definition_of_touches, our_answer);
panic!("Discrepency in touches() detected!");
}
}
}
}
// Test Helper Functions
//======================
fn all_non_overlapping_test_bound_pairs() -> Vec<(TestBounds, TestBounds)> {