mass_overlaps_tests pass whooo

This commit is contained in:
ripytide
2022-11-25 20:11:28 +00:00
parent cdff3041d5
commit 9254e32b09
4 changed files with 56 additions and 60 deletions
-1
View File
@@ -9,5 +9,4 @@ edition = "2021"
either = "1.8.0"
[dev-dependencies]
ranges = "0.3.3"
pretty_assertions = "1.3.0"
+9 -14
View File
@@ -147,10 +147,9 @@ where
#[cfg(test)]
mod tests {
use ranges::GenericRange;
use super::*;
use crate::test_helpers::all_valid_test_bounds;
use crate::test_helpers::{all_valid_test_bounds, NUMBERS_DOMAIN};
//we test our function against GenericRange's is_overlapping()
//which we trust cuz y not lel
@@ -158,22 +157,18 @@ mod tests {
fn mass_overlaps_test() {
for range_bounds1 in all_valid_test_bounds() {
for range_bounds2 in all_valid_test_bounds() {
let mut trusted_answer = GenericRange::from(range_bounds1)
.is_overlapping(&GenericRange::from(range_bounds2));
let our_answer = range_bounds1.overlaps(&range_bounds2);
//the only thing the "trusted" answer get wrong --__--
if let (Bound::Included(start1), Bound::Included(end1)) = range_bounds1 &&
let (Bound::Included(start2), Bound::Included(end2)) = range_bounds2 &&
(start1 == end1) && (start2 == end2) && (end1 == start2)
{
trusted_answer = true;
}
//since we are using discrete numbers this is indeed
//the mathematical_definition_of_overlap
let mathematical_definition_of_overlap =
NUMBERS_DOMAIN.iter().any(|x| {
range_bounds1.contains(x) && range_bounds2.contains(x)
});
if our_answer != trusted_answer {
if our_answer != mathematical_definition_of_overlap {
dbg!(range_bounds1, range_bounds2);
dbg!(trusted_answer, our_answer);
dbg!(mathematical_definition_of_overlap, our_answer);
panic!("Discrepency in .overlaps() detected!");
}
}
+43 -44
View File
@@ -134,58 +134,57 @@ mod tests {
//if that works everything is likely to work so there are only
//tests for overlapping()
use ranges::GenericRange;
use crate::{test_helpers::{all_valid_test_bounds, TestBounds}, RangeBoundsMap};
use crate::test_helpers::{all_valid_test_bounds, TestBounds};
use crate::RangeBoundsMap;
//fn mass_overlapping_test() {
////case zero
//for overlap_range in all_valid_test_bounds() {
//RangeBoundsMap::new().o
//}
////case zero
//for overlap_range in all_valid_test_bounds() {
//RangeBoundsMap::new().o
//}
////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 = Vec::new();
//range_bounds_set.push(inside_range);
//output.push(OverlappingTestCase {
//range_bounds_set,
//overlap_range,
//})
//}
//}
////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,
//})
//}
//}
////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,
//})
//}
//}
//return output;
//return output;
//}
//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));
//}
//}
//}
//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));
//}
//}
//}
//return output;
//return output;
//}
}
+4 -1
View File
@@ -21,7 +21,10 @@ pub fn all_valid_test_bounds() -> Vec<TestBounds> {
return output;
}
const NUMBERS: &'static [u8] = &[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20];
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] =
&[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
fn all_finite_bounded_pairs() -> Vec<(Bound<u8>, Bound<u8>)> {
let mut output = Vec::new();