2019-07-26 16:54:25 -05:00
|
|
|
// run-pass
|
|
|
|
|
2014-12-22 11:04:23 -06:00
|
|
|
use std::cmp::Ordering;
|
|
|
|
|
2014-05-29 19:45:07 -05:00
|
|
|
// Test default methods in PartialOrd and PartialEq
|
2013-07-12 21:29:31 -05:00
|
|
|
//
|
2015-06-07 13:00:38 -05:00
|
|
|
#[derive(Debug)]
|
2013-07-14 21:00:39 -05:00
|
|
|
struct Fool(bool);
|
|
|
|
|
2014-05-29 19:45:07 -05:00
|
|
|
impl PartialEq for Fool {
|
2013-07-14 21:00:39 -05:00
|
|
|
fn eq(&self, other: &Fool) -> bool {
|
2013-11-01 20:06:31 -05:00
|
|
|
let Fool(this) = *self;
|
|
|
|
let Fool(other) = *other;
|
|
|
|
this != other
|
2013-07-14 21:00:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
struct Int(isize);
|
2013-07-12 21:29:31 -05:00
|
|
|
|
2014-05-29 19:45:07 -05:00
|
|
|
impl PartialEq for Int {
|
2014-02-24 07:11:00 -06:00
|
|
|
fn eq(&self, other: &Int) -> bool {
|
|
|
|
let Int(this) = *self;
|
|
|
|
let Int(other) = *other;
|
|
|
|
this == other
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-29 19:45:07 -05:00
|
|
|
impl PartialOrd for Int {
|
2014-06-18 01:25:51 -05:00
|
|
|
fn partial_cmp(&self, other: &Int) -> Option<Ordering> {
|
2013-11-01 20:06:31 -05:00
|
|
|
let Int(this) = *self;
|
|
|
|
let Int(other) = *other;
|
2014-06-18 01:25:51 -05:00
|
|
|
this.partial_cmp(&other)
|
2013-07-12 21:29:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
struct RevInt(isize);
|
2013-07-12 21:29:31 -05:00
|
|
|
|
2014-05-29 19:45:07 -05:00
|
|
|
impl PartialEq for RevInt {
|
2014-02-24 07:11:00 -06:00
|
|
|
fn eq(&self, other: &RevInt) -> bool {
|
|
|
|
let RevInt(this) = *self;
|
|
|
|
let RevInt(other) = *other;
|
|
|
|
this == other
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-29 19:45:07 -05:00
|
|
|
impl PartialOrd for RevInt {
|
2014-06-18 01:25:51 -05:00
|
|
|
fn partial_cmp(&self, other: &RevInt) -> Option<Ordering> {
|
2013-11-01 20:06:31 -05:00
|
|
|
let RevInt(this) = *self;
|
|
|
|
let RevInt(other) = *other;
|
2014-06-18 01:25:51 -05:00
|
|
|
other.partial_cmp(&this)
|
2013-07-12 21:29:31 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
|
|
|
assert!(Int(2) > Int(1));
|
|
|
|
assert!(Int(2) >= Int(1));
|
|
|
|
assert!(Int(1) >= Int(1));
|
|
|
|
assert!(Int(1) < Int(2));
|
|
|
|
assert!(Int(1) <= Int(2));
|
|
|
|
assert!(Int(1) <= Int(1));
|
|
|
|
|
|
|
|
assert!(RevInt(2) < RevInt(1));
|
|
|
|
assert!(RevInt(2) <= RevInt(1));
|
|
|
|
assert!(RevInt(1) <= RevInt(1));
|
|
|
|
assert!(RevInt(1) > RevInt(2));
|
|
|
|
assert!(RevInt(1) >= RevInt(2));
|
|
|
|
assert!(RevInt(1) >= RevInt(1));
|
2013-07-14 21:00:39 -05:00
|
|
|
|
2015-06-07 13:00:38 -05:00
|
|
|
assert_eq!(Fool(true), Fool(false));
|
2013-07-14 21:00:39 -05:00
|
|
|
assert!(Fool(true) != Fool(true));
|
|
|
|
assert!(Fool(false) != Fool(false));
|
2015-06-07 13:00:38 -05:00
|
|
|
assert_eq!(Fool(false), Fool(true));
|
2013-07-12 21:29:31 -05:00
|
|
|
}
|