Fix failing test

This commit is contained in:
Kay Simmons 2023-02-17 22:00:39 -08:00
parent 5e4d113308
commit fc811d14b1
4 changed files with 52 additions and 26 deletions

View file

@ -3,16 +3,17 @@ pub mod paths;
#[cfg(any(test, feature = "test-support"))]
pub mod test;
pub use backtrace::Backtrace;
use futures::Future;
use rand::{seq::SliceRandom, Rng};
use std::{
cmp::Ordering,
ops::AddAssign,
cmp::{self, Ordering},
ops::{AddAssign, Range, RangeInclusive},
pin::Pin,
task::{Context, Poll},
};
pub use backtrace::Backtrace;
use futures::Future;
use rand::{seq::SliceRandom, Rng};
#[derive(Debug, Default)]
pub struct StaffMode(pub bool);
@ -245,6 +246,46 @@ macro_rules! async_iife {
};
}
pub trait RangeExt<T> {
fn sorted(&self) -> Self;
fn to_inclusive(&self) -> RangeInclusive<T>;
fn overlaps(&self, other: &Range<T>) -> bool;
}
impl<T: Ord + Clone> RangeExt<T> for Range<T> {
fn sorted(&self) -> Self {
cmp::min(&self.start, &self.end).clone()..cmp::max(&self.start, &self.end).clone()
}
fn to_inclusive(&self) -> RangeInclusive<T> {
self.start.clone()..=self.end.clone()
}
fn overlaps(&self, other: &Range<T>) -> bool {
self.contains(&other.start)
|| self.contains(&other.end)
|| other.contains(&self.start)
|| other.contains(&self.end)
}
}
impl<T: Ord + Clone> RangeExt<T> for RangeInclusive<T> {
fn sorted(&self) -> Self {
cmp::min(self.start(), self.end()).clone()..=cmp::max(self.start(), self.end()).clone()
}
fn to_inclusive(&self) -> RangeInclusive<T> {
self.clone()
}
fn overlaps(&self, other: &Range<T>) -> bool {
self.contains(&other.start)
|| self.contains(&other.end)
|| other.contains(&self.start())
|| other.contains(&self.end())
}
}
#[cfg(test)]
mod tests {
use super::*;