Skip to content

Commit 47c071f

Browse files
committed
---
yaml --- r: 56079 b: refs/heads/auto c: 9949279 h: refs/heads/master i: 56077: 69a699e 56075: 657187a 56071: 14c8d83 56063: 02320c2 v: v3
1 parent 682cdb6 commit 47c071f

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
@@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: 7906c5572a8c4c5c0f6aa6e69bb63d64de50d697
17+
refs/heads/auto: 99492796dcaac41966dc54f7ab4b8e33e641bb73
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1919
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
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)