2014-06-23 18:41:23 -05:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
// Basic boolean tests
|
|
|
|
|
2015-03-22 15:13:15 -05:00
|
|
|
|
2014-12-23 12:31:43 -06:00
|
|
|
use std::cmp::Ordering::{Equal, Greater, Less};
|
2014-12-22 11:04:23 -06:00
|
|
|
use std::ops::{BitAnd, BitOr, BitXor};
|
|
|
|
|
2014-06-23 18:41:23 -05:00
|
|
|
fn main() {
|
|
|
|
assert_eq!(false.eq(&true), false);
|
|
|
|
assert_eq!(false == false, true);
|
|
|
|
assert_eq!(false != true, true);
|
|
|
|
assert_eq!(false.ne(&false), false);
|
|
|
|
|
2014-12-01 16:33:22 -06:00
|
|
|
assert_eq!(false.bitand(false), false);
|
|
|
|
assert_eq!(true.bitand(false), false);
|
|
|
|
assert_eq!(false.bitand(true), false);
|
|
|
|
assert_eq!(true.bitand(true), true);
|
2014-06-23 18:41:23 -05:00
|
|
|
|
|
|
|
assert_eq!(false & false, false);
|
|
|
|
assert_eq!(true & false, false);
|
|
|
|
assert_eq!(false & true, false);
|
|
|
|
assert_eq!(true & true, true);
|
|
|
|
|
2014-12-01 16:33:22 -06:00
|
|
|
assert_eq!(false.bitor(false), false);
|
|
|
|
assert_eq!(true.bitor(false), true);
|
|
|
|
assert_eq!(false.bitor(true), true);
|
|
|
|
assert_eq!(true.bitor(true), true);
|
2014-06-23 18:41:23 -05:00
|
|
|
|
|
|
|
assert_eq!(false | false, false);
|
|
|
|
assert_eq!(true | false, true);
|
|
|
|
assert_eq!(false | true, true);
|
|
|
|
assert_eq!(true | true, true);
|
|
|
|
|
2014-12-01 16:33:22 -06:00
|
|
|
assert_eq!(false.bitxor(false), false);
|
|
|
|
assert_eq!(true.bitxor(false), true);
|
|
|
|
assert_eq!(false.bitxor(true), true);
|
|
|
|
assert_eq!(true.bitxor(true), false);
|
2014-06-23 18:41:23 -05:00
|
|
|
|
|
|
|
assert_eq!(false ^ false, false);
|
|
|
|
assert_eq!(true ^ false, true);
|
|
|
|
assert_eq!(false ^ true, true);
|
|
|
|
assert_eq!(true ^ true, false);
|
|
|
|
|
|
|
|
assert_eq!(!true, false);
|
|
|
|
assert_eq!(!false, true);
|
|
|
|
|
2014-06-21 05:39:03 -05:00
|
|
|
let s = false.to_string();
|
2015-02-01 20:53:25 -06:00
|
|
|
assert_eq!(s, "false");
|
2014-06-21 05:39:03 -05:00
|
|
|
let s = true.to_string();
|
2015-02-01 20:53:25 -06:00
|
|
|
assert_eq!(s, "true");
|
2014-06-23 18:41:23 -05:00
|
|
|
|
|
|
|
assert!(true > false);
|
|
|
|
assert!(!(false > true));
|
|
|
|
|
|
|
|
assert!(false < true);
|
|
|
|
assert!(!(true < false));
|
|
|
|
|
|
|
|
assert!(false <= false);
|
|
|
|
assert!(false >= false);
|
|
|
|
assert!(true <= true);
|
|
|
|
assert!(true >= true);
|
|
|
|
|
|
|
|
assert!(false <= true);
|
|
|
|
assert!(!(false >= true));
|
|
|
|
assert!(true >= false);
|
|
|
|
assert!(!(true <= false));
|
|
|
|
|
|
|
|
assert!(true.cmp(&true) == Equal);
|
|
|
|
assert!(false.cmp(&false) == Equal);
|
|
|
|
assert!(true.cmp(&false) == Greater);
|
|
|
|
assert!(false.cmp(&true) == Less);
|
|
|
|
}
|