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() {
66 assert!(!(0.0..10.0).is_empty());
67 assert!((-0.0..0.0).is_empty());
68 assert!((10.0..0.0).is_empty());
70 assert!(!(NEG_INFINITY..INFINITY).is_empty());
71 assert!((EPSILON..NAN).is_empty());
72 assert!((NAN..EPSILON).is_empty());
73 assert!((NAN..NAN).is_empty());
75 assert!(!(0.0..=10.0).is_empty());
76 assert!(!(-0.0..=0.0).is_empty());
77 assert!((10.0..=0.0).is_empty());
79 assert!(!(NEG_INFINITY..=INFINITY).is_empty());
80 assert!((EPSILON..=NAN).is_empty());
81 assert!((NAN..=EPSILON).is_empty());
82 assert!((NAN..=NAN).is_empty());
86 fn test_bound_cloned_unbounded() {
87 assert_eq!(Bound::<&u32>::Unbounded.cloned(), Bound::Unbounded);
91 fn test_bound_cloned_included() {
92 assert_eq!(Bound::Included(&3).cloned(), Bound::Included(3));
96 fn test_bound_cloned_excluded() {
97 assert_eq!(Bound::Excluded(&3).cloned(), Bound::Excluded(3));