btree_range_map/
range.rs

1pub use range_traits::{Measure, PartialEnum};
2use std::{
3	cmp::PartialOrd,
4	ops::{Bound, RangeBounds},
5};
6
7mod bound;
8mod ordering;
9
10mod any;
11mod from_excluded;
12mod from_excluded_to;
13mod from_excluded_to_included;
14
15pub use any::*;
16pub use bound::*;
17pub use from_excluded::*;
18pub use from_excluded_to::*;
19pub use from_excluded_to_included::*;
20pub use ordering::*;
21
22/// Types that can be interpreted as ranges.
23pub trait AsRange: Sized {
24	/// Type of the elements of the range.
25	type Item: Measure + PartialEnum;
26
27	/// Start bound of the range.
28	fn start(&self) -> Bound<&Self::Item>;
29
30	/// End bound of the range.
31	fn end(&self) -> Bound<&Self::Item>;
32
33	fn is_empty(&self) -> bool {
34		is_range_empty(self.start(), self.end())
35	}
36
37	fn intersects<R: AsRange>(&self, other: &R) -> bool
38	where
39		Self::Item: PartialOrd<R::Item> + Measure<R::Item>,
40	{
41		matches!(
42			self.range_partial_cmp(other),
43			Some(RangeOrdering::Intersecting(_, _))
44		)
45	}
46
47	fn connected_to<R: AsRange>(&self, other: &R) -> bool
48	where
49		Self::Item: PartialOrd<R::Item> + Measure<R::Item>,
50	{
51		match self.range_partial_cmp(other) {
52			Some(RangeOrdering::Intersecting(_, _)) => true,
53			Some(RangeOrdering::Before(connected)) => connected,
54			Some(RangeOrdering::After(connected)) => connected,
55			_ => false,
56		}
57	}
58
59	fn intersected_with<'a, R: AsRange<Item = Self::Item>>(
60		&'a self,
61		other: &'a R,
62	) -> AnyRange<&'a Self::Item>
63	where
64		Self::Item: PartialOrd + Measure,
65	{
66		AnyRange {
67			start: max_bound(self.start(), other.start(), true),
68			end: min_bound(self.end(), other.end(), false),
69		}
70	}
71
72	fn without<'a, R: AsRange<Item = Self::Item>>(
73		&'a self,
74		other: &'a R,
75	) -> Difference<&'a Self::Item>
76	where
77		Self::Item: PartialOrd + Measure,
78	{
79		let left = match invert_bound(other.start()) {
80			Some(inverted_other_start) => {
81				if !is_range_empty(self.start(), inverted_other_start) {
82					Some(AnyRange {
83						start: self.start(),
84						end: inverted_other_start,
85					})
86				} else {
87					None
88				}
89			}
90			None => None,
91		};
92
93		let right = match invert_bound(other.end()) {
94			Some(inverted_other_end) => {
95				if !is_range_empty(inverted_other_end, self.end()) {
96					Some(AnyRange {
97						start: inverted_other_end,
98						end: self.end(),
99					})
100				} else {
101					None
102				}
103			}
104			None => None,
105		};
106
107		match (left, right) {
108			(Some(left), None) => Difference::Before(
109				left,
110				Directed::End(left.end) >= Directed::Start(other.start()),
111			),
112			(None, Some(right)) => Difference::After(
113				right,
114				Directed::Start(right.start) <= Directed::End(other.end()),
115			),
116			(Some(left), Some(right)) => Difference::Split(left, right),
117			(None, None) => Difference::Empty,
118		}
119	}
120
121	fn product<'a, R: AsRange<Item = Self::Item>>(&'a self, other: &'a R) -> Product<&'a Self::Item>
122	where
123		Self::Item: PartialOrd + Measure,
124	{
125		let before = match crop_right(self, other.start()) {
126			Some(self_before) => Some(ProductArg::Subject(self_before)),
127			None => crop_right(other, self.start()).map(ProductArg::Object),
128		};
129
130		let intersection = self.intersected_with(other);
131		let intersection = if is_range_empty(intersection.start, intersection.end) {
132			None
133		} else {
134			Some(intersection)
135		};
136
137		let after = match crop_left(self, other.end()) {
138			Some(self_after) => Some(ProductArg::Subject(self_after)),
139			None => crop_left(other, self.end()).map(ProductArg::Object),
140		};
141
142		Product {
143			before,
144			intersection,
145			after,
146		}
147	}
148}
149
150pub trait IntoRange: AsRange {
151	fn into_range(self) -> AnyRange<Self::Item>;
152}
153
154fn crop_left<'a, R: AsRange>(
155	range: &'a R,
156	other_end: Bound<&'a R::Item>,
157) -> Option<AnyRange<&'a R::Item>> {
158	match invert_bound(other_end) {
159		Some(inverted_other_end) => {
160			let max_start = max_bound(range.start(), inverted_other_end, true);
161			if !is_range_empty(max_start, range.end()) {
162				Some(AnyRange {
163					start: inverted_other_end,
164					end: range.end(),
165				})
166			} else {
167				None
168			}
169		}
170		None => None,
171	}
172}
173
174fn crop_right<'a, R: AsRange>(
175	range: &'a R,
176	other_start: Bound<&'a R::Item>,
177) -> Option<AnyRange<&'a R::Item>> {
178	match invert_bound(other_start) {
179		Some(inverted_other_start) => {
180			let min_end = min_bound(range.end(), inverted_other_start, false);
181			if !is_range_empty(range.start(), min_end) {
182				Some(AnyRange {
183					start: range.start(),
184					end: min_end,
185				})
186			} else {
187				None
188			}
189		}
190		None => None,
191	}
192}
193
194/// Part of the result of a `product` operation.
195pub enum ProductArg<T> {
196	/// A part of the subject, `self`.
197	Subject(AnyRange<T>),
198
199	/// A part of the object, `other`.
200	Object(AnyRange<T>),
201}
202
203impl<'a, T: Clone> ProductArg<&'a T> {
204	pub fn cloned(&self) -> ProductArg<T> {
205		match self {
206			ProductArg::Subject(range) => ProductArg::Subject(range.cloned()),
207			ProductArg::Object(range) => ProductArg::Object(range.cloned()),
208		}
209	}
210}
211
212/// Result of a `product` operation.
213pub struct Product<T> {
214	/// What is left of `self` and `other` before their intersection.
215	pub before: Option<ProductArg<T>>,
216
217	/// The intersection of `self` and `other`, if not empty.
218	pub intersection: Option<AnyRange<T>>,
219
220	/// What is left of `self` and `other` after their intersection.
221	pub after: Option<ProductArg<T>>,
222}
223
224impl<'a, T: Clone> Product<&'a T> {
225	pub fn cloned(&self) -> Product<T> {
226		Product {
227			before: self.before.as_ref().map(|r| r.cloned()),
228			intersection: self.intersection.as_ref().map(|r| r.cloned()),
229			after: self.after.as_ref().map(|r| r.cloned()),
230		}
231	}
232}
233
234pub enum RelativePosition {
235	Before,
236	After,
237}
238
239/// Result of a `without` operation.
240pub enum Difference<T> {
241	/// The end of the range may intersects `other`. The boolean is set to true if it does.
242	Before(AnyRange<T>, bool),
243
244	/// The begining of the range may intersects `other`. The boolean is set to true if it does.
245	After(AnyRange<T>, bool),
246
247	/// The `other` range if fully included.
248	Split(AnyRange<T>, AnyRange<T>),
249
250	/// The range is fully included in `other`.
251	Empty,
252}
253
254macro_rules! singleton_range {
255	($ty:ident) => {
256		impl AsRange for $ty {
257			type Item = Self;
258
259			fn start(&self) -> Bound<&Self::Item> {
260				Bound::Included(self)
261			}
262
263			fn end(&self) -> Bound<&Self::Item> {
264				Bound::Included(self)
265			}
266		}
267
268		impl IntoRange for $ty {
269			fn into_range(self) -> AnyRange<Self::Item> {
270				AnyRange::new(Bound::Included(self), Bound::Included(self))
271			}
272		}
273	};
274}
275
276singleton_range!(u8);
277singleton_range!(i8);
278singleton_range!(u16);
279singleton_range!(i16);
280singleton_range!(u32);
281singleton_range!(i32);
282singleton_range!(u64);
283singleton_range!(i64);
284// singleton_range!(u128);
285// singleton_range!(i128);
286singleton_range!(usize);
287// singleton_range!(isize);
288singleton_range!(f32);
289singleton_range!(f64);
290singleton_range!(char);
291
292macro_rules! standard_range {
293	($ty:path, |$this:ident| $into_range:expr) => {
294		impl<T: Measure + PartialEnum> AsRange for $ty {
295			type Item = T;
296
297			fn start(&self) -> Bound<&Self::Item> {
298				self.start_bound()
299			}
300
301			fn end(&self) -> Bound<&Self::Item> {
302				self.end_bound()
303			}
304		}
305
306		impl<T: Measure + PartialEnum> IntoRange for $ty {
307			fn into_range($this) -> AnyRange<Self::Item> {
308				$into_range
309			}
310		}
311	};
312}
313
314standard_range!(std::ops::Range<T>, |self| AnyRange::new(
315	Bound::Included(self.start),
316	Bound::Excluded(self.end)
317));
318standard_range!(std::ops::RangeInclusive<T>, |self| {
319	let (a, b) = self.into_inner();
320	AnyRange::new(Bound::Included(a), Bound::Included(b))
321});
322standard_range!(std::ops::RangeFrom<T>, |self| AnyRange::new(
323	Bound::Included(self.start),
324	Bound::Unbounded
325));
326standard_range!(std::ops::RangeTo<T>, |self| AnyRange::new(
327	Bound::Unbounded,
328	Bound::Excluded(self.end)
329));
330standard_range!(std::ops::RangeToInclusive<T>, |self| AnyRange::new(
331	Bound::Unbounded,
332	Bound::Included(self.end)
333));
334standard_range!(AnyRange<T>, |self| self);
335standard_range!(RangeFromExcluded<T>, |self| AnyRange::new(
336	Bound::Excluded(self.start),
337	Bound::Unbounded
338));
339standard_range!(RangeFromExcludedTo<T>, |self| AnyRange::new(
340	Bound::Excluded(self.start),
341	Bound::Excluded(self.end)
342));
343standard_range!(RangeFromExcludedToIncluded<T>, |self| AnyRange::new(
344	Bound::Excluded(self.start),
345	Bound::Included(self.end)
346));
347
348#[inline(always)]
349fn is_range_empty<T, U>(start: Bound<&T>, end: Bound<&U>) -> bool
350where
351	T: PartialOrd<U> + Measure<U> + PartialEnum,
352	U: PartialEnum,
353{
354	Directed::Start(start) > Directed::End(end)
355}
356
357#[cfg(test)]
358mod tests {
359	use crate::RangeSet;
360
361	use super::*;
362	use std::cmp::Ordering;
363
364	macro_rules! make_bound {
365		([= $v:literal ..]) => {
366			Directed::Start(Bound::Included(&$v))
367		};
368		([$v:literal ..]) => {
369			Directed::Start(Bound::Excluded(&$v))
370		};
371		([~ ..]) => {
372			Directed::Start(Bound::Unbounded)
373		};
374		([..= $v:literal]) => {
375			Directed::End(Bound::Included(&$v))
376		};
377		([.. $v:literal]) => {
378			Directed::End(Bound::Excluded(&$v))
379		};
380		([.. ~]) => {
381			Directed::End(Bound::Unbounded)
382		};
383	}
384
385	macro_rules! test_bound_cmp {
386		(@assert $ty:ty, $a:tt, $b:tt, $expected:ident) => {
387			assert_eq!(<Directed<Bound<&$ty>> as PartialOrd>::partial_cmp(&make_bound!($a), &make_bound!($b)), Some(Ordering::$expected));
388		};
389		($ty:ty, $a:tt < $b:tt) => {
390			test_bound_cmp!(@assert $ty, $a, $b, Less)
391		};
392		($ty:ty, $a:tt == $b:tt) => {
393			test_bound_cmp!(@assert $ty, $a, $b, Equal)
394		};
395		($ty:ty, $a:tt > $b:tt) => {
396			test_bound_cmp!(@assert $ty, $a, $b, Greater)
397		}
398	}
399
400	#[test]
401	fn issue_2() {
402		let k = AnyRange {
403			start: Bound::Excluded(0u32),
404			end: Bound::Unbounded,
405		};
406		assert!(!k.is_empty());
407
408		let mut ids: RangeSet<u32> = RangeSet::new();
409		ids.insert(0u32);
410
411		let mut gaps = ids.gaps();
412		assert_eq!(
413			gaps.next().unwrap().cloned(),
414			AnyRange::new(Bound::Excluded(0), Bound::Unbounded)
415		);
416		assert_eq!(gaps.next().map(AnyRange::cloned), None);
417	}
418
419	#[test]
420	fn unsigned_integer_bound_partial_less() {
421		test_bound_cmp!(u32, [=0..] < [=1..]);
422		test_bound_cmp!(u32, [=0..] < [0..]);
423		test_bound_cmp!(u32, [=0..] < [..=1]);
424		test_bound_cmp!(u32, [=0..] < [..2]);
425		test_bound_cmp!(u32, [=0..] < [..~]);
426
427		test_bound_cmp!(u32, [0..] < [=2..]);
428		test_bound_cmp!(u32, [0..] < [1..]);
429		test_bound_cmp!(u32, [0..] < [..=2]);
430		test_bound_cmp!(u32, [0..] < [..3]);
431		test_bound_cmp!(u32, [0..] < [..~]);
432
433		test_bound_cmp!(u32, [~..] < [..=0]);
434		test_bound_cmp!(u32, [~..] < [..~]);
435
436		test_bound_cmp!(u32, [..=0] < [=1..]);
437		test_bound_cmp!(u32, [..=0] < [0..]);
438		test_bound_cmp!(u32, [..=0] < [..=1]);
439		test_bound_cmp!(u32, [..=0] < [..2]);
440		test_bound_cmp!(u32, [..=0] < [..~]);
441
442		test_bound_cmp!(u32, [..1] < [=1..]);
443		test_bound_cmp!(u32, [..1] < [0..]);
444		test_bound_cmp!(u32, [..1] < [..=1]);
445		test_bound_cmp!(u32, [..1] < [..2]);
446		test_bound_cmp!(u32, [..0] < [..~]);
447	}
448
449	#[test]
450	fn unsigned_integer_bound_partial_eq() {
451		test_bound_cmp!(u32, [~..] == [=0..]);
452	}
453
454	#[test]
455	fn unsigned_integer_bound_partial_greater() {
456		test_bound_cmp!(u32, [~..] > [..0]);
457	}
458
459	#[test]
460	fn integer_bound_partial_less() {
461		test_bound_cmp!(i32, [=0..] < [=1..]);
462		test_bound_cmp!(i32, [=0..] < [0..]);
463		test_bound_cmp!(i32, [=0..] < [..=1]);
464		test_bound_cmp!(i32, [=0..] < [..2]);
465		test_bound_cmp!(i32, [=0..] < [..~]);
466
467		test_bound_cmp!(i32, [0..] < [=2..]);
468		test_bound_cmp!(i32, [0..] < [1..]);
469		test_bound_cmp!(i32, [0..] < [..=2]);
470		test_bound_cmp!(i32, [0..] < [..3]);
471		test_bound_cmp!(i32, [0..] < [..~]);
472		test_bound_cmp!(i32, [-2_147_483_648i32..] < [..~]);
473
474		test_bound_cmp!(i32, [~..] < [=0..]);
475		test_bound_cmp!(i32, [~..] < [..=0]);
476		test_bound_cmp!(i32, [~..] < [..0]);
477		test_bound_cmp!(i32, [~..] < [..~]);
478
479		test_bound_cmp!(i32, [..=0] < [=1..]);
480		test_bound_cmp!(i32, [..=0] < [0..]);
481		test_bound_cmp!(i32, [..=0] < [..=1]);
482		test_bound_cmp!(i32, [..=0] < [..2]);
483		test_bound_cmp!(i32, [..=0] < [..~]);
484
485		test_bound_cmp!(i32, [..1] < [=1..]);
486		test_bound_cmp!(i32, [..1] < [0..]);
487		test_bound_cmp!(i32, [..1] < [..=1]);
488		test_bound_cmp!(i32, [..1] < [..2]);
489		test_bound_cmp!(i32, [..0] < [..~]);
490	}
491
492	#[test]
493	fn integer_bound_partial_eq() {
494		test_bound_cmp!(i32, [=0..] == [=0..]);
495		test_bound_cmp!(i32, [=1..] == [0..]);
496		test_bound_cmp!(i32, [=0..] == [..=0]);
497		test_bound_cmp!(i32, [=0..] == [..1]);
498
499		test_bound_cmp!(i32, [0..] == [=1..]);
500		test_bound_cmp!(i32, [0..] == [0..]);
501		test_bound_cmp!(i32, [0..] == [..=1]);
502		test_bound_cmp!(i32, [0..] == [..2]);
503
504		test_bound_cmp!(i32, [~..] == [~..]);
505
506		test_bound_cmp!(i32, [..=0] == [=0..]);
507		test_bound_cmp!(i32, [..=1] == [0..]);
508		test_bound_cmp!(i32, [..=0] == [..=0]);
509		test_bound_cmp!(i32, [..=0] == [..1]);
510
511		test_bound_cmp!(i32, [..1] == [=0..]);
512		test_bound_cmp!(i32, [..2] == [0..]);
513		test_bound_cmp!(i32, [..1] == [..=0]);
514		test_bound_cmp!(i32, [..0] == [..0]);
515
516		test_bound_cmp!(i32, [..~] == [..~]);
517	}
518
519	#[test]
520	fn integer_bound_partial_greater() {
521		test_bound_cmp!(i32, [=1..] > [=0..]);
522		test_bound_cmp!(i32, [0..] > [=0..]);
523		test_bound_cmp!(i32, [..=1] > [=0..]);
524		test_bound_cmp!(i32, [..2] > [=0..]);
525		test_bound_cmp!(i32, [..~] > [=0..]);
526
527		test_bound_cmp!(i32, [=2..] > [0..]);
528		test_bound_cmp!(i32, [1..] > [0..]);
529		test_bound_cmp!(i32, [..=2] > [0..]);
530		test_bound_cmp!(i32, [..3] > [0..]);
531		test_bound_cmp!(i32, [..~] > [0..]);
532
533		test_bound_cmp!(i32, [=0..] > [~..]);
534		test_bound_cmp!(i32, [..=0] > [~..]);
535		test_bound_cmp!(i32, [..0] > [~..]);
536		test_bound_cmp!(i32, [..~] > [~..]);
537
538		test_bound_cmp!(i32, [=1..] > [..=0]);
539		test_bound_cmp!(i32, [0..] > [..=0]);
540		test_bound_cmp!(i32, [..=1] > [..=0]);
541		test_bound_cmp!(i32, [..2] > [..=0]);
542		test_bound_cmp!(i32, [..~] > [..=0]);
543
544		test_bound_cmp!(i32, [=1..] > [..1]);
545		test_bound_cmp!(i32, [0..] > [..1]);
546		test_bound_cmp!(i32, [..=1] > [..1]);
547		test_bound_cmp!(i32, [..2] > [..1]);
548		test_bound_cmp!(i32, [..~] > [..0]);
549	}
550
551	#[test]
552	fn float_bound_partial_less() {
553		test_bound_cmp!(f32, [=0.0..] < [=1.0..]);
554		test_bound_cmp!(f32, [=0.0..] < [0.0..]);
555		test_bound_cmp!(f32, [=0.0..] < [..=1.0]);
556		test_bound_cmp!(f32, [=0.0..] < [..2.0]);
557		test_bound_cmp!(f32, [=0.0..] < [..~]);
558
559		test_bound_cmp!(f32, [0.0..] < [=2.0..]);
560		test_bound_cmp!(f32, [0.0..] < [1.0..]);
561		test_bound_cmp!(f32, [0.0..] < [..1.0]); // different from the int behavior
562		test_bound_cmp!(f32, [0.0..] < [..=2.0]);
563		test_bound_cmp!(f32, [0.0..] < [..3.0]);
564		test_bound_cmp!(f32, [0.0..] < [..~]);
565
566		test_bound_cmp!(f32, [~..] < [=0.0..]);
567		test_bound_cmp!(f32, [~..] < [..=0.0]);
568		test_bound_cmp!(f32, [~..] < [..0.0]);
569		test_bound_cmp!(f32, [~..] < [..~]);
570
571		test_bound_cmp!(f32, [..=0.0] < [=1.0..]);
572		test_bound_cmp!(f32, [..=0.0] < [0.0..]);
573		test_bound_cmp!(f32, [..=0.0] < [..=1.0]);
574		test_bound_cmp!(f32, [..=0.0] < [..2.0]);
575		test_bound_cmp!(f32, [..=0.0] < [..~]);
576
577		test_bound_cmp!(f32, [..1.0] < [=1.0..]);
578		test_bound_cmp!(f32, [..1.0] < [1.0..]);
579		test_bound_cmp!(f32, [..1.0] < [..=1.0]);
580		test_bound_cmp!(f32, [..1.0] < [..2.0]);
581		test_bound_cmp!(f32, [..0.0] < [..~]);
582	}
583
584	#[test]
585	fn float_bound_partial_eq() {
586		test_bound_cmp!(f32, [=0.0..] == [=0.0..]);
587		test_bound_cmp!(f32, [=1.0..] > [0.0..]); // different from the int behavior
588		test_bound_cmp!(f32, [=0.0..] == [..=0.0]);
589		test_bound_cmp!(f32, [=0.0..] < [..1.0]); // different from the int behavior
590
591		test_bound_cmp!(f32, [0.0..] < [=1.0..]); // different from the int behavior
592		test_bound_cmp!(f32, [0.0..] == [0.0..]);
593		test_bound_cmp!(f32, [0.0..] < [..=1.0]); // different from the int behavior
594		test_bound_cmp!(f32, [0.0..] < [..2.0]); // different from the int behavior
595
596		test_bound_cmp!(f32, [~..] == [~..]);
597
598		test_bound_cmp!(f32, [..=0.0] == [=0.0..]);
599		test_bound_cmp!(f32, [..=1.0] > [0.0..]); // different from the int behavior
600		test_bound_cmp!(f32, [..=0.0] == [..=0.0]);
601		test_bound_cmp!(f32, [..=0.0] < [..1.0]); // different from the int behavior
602
603		test_bound_cmp!(f32, [..1.0] > [=0.0..]); // different from the int behavior
604		test_bound_cmp!(f32, [..2.0] > [0.0..]); // different from the int behavior
605		test_bound_cmp!(f32, [..1.0] > [..=0.0]); // different from the int behavior
606		test_bound_cmp!(f32, [..0.0] == [..0.0]);
607
608		test_bound_cmp!(f32, [..~] == [..~]);
609	}
610
611	#[test]
612	fn float_bound_partial_greater() {
613		test_bound_cmp!(f32, [=1.0..] > [=0.0..]);
614		test_bound_cmp!(f32, [0.0..] > [=0.0..]);
615		test_bound_cmp!(f32, [..=1.0] > [=0.0..]);
616		test_bound_cmp!(f32, [..2.0] > [=0.0..]);
617		test_bound_cmp!(f32, [..~] > [=0.0..]);
618
619		test_bound_cmp!(f32, [=2.0..] > [0.0..]);
620		test_bound_cmp!(f32, [1.0..] > [0.0..]);
621		test_bound_cmp!(f32, [..1.0] > [0.0..]); // different from the int behavior
622		test_bound_cmp!(f32, [..=2.0] > [0.0..]);
623		test_bound_cmp!(f32, [..3.0] > [0.0..]);
624		test_bound_cmp!(f32, [..~] > [0.0..]);
625
626		test_bound_cmp!(f32, [=0.0..] > [~..]);
627		test_bound_cmp!(f32, [..=0.0] > [~..]);
628		test_bound_cmp!(f32, [..0.0] > [~..]);
629		test_bound_cmp!(f32, [..~] > [~..]);
630
631		test_bound_cmp!(f32, [=1.0..] > [..=0.0]);
632		test_bound_cmp!(f32, [0.0..] > [..=0.0]);
633		test_bound_cmp!(f32, [..=1.0] > [..=0.0]);
634		test_bound_cmp!(f32, [..2.0] > [..=0.0]);
635		test_bound_cmp!(f32, [..~] > [..=0.0]);
636
637		test_bound_cmp!(f32, [=1.0..] > [..1.0]);
638		test_bound_cmp!(f32, [1.0..] > [..1.0]);
639		test_bound_cmp!(f32, [..=1.0] > [..1.0]);
640		test_bound_cmp!(f32, [..2.0] > [..1.0]);
641		test_bound_cmp!(f32, [..~] > [..0.0]);
642	}
643
644	#[test]
645	fn int_intersection() {
646		assert!((0..10).intersects(&(5..100)));
647	}
648
649	// Intersecting ranges are connected.
650	#[test]
651	fn int_connected_intersection() {
652		assert!((0..10).connected_to(&(5..100)));
653	}
654
655	#[test]
656	fn int_connected() {
657		assert!((0..10).connected_to(&(10..20)));
658		assert!((10..20).connected_to(&(0..10)));
659		assert!((0..=10).connected_to(&(RangeFromExcludedTo::new(10, 20))));
660	}
661
662	#[test]
663	fn int_disconnected() {
664		assert!(!(0..10).connected_to(&(11..20)));
665		assert!(!(11..20).connected_to(&(0..10)));
666		assert!(!(0..10).connected_to(&(RangeFromExcludedTo::new(10, 20))));
667	}
668
669	#[test]
670	fn float_connected() {
671		assert!((0.0..10.0).connected_to(&(10.0..20.0)));
672		assert!((0.0..=10.0).connected_to(&(RangeFromExcludedTo::new(10.0, 20.0))));
673	}
674
675	#[test]
676	fn float_disconnected() {
677		assert!(!(0.0..10.0).connected_to(&(RangeFromExcludedTo::new(10.0, 20.0))));
678		assert!(!(..10.0).connected_to(&(RangeFromExcludedTo::new(10.0, 20.0))));
679		assert!(!(0.0..10.0).connected_to(&(RangeFromExcluded::new(10.0))));
680		assert!(!(..10.0).connected_to(&(RangeFromExcluded::new(10.0))));
681	}
682}