1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 use core::ops::{Range, RangeFull, RangeFrom, RangeTo, RangeInclusive};
13 // Test the Range structs without the syntactic sugar.
17 let r = Range { start: 2, end: 10 };
19 for (i, ri) in r.enumerate() {
21 assert!(ri >= 2 && ri < 10);
28 fn test_range_from() {
29 let r = RangeFrom { start: 2 };
31 for (i, ri) in r.take(10).enumerate() {
33 assert!(ri >= 2 && ri < 12);
42 let _ = RangeTo { end: 42 };
46 fn test_full_range() {
52 fn test_range_inclusive() {
53 let mut r = RangeInclusive { start: 1i8, end: 2 };
54 assert_eq!(r.next(), Some(1));
55 assert_eq!(r.next(), Some(2));
56 assert_eq!(r.next(), None);
58 r = RangeInclusive { start: 127i8, end: 127 };
59 assert_eq!(r.next(), Some(127));
60 assert_eq!(r.next(), None);
62 r = RangeInclusive { start: -128i8, end: -128 };
63 assert_eq!(r.next_back(), Some(-128));
64 assert_eq!(r.next_back(), None);
67 r = RangeInclusive { start: 1, end: -1 };
68 assert_eq!(r.size_hint(), (0, Some(0)));
69 assert_eq!(r.next(), None);
74 fn test_range_is_empty() {
77 assert!(!(0.0 .. 10.0).is_empty());
78 assert!( (-0.0 .. 0.0).is_empty());
79 assert!( (10.0 .. 0.0).is_empty());
81 assert!(!(NEG_INFINITY .. INFINITY).is_empty());
82 assert!( (EPSILON .. NAN).is_empty());
83 assert!( (NAN .. EPSILON).is_empty());
84 assert!( (NAN .. NAN).is_empty());
86 assert!(!(0.0 ..= 10.0).is_empty());
87 assert!(!(-0.0 ..= 0.0).is_empty());
88 assert!( (10.0 ..= 0.0).is_empty());
90 assert!(!(NEG_INFINITY ..= INFINITY).is_empty());
91 assert!( (EPSILON ..= NAN).is_empty());
92 assert!( (NAN ..= EPSILON).is_empty());
93 assert!( (NAN ..= NAN).is_empty());