]> git.lizzy.rs Git - rust.git/blob - src/libcoretest/ops.rs
Auto merge of #27630 - sylvestre:master, r=dotdash
[rust.git] / src / libcoretest / ops.rs
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.
4 //
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.
10
11 use test::Bencher;
12 use core::ops::{Range, RangeFull, RangeFrom, RangeTo};
13
14 // Overhead of dtors
15
16 struct HasDtor {
17     _x: isize
18 }
19
20 impl Drop for HasDtor {
21     fn drop(&mut self) {
22     }
23 }
24
25 #[bench]
26 fn alloc_obj_with_dtor(b: &mut Bencher) {
27     b.iter(|| {
28         HasDtor { _x : 10 };
29     })
30 }
31
32 // Test the Range structs without the syntactic sugar.
33
34 #[test]
35 fn test_range() {
36     let r = Range { start: 2, end: 10 };
37     let mut count = 0;
38     for (i, ri) in r.enumerate() {
39         assert!(ri == i + 2);
40         assert!(ri >= 2 && ri < 10);
41         count += 1;
42     }
43     assert!(count == 8);
44 }
45
46 #[test]
47 fn test_range_from() {
48     let r = RangeFrom { start: 2 };
49     let mut count = 0;
50     for (i, ri) in r.take(10).enumerate() {
51         assert!(ri == i + 2);
52         assert!(ri >= 2 && ri < 12);
53         count += 1;
54     }
55     assert!(count == 10);
56 }
57
58 #[test]
59 fn test_range_to() {
60     // Not much to test.
61     let _ = RangeTo { end: 42 };
62 }
63
64 #[test]
65 fn test_full_range() {
66     // Not much to test.
67     let _ = RangeFull;
68 }