]> git.lizzy.rs Git - rust.git/blob - src/libcoretest/tuple.rs
std: Rename Show/String to Debug/Display
[rust.git] / src / libcoretest / tuple.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 std::cmp::Ordering::{Equal, Less, Greater};
12
13 #[test]
14 fn test_clone() {
15     let a = (1i, "2");
16     let b = a.clone();
17     assert_eq!(a, b);
18 }
19
20 #[test]
21 fn test_tuple_cmp() {
22     let (small, big) = ((1u, 2u, 3u), (3u, 2u, 1u));
23
24     let nan = 0.0f64/0.0;
25
26     // PartialEq
27     assert_eq!(small, small);
28     assert_eq!(big, big);
29     assert!(small != big);
30     assert!(big != small);
31
32     // PartialOrd
33     assert!(small < big);
34     assert!(!(small < small));
35     assert!(!(big < small));
36     assert!(!(big < big));
37
38     assert!(small <= small);
39     assert!(big <= big);
40
41     assert!(big > small);
42     assert!(small >= small);
43     assert!(big >= small);
44     assert!(big >= big);
45
46     assert!(!((1.0f64, 2.0f64) < (nan, 3.0)));
47     assert!(!((1.0f64, 2.0f64) <= (nan, 3.0)));
48     assert!(!((1.0f64, 2.0f64) > (nan, 3.0)));
49     assert!(!((1.0f64, 2.0f64) >= (nan, 3.0)));
50     assert!(((1.0f64, 2.0f64) < (2.0, nan)));
51     assert!(!((2.0f64, 2.0f64) < (2.0, nan)));
52
53     // Ord
54     assert!(small.cmp(&small) == Equal);
55     assert!(big.cmp(&big) == Equal);
56     assert!(small.cmp(&big) == Less);
57     assert!(big.cmp(&small) == Greater);
58 }
59
60 #[test]
61 fn test_show() {
62     let s = format!("{:?}", (1i,));
63     assert_eq!(s, "(1,)");
64     let s = format!("{:?}", (1i, true));
65     assert_eq!(s, "(1, true)");
66     let s = format!("{:?}", (1i, "hi", true));
67     assert_eq!(s, "(1, \"hi\", true)");
68 }