rust/src/test/run-pass/structured-compare.rs

27 lines
532 B
Rust
Raw Normal View History

enum foo { large, small, }
2012-08-27 18:26:35 -05:00
impl foo : cmp::Eq {
pure fn eq(other: &foo) -> bool {
(self as uint) == ((*other) as uint)
2012-08-27 18:26:35 -05:00
}
pure fn ne(other: &foo) -> bool { !self.eq(other) }
2012-08-27 18:26:35 -05:00
}
fn main() {
2012-08-27 18:26:35 -05:00
let a = (1, 2, 3);
let b = (1, 2, 3);
assert (a == b);
2012-08-27 18:26:35 -05:00
assert (a != (1, 2, 4));
assert (a < (1, 2, 4));
assert (a <= (1, 2, 4));
assert ((1, 2, 4) > a);
assert ((1, 2, 4) >= a);
2011-07-27 07:19:39 -05:00
let x = large;
let y = small;
assert (x != y);
assert (x == large);
assert (x != small);
}