1 use core::ops::{Bound, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo};
3 // Test the Range structs without the syntactic sugar.
7 let r = Range { start: 2, end: 10 };
9 for (i, ri) in r.enumerate() {
10 assert_eq!(ri, i + 2);
11 assert!(ri >= 2 && ri < 10);
18 fn test_range_from() {
19 let r = RangeFrom { start: 2 };
21 for (i, ri) in r.take(10).enumerate() {
22 assert_eq!(ri, i + 2);
23 assert!(ri >= 2 && ri < 12);
26 assert_eq!(count, 10);
32 let _ = RangeTo { end: 42 };
36 fn test_full_range() {
42 fn test_range_inclusive() {
43 let mut r = RangeInclusive::new(1i8, 2);
44 assert_eq!(r.next(), Some(1));
45 assert_eq!(r.next(), Some(2));
46 assert_eq!(r.next(), None);
48 r = RangeInclusive::new(127i8, 127);
49 assert_eq!(r.next(), Some(127));
50 assert_eq!(r.next(), None);
52 r = RangeInclusive::new(-128i8, -128);
53 assert_eq!(r.next_back(), Some(-128));
54 assert_eq!(r.next_back(), None);
57 r = RangeInclusive::new(1, -1);
58 assert_eq!(r.size_hint(), (0, Some(0)));
59 assert_eq!(r.next(), None);
63 fn test_range_is_empty() {
64 assert!(!(0.0..10.0).is_empty());
65 assert!((-0.0..0.0).is_empty());
66 assert!((10.0..0.0).is_empty());
68 assert!(!(f32::NEG_INFINITY..f32::INFINITY).is_empty());
69 assert!((f32::EPSILON..f32::NAN).is_empty());
70 assert!((f32::NAN..f32::EPSILON).is_empty());
71 assert!((f32::NAN..f32::NAN).is_empty());
73 assert!(!(0.0..=10.0).is_empty());
74 assert!(!(-0.0..=0.0).is_empty());
75 assert!((10.0..=0.0).is_empty());
77 assert!(!(f32::NEG_INFINITY..=f32::INFINITY).is_empty());
78 assert!((f32::EPSILON..=f32::NAN).is_empty());
79 assert!((f32::NAN..=f32::EPSILON).is_empty());
80 assert!((f32::NAN..=f32::NAN).is_empty());
84 fn test_bound_cloned_unbounded() {
85 assert_eq!(Bound::<&u32>::Unbounded.cloned(), Bound::Unbounded);
89 fn test_bound_cloned_included() {
90 assert_eq!(Bound::Included(&3).cloned(), Bound::Included(3));
94 fn test_bound_cloned_excluded() {
95 assert_eq!(Bound::Excluded(&3).cloned(), Bound::Excluded(3));