Skip to content

Commit 4dd44b6

Browse files
committed
---
yaml --- r: 54673 b: refs/heads/snap-stage3 c: 9949279 h: refs/heads/master i: 54671: b15b466 v: v3
1 parent 797d41b commit 4dd44b6

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 5f13e9ccc2e3328d4cd8ca49f84e6840dd998346
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 7906c5572a8c4c5c0f6aa6e69bb63d64de50d697
4+
refs/heads/snap-stage3: 99492796dcaac41966dc54f7ab4b8e33e641bb73
55
refs/heads/try: 8eb2bab100b42f0ba751552d8eff00eb2134c55a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright 2013 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+
#[deriving(Eq, TotalEq, Ord, TotalOrd)]
12+
struct S<T> {
13+
x: T,
14+
y: T
15+
}
16+
17+
#[deriving(Eq, TotalEq, Ord, TotalOrd)]
18+
struct TS<T>(T,T);
19+
20+
#[deriving(Eq, TotalEq, Ord, TotalOrd)]
21+
enum E<T> {
22+
E0,
23+
E1(T),
24+
E2(T,T)
25+
}
26+
27+
#[deriving(Eq, TotalEq, Ord, TotalOrd)]
28+
enum ES<T> {
29+
ES1 { x: T },
30+
ES2 { x: T, y: T }
31+
}
32+
33+
34+
pub fn main() {
35+
let s1 = S {x: 1, y: 1}, s2 = S {x: 1, y: 2};
36+
let ts1 = TS(1, 1), ts2 = TS(1,2);
37+
let e0 = E0, e11 = E1(1), e12 = E1(2), e21 = E2(1,1), e22 = E2(1, 2);
38+
let es11 = ES1 {x: 1}, es12 = ES1 {x: 2}, es21 = ES2 {x: 1, y: 1}, es22 = ES2 {x: 1, y: 2};
39+
40+
test([s1, s2]);
41+
test([ts1, ts2]);
42+
test([e0, e11, e12, e21, e22]);
43+
test([es11, es12, es21, es22]);
44+
}
45+
46+
fn test<T: Eq+TotalEq+Ord+TotalOrd>(ts: &[T]) {
47+
// compare each element against all other elements. The list
48+
// should be in sorted order, so that if i < j, then ts[i] <
49+
// ts[j], etc.
50+
for ts.eachi |i, t1| {
51+
for ts.eachi |j, t2| {
52+
let ord = i.cmp(&j);
53+
54+
let eq = i == j;
55+
let lt = i < j, le = i <= j;
56+
let gt = i > j, ge = i >= j;
57+
58+
// Eq
59+
assert_eq!(*t1 == *t2, eq);
60+
61+
// TotalEq
62+
assert_eq!(t1.equals(t2), eq);
63+
64+
// Ord
65+
assert_eq!(*t1 < *t2, lt);
66+
assert_eq!(*t1 > *t2, gt);
67+
68+
assert_eq!(*t1 <= *t2, le);
69+
assert_eq!(*t1 >= *t2, ge);
70+
71+
// TotalOrd
72+
assert_eq!(t1.cmp(t2), ord);
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)