]>
Commit | Line | Data |
---|---|---|
416331ca XL |
1 | // run-pass |
2 | ||
1a4d82fc JJ |
3 | use std::cmp::Ordering; |
4 | ||
5 | // Test default methods in PartialOrd and PartialEq | |
6 | // | |
62682a34 | 7 | #[derive(Debug)] |
1a4d82fc JJ |
8 | struct Fool(bool); |
9 | ||
10 | impl PartialEq for Fool { | |
11 | fn eq(&self, other: &Fool) -> bool { | |
12 | let Fool(this) = *self; | |
13 | let Fool(other) = *other; | |
14 | this != other | |
15 | } | |
16 | } | |
17 | ||
c34b1796 | 18 | struct Int(isize); |
1a4d82fc JJ |
19 | |
20 | impl PartialEq for Int { | |
21 | fn eq(&self, other: &Int) -> bool { | |
22 | let Int(this) = *self; | |
23 | let Int(other) = *other; | |
24 | this == other | |
25 | } | |
26 | } | |
27 | ||
28 | impl PartialOrd for Int { | |
29 | fn partial_cmp(&self, other: &Int) -> Option<Ordering> { | |
30 | let Int(this) = *self; | |
31 | let Int(other) = *other; | |
32 | this.partial_cmp(&other) | |
33 | } | |
34 | } | |
35 | ||
c34b1796 | 36 | struct RevInt(isize); |
1a4d82fc JJ |
37 | |
38 | impl PartialEq for RevInt { | |
39 | fn eq(&self, other: &RevInt) -> bool { | |
40 | let RevInt(this) = *self; | |
41 | let RevInt(other) = *other; | |
42 | this == other | |
43 | } | |
44 | } | |
45 | ||
46 | impl PartialOrd for RevInt { | |
47 | fn partial_cmp(&self, other: &RevInt) -> Option<Ordering> { | |
48 | let RevInt(this) = *self; | |
49 | let RevInt(other) = *other; | |
50 | other.partial_cmp(&this) | |
51 | } | |
52 | } | |
53 | ||
54 | pub fn main() { | |
55 | assert!(Int(2) > Int(1)); | |
56 | assert!(Int(2) >= Int(1)); | |
57 | assert!(Int(1) >= Int(1)); | |
58 | assert!(Int(1) < Int(2)); | |
59 | assert!(Int(1) <= Int(2)); | |
60 | assert!(Int(1) <= Int(1)); | |
61 | ||
62 | assert!(RevInt(2) < RevInt(1)); | |
63 | assert!(RevInt(2) <= RevInt(1)); | |
64 | assert!(RevInt(1) <= RevInt(1)); | |
65 | assert!(RevInt(1) > RevInt(2)); | |
66 | assert!(RevInt(1) >= RevInt(2)); | |
67 | assert!(RevInt(1) >= RevInt(1)); | |
68 | ||
62682a34 | 69 | assert_eq!(Fool(true), Fool(false)); |
1a4d82fc JJ |
70 | assert!(Fool(true) != Fool(true)); |
71 | assert!(Fool(false) != Fool(false)); | |
62682a34 | 72 | assert_eq!(Fool(false), Fool(true)); |
1a4d82fc | 73 | } |