2012-12-03 16:48:01 -08:00
|
|
|
// Copyright 2012 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.
|
|
|
|
|
2012-07-04 22:53:12 +01:00
|
|
|
//! Operations on tuples
|
2012-03-15 18:58:14 -07:00
|
|
|
|
2014-03-21 18:05:05 -07:00
|
|
|
#![allow(missing_doc)]
|
2013-05-28 16:35:52 -05:00
|
|
|
|
2013-07-02 12:47:32 -07:00
|
|
|
use clone::Clone;
|
2013-11-29 15:52:38 +01:00
|
|
|
#[cfg(not(test))] use cmp::*;
|
|
|
|
#[cfg(not(test))] use default::Default;
|
2013-05-18 19:43:14 +10:00
|
|
|
|
2013-05-18 21:38:06 +10:00
|
|
|
// macro for implementing n-ary tuple functions and operations
|
2013-05-19 18:51:14 +10:00
|
|
|
macro_rules! tuple_impls {
|
2013-05-18 21:38:06 +10:00
|
|
|
($(
|
2014-02-16 20:25:28 +11:00
|
|
|
$Tuple:ident {
|
2014-02-16 22:19:41 +11:00
|
|
|
$(($valN:ident, $refN:ident, $mutN:ident) -> $T:ident {
|
|
|
|
($($x:ident),+) => $ret:expr
|
2013-05-18 22:46:02 +10:00
|
|
|
})+
|
2013-03-26 16:08:05 -07:00
|
|
|
}
|
2013-05-19 18:51:14 +10:00
|
|
|
)+) => {
|
2013-11-29 15:52:38 +01:00
|
|
|
$(
|
2014-02-16 20:25:28 +11:00
|
|
|
pub trait $Tuple<$($T),+> {
|
2014-02-16 22:19:41 +11:00
|
|
|
$(fn $valN(self) -> $T;)+
|
|
|
|
$(fn $refN<'a>(&'a self) -> &'a $T;)+
|
|
|
|
$(fn $mutN<'a>(&'a mut self) -> &'a mut $T;)+
|
2013-11-29 15:52:38 +01:00
|
|
|
}
|
2013-05-18 22:46:02 +10:00
|
|
|
|
2014-02-16 20:25:28 +11:00
|
|
|
impl<$($T),+> $Tuple<$($T),+> for ($($T,)+) {
|
2013-11-29 15:52:38 +01:00
|
|
|
$(
|
|
|
|
#[inline]
|
2014-02-16 22:19:41 +11:00
|
|
|
#[allow(unused_variable)]
|
|
|
|
fn $valN(self) -> $T {
|
|
|
|
let ($($x,)+) = self; $ret
|
2013-11-29 15:52:38 +01:00
|
|
|
}
|
2012-08-27 16:26:35 -07:00
|
|
|
|
2013-11-29 15:52:38 +01:00
|
|
|
#[inline]
|
2014-02-16 22:19:41 +11:00
|
|
|
#[allow(unused_variable)]
|
|
|
|
fn $refN<'a>(&'a self) -> &'a $T {
|
|
|
|
let ($(ref $x,)+) = *self; $ret
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
#[allow(unused_variable)]
|
|
|
|
fn $mutN<'a>(&'a mut self) -> &'a mut $T {
|
|
|
|
let ($(ref mut $x,)+) = *self; $ret
|
2012-11-14 18:59:30 -08:00
|
|
|
}
|
2013-11-29 15:52:38 +01:00
|
|
|
)+
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<$($T:Clone),+> Clone for ($($T,)+) {
|
|
|
|
fn clone(&self) -> ($($T,)+) {
|
2014-02-16 22:19:41 +11:00
|
|
|
($(self.$refN().clone(),)+)
|
2012-11-14 18:59:30 -08:00
|
|
|
}
|
2013-11-29 15:52:38 +01:00
|
|
|
}
|
2012-08-27 16:26:35 -07:00
|
|
|
|
2013-11-29 15:52:38 +01:00
|
|
|
#[cfg(not(test))]
|
|
|
|
impl<$($T:Eq),+> Eq for ($($T,)+) {
|
|
|
|
#[inline]
|
|
|
|
fn eq(&self, other: &($($T,)+)) -> bool {
|
2014-02-16 22:19:41 +11:00
|
|
|
$(*self.$refN() == *other.$refN())&&+
|
2013-11-29 15:52:38 +01:00
|
|
|
}
|
|
|
|
#[inline]
|
|
|
|
fn ne(&self, other: &($($T,)+)) -> bool {
|
2014-02-16 22:19:41 +11:00
|
|
|
$(*self.$refN() != *other.$refN())||+
|
2012-11-14 18:59:30 -08:00
|
|
|
}
|
2013-11-29 15:52:38 +01:00
|
|
|
}
|
2012-08-27 16:26:35 -07:00
|
|
|
|
2013-11-29 15:52:38 +01:00
|
|
|
#[cfg(not(test))]
|
2014-03-23 22:54:42 +11:00
|
|
|
impl<$($T:TotalEq),+> TotalEq for ($($T,)+) {}
|
2013-05-19 18:51:14 +10:00
|
|
|
|
2013-11-29 15:52:38 +01:00
|
|
|
#[cfg(not(test))]
|
|
|
|
impl<$($T:Ord + Eq),+> Ord for ($($T,)+) {
|
|
|
|
#[inline]
|
|
|
|
fn lt(&self, other: &($($T,)+)) -> bool {
|
2014-02-16 22:19:41 +11:00
|
|
|
lexical_ord!(lt, $(self.$refN(), other.$refN()),+)
|
2013-11-29 15:52:38 +01:00
|
|
|
}
|
|
|
|
#[inline]
|
|
|
|
fn le(&self, other: &($($T,)+)) -> bool {
|
2014-02-16 22:19:41 +11:00
|
|
|
lexical_ord!(le, $(self.$refN(), other.$refN()),+)
|
2013-11-29 15:52:38 +01:00
|
|
|
}
|
|
|
|
#[inline]
|
|
|
|
fn ge(&self, other: &($($T,)+)) -> bool {
|
2014-02-16 22:19:41 +11:00
|
|
|
lexical_ord!(ge, $(self.$refN(), other.$refN()),+)
|
2013-05-18 21:38:06 +10:00
|
|
|
}
|
2013-11-29 15:52:38 +01:00
|
|
|
#[inline]
|
|
|
|
fn gt(&self, other: &($($T,)+)) -> bool {
|
2014-02-16 22:19:41 +11:00
|
|
|
lexical_ord!(gt, $(self.$refN(), other.$refN()),+)
|
2013-11-29 15:52:38 +01:00
|
|
|
}
|
|
|
|
}
|
2013-05-19 18:51:14 +10:00
|
|
|
|
2013-11-29 15:52:38 +01:00
|
|
|
#[cfg(not(test))]
|
|
|
|
impl<$($T:TotalOrd),+> TotalOrd for ($($T,)+) {
|
|
|
|
#[inline]
|
|
|
|
fn cmp(&self, other: &($($T,)+)) -> Ordering {
|
2014-02-16 22:19:41 +11:00
|
|
|
lexical_cmp!($(self.$refN(), other.$refN()),+)
|
2013-05-19 18:51:14 +10:00
|
|
|
}
|
2013-11-29 15:52:38 +01:00
|
|
|
}
|
2013-06-14 18:27:52 -07:00
|
|
|
|
2013-11-29 15:52:38 +01:00
|
|
|
#[cfg(not(test))]
|
|
|
|
impl<$($T:Default),+> Default for ($($T,)+) {
|
|
|
|
#[inline]
|
|
|
|
fn default() -> ($($T,)+) {
|
|
|
|
($({ let x: $T = Default::default(); x},)+)
|
2013-09-11 21:49:25 -07:00
|
|
|
}
|
2013-11-29 15:52:38 +01:00
|
|
|
}
|
|
|
|
)+
|
2013-05-19 18:51:14 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-08 22:07:22 +02:00
|
|
|
// Constructs an expression that performs a lexical ordering using method $rel.
|
|
|
|
// The values are interleaved, so the macro invocation for
|
|
|
|
// `(a1, a2, a3) < (b1, b2, b3)` would be `lexical_ord!(lt, a1, b1, a2, b2,
|
2013-05-19 18:51:14 +10:00
|
|
|
// a3, b3)` (and similarly for `lexical_cmp`)
|
2013-08-08 22:07:22 +02:00
|
|
|
macro_rules! lexical_ord {
|
|
|
|
($rel: ident, $a:expr, $b:expr, $($rest_a:expr, $rest_b:expr),+) => {
|
|
|
|
if *$a != *$b { lexical_ord!($rel, $a, $b) }
|
|
|
|
else { lexical_ord!($rel, $($rest_a, $rest_b),+) }
|
2013-05-19 18:51:14 +10:00
|
|
|
};
|
2013-08-08 22:07:22 +02:00
|
|
|
($rel: ident, $a:expr, $b:expr) => { (*$a) . $rel ($b) };
|
2013-05-19 18:51:14 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! lexical_cmp {
|
|
|
|
($a:expr, $b:expr, $($rest_a:expr, $rest_b:expr),+) => {
|
|
|
|
match ($a).cmp($b) {
|
|
|
|
Equal => lexical_cmp!($($rest_a, $rest_b),+),
|
|
|
|
ordering => ordering
|
|
|
|
}
|
|
|
|
};
|
|
|
|
($a:expr, $b:expr) => { ($a).cmp($b) };
|
|
|
|
}
|
|
|
|
|
|
|
|
tuple_impls! {
|
2014-02-16 20:25:28 +11:00
|
|
|
Tuple1 {
|
2014-02-16 22:19:41 +11:00
|
|
|
(val0, ref0, mut0) -> A { (a) => a }
|
2013-08-08 22:07:21 +02:00
|
|
|
}
|
2014-02-16 20:25:28 +11:00
|
|
|
Tuple2 {
|
2014-02-16 22:19:41 +11:00
|
|
|
(val0, ref0, mut0) -> A { (a, b) => a }
|
|
|
|
(val1, ref1, mut1) -> B { (a, b) => b }
|
2013-05-18 19:43:14 +10:00
|
|
|
}
|
2014-02-16 20:25:28 +11:00
|
|
|
Tuple3 {
|
2014-02-16 22:19:41 +11:00
|
|
|
(val0, ref0, mut0) -> A { (a, b, c) => a }
|
|
|
|
(val1, ref1, mut1) -> B { (a, b, c) => b }
|
|
|
|
(val2, ref2, mut2) -> C { (a, b, c) => c }
|
2013-05-18 19:43:14 +10:00
|
|
|
}
|
2014-02-16 20:25:28 +11:00
|
|
|
Tuple4 {
|
2014-02-16 22:19:41 +11:00
|
|
|
(val0, ref0, mut0) -> A { (a, b, c, d) => a }
|
|
|
|
(val1, ref1, mut1) -> B { (a, b, c, d) => b }
|
|
|
|
(val2, ref2, mut2) -> C { (a, b, c, d) => c }
|
|
|
|
(val3, ref3, mut3) -> D { (a, b, c, d) => d }
|
2013-05-18 19:43:14 +10:00
|
|
|
}
|
2014-02-16 20:25:28 +11:00
|
|
|
Tuple5 {
|
2014-02-16 22:19:41 +11:00
|
|
|
(val0, ref0, mut0) -> A { (a, b, c, d, e) => a }
|
|
|
|
(val1, ref1, mut1) -> B { (a, b, c, d, e) => b }
|
|
|
|
(val2, ref2, mut2) -> C { (a, b, c, d, e) => c }
|
|
|
|
(val3, ref3, mut3) -> D { (a, b, c, d, e) => d }
|
|
|
|
(val4, ref4, mut4) -> E { (a, b, c, d, e) => e }
|
2013-05-18 19:43:14 +10:00
|
|
|
}
|
2014-02-16 20:25:28 +11:00
|
|
|
Tuple6 {
|
2014-02-16 22:19:41 +11:00
|
|
|
(val0, ref0, mut0) -> A { (a, b, c, d, e, f) => a }
|
|
|
|
(val1, ref1, mut1) -> B { (a, b, c, d, e, f) => b }
|
|
|
|
(val2, ref2, mut2) -> C { (a, b, c, d, e, f) => c }
|
|
|
|
(val3, ref3, mut3) -> D { (a, b, c, d, e, f) => d }
|
|
|
|
(val4, ref4, mut4) -> E { (a, b, c, d, e, f) => e }
|
|
|
|
(val5, ref5, mut5) -> F { (a, b, c, d, e, f) => f }
|
2013-05-18 19:43:14 +10:00
|
|
|
}
|
2014-02-16 20:25:28 +11:00
|
|
|
Tuple7 {
|
2014-02-16 22:19:41 +11:00
|
|
|
(val0, ref0, mut0) -> A { (a, b, c, d, e, f, g) => a }
|
|
|
|
(val1, ref1, mut1) -> B { (a, b, c, d, e, f, g) => b }
|
|
|
|
(val2, ref2, mut2) -> C { (a, b, c, d, e, f, g) => c }
|
|
|
|
(val3, ref3, mut3) -> D { (a, b, c, d, e, f, g) => d }
|
|
|
|
(val4, ref4, mut4) -> E { (a, b, c, d, e, f, g) => e }
|
|
|
|
(val5, ref5, mut5) -> F { (a, b, c, d, e, f, g) => f }
|
|
|
|
(val6, ref6, mut6) -> G { (a, b, c, d, e, f, g) => g }
|
2013-05-18 19:43:14 +10:00
|
|
|
}
|
2014-02-16 20:25:28 +11:00
|
|
|
Tuple8 {
|
2014-02-16 22:19:41 +11:00
|
|
|
(val0, ref0, mut0) -> A { (a, b, c, d, e, f, g, h) => a }
|
|
|
|
(val1, ref1, mut1) -> B { (a, b, c, d, e, f, g, h) => b }
|
|
|
|
(val2, ref2, mut2) -> C { (a, b, c, d, e, f, g, h) => c }
|
|
|
|
(val3, ref3, mut3) -> D { (a, b, c, d, e, f, g, h) => d }
|
|
|
|
(val4, ref4, mut4) -> E { (a, b, c, d, e, f, g, h) => e }
|
|
|
|
(val5, ref5, mut5) -> F { (a, b, c, d, e, f, g, h) => f }
|
|
|
|
(val6, ref6, mut6) -> G { (a, b, c, d, e, f, g, h) => g }
|
|
|
|
(val7, ref7, mut7) -> H { (a, b, c, d, e, f, g, h) => h }
|
2013-05-18 19:43:14 +10:00
|
|
|
}
|
2014-02-16 20:25:28 +11:00
|
|
|
Tuple9 {
|
2014-02-16 22:19:41 +11:00
|
|
|
(val0, ref0, mut0) -> A { (a, b, c, d, e, f, g, h, i) => a }
|
|
|
|
(val1, ref1, mut1) -> B { (a, b, c, d, e, f, g, h, i) => b }
|
|
|
|
(val2, ref2, mut2) -> C { (a, b, c, d, e, f, g, h, i) => c }
|
|
|
|
(val3, ref3, mut3) -> D { (a, b, c, d, e, f, g, h, i) => d }
|
|
|
|
(val4, ref4, mut4) -> E { (a, b, c, d, e, f, g, h, i) => e }
|
|
|
|
(val5, ref5, mut5) -> F { (a, b, c, d, e, f, g, h, i) => f }
|
|
|
|
(val6, ref6, mut6) -> G { (a, b, c, d, e, f, g, h, i) => g }
|
|
|
|
(val7, ref7, mut7) -> H { (a, b, c, d, e, f, g, h, i) => h }
|
|
|
|
(val8, ref8, mut8) -> I { (a, b, c, d, e, f, g, h, i) => i }
|
2013-05-18 19:43:14 +10:00
|
|
|
}
|
2014-02-16 20:25:28 +11:00
|
|
|
Tuple10 {
|
2014-02-16 22:19:41 +11:00
|
|
|
(val0, ref0, mut0) -> A { (a, b, c, d, e, f, g, h, i, j) => a }
|
|
|
|
(val1, ref1, mut1) -> B { (a, b, c, d, e, f, g, h, i, j) => b }
|
|
|
|
(val2, ref2, mut2) -> C { (a, b, c, d, e, f, g, h, i, j) => c }
|
|
|
|
(val3, ref3, mut3) -> D { (a, b, c, d, e, f, g, h, i, j) => d }
|
|
|
|
(val4, ref4, mut4) -> E { (a, b, c, d, e, f, g, h, i, j) => e }
|
|
|
|
(val5, ref5, mut5) -> F { (a, b, c, d, e, f, g, h, i, j) => f }
|
|
|
|
(val6, ref6, mut6) -> G { (a, b, c, d, e, f, g, h, i, j) => g }
|
|
|
|
(val7, ref7, mut7) -> H { (a, b, c, d, e, f, g, h, i, j) => h }
|
|
|
|
(val8, ref8, mut8) -> I { (a, b, c, d, e, f, g, h, i, j) => i }
|
|
|
|
(val9, ref9, mut9) -> J { (a, b, c, d, e, f, g, h, i, j) => j }
|
2013-05-18 19:43:14 +10:00
|
|
|
}
|
2014-02-16 20:25:28 +11:00
|
|
|
Tuple11 {
|
2014-02-16 22:19:41 +11:00
|
|
|
(val0, ref0, mut0) -> A { (a, b, c, d, e, f, g, h, i, j, k) => a }
|
|
|
|
(val1, ref1, mut1) -> B { (a, b, c, d, e, f, g, h, i, j, k) => b }
|
|
|
|
(val2, ref2, mut2) -> C { (a, b, c, d, e, f, g, h, i, j, k) => c }
|
|
|
|
(val3, ref3, mut3) -> D { (a, b, c, d, e, f, g, h, i, j, k) => d }
|
|
|
|
(val4, ref4, mut4) -> E { (a, b, c, d, e, f, g, h, i, j, k) => e }
|
|
|
|
(val5, ref5, mut5) -> F { (a, b, c, d, e, f, g, h, i, j, k) => f }
|
|
|
|
(val6, ref6, mut6) -> G { (a, b, c, d, e, f, g, h, i, j, k) => g }
|
|
|
|
(val7, ref7, mut7) -> H { (a, b, c, d, e, f, g, h, i, j, k) => h }
|
|
|
|
(val8, ref8, mut8) -> I { (a, b, c, d, e, f, g, h, i, j, k) => i }
|
|
|
|
(val9, ref9, mut9) -> J { (a, b, c, d, e, f, g, h, i, j, k) => j }
|
|
|
|
(val10, ref10, mut10) -> K { (a, b, c, d, e, f, g, h, i, j, k) => k }
|
2013-05-18 19:43:14 +10:00
|
|
|
}
|
2014-02-16 20:25:28 +11:00
|
|
|
Tuple12 {
|
2014-02-16 22:19:41 +11:00
|
|
|
(val0, ref0, mut0) -> A { (a, b, c, d, e, f, g, h, i, j, k, l) => a }
|
|
|
|
(val1, ref1, mut1) -> B { (a, b, c, d, e, f, g, h, i, j, k, l) => b }
|
|
|
|
(val2, ref2, mut2) -> C { (a, b, c, d, e, f, g, h, i, j, k, l) => c }
|
|
|
|
(val3, ref3, mut3) -> D { (a, b, c, d, e, f, g, h, i, j, k, l) => d }
|
|
|
|
(val4, ref4, mut4) -> E { (a, b, c, d, e, f, g, h, i, j, k, l) => e }
|
|
|
|
(val5, ref5, mut5) -> F { (a, b, c, d, e, f, g, h, i, j, k, l) => f }
|
|
|
|
(val6, ref6, mut6) -> G { (a, b, c, d, e, f, g, h, i, j, k, l) => g }
|
|
|
|
(val7, ref7, mut7) -> H { (a, b, c, d, e, f, g, h, i, j, k, l) => h }
|
|
|
|
(val8, ref8, mut8) -> I { (a, b, c, d, e, f, g, h, i, j, k, l) => i }
|
|
|
|
(val9, ref9, mut9) -> J { (a, b, c, d, e, f, g, h, i, j, k, l) => j }
|
|
|
|
(val10, ref10, mut10) -> K { (a, b, c, d, e, f, g, h, i, j, k, l) => k }
|
|
|
|
(val11, ref11, mut11) -> L { (a, b, c, d, e, f, g, h, i, j, k, l) => l }
|
2013-05-18 19:43:14 +10:00
|
|
|
}
|
2013-05-19 18:51:14 +10:00
|
|
|
}
|
2013-05-18 18:59:16 +10:00
|
|
|
|
2013-05-19 02:23:52 +10:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
use clone::Clone;
|
2013-05-19 18:51:14 +10:00
|
|
|
use cmp::*;
|
2014-05-01 18:06:59 -07:00
|
|
|
use realstd::str::StrAllocating;
|
2013-05-19 02:23:52 +10:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_clone() {
|
2014-04-15 18:17:48 -07:00
|
|
|
let a = (1, "2".to_owned());
|
2013-05-19 02:23:52 +10:00
|
|
|
let b = a.clone();
|
2014-02-16 20:36:43 +11:00
|
|
|
assert_eq!(a, b);
|
2013-05-19 02:23:52 +10:00
|
|
|
}
|
2013-05-18 18:59:16 +10:00
|
|
|
|
2013-05-19 02:23:52 +10:00
|
|
|
#[test]
|
2014-02-16 22:19:41 +11:00
|
|
|
fn test_getters() {
|
|
|
|
macro_rules! test_getter(
|
|
|
|
($x:expr, $valN:ident, $refN:ident, $mutN:ident,
|
|
|
|
$init:expr, $incr:expr, $result:expr) => ({
|
|
|
|
assert_eq!($x.$valN(), $init);
|
|
|
|
assert_eq!(*$x.$refN(), $init);
|
|
|
|
*$x.$mutN() += $incr;
|
|
|
|
assert_eq!(*$x.$refN(), $result);
|
|
|
|
})
|
|
|
|
)
|
|
|
|
let mut x = (0u8, 1u16, 2u32, 3u64, 4u, 5i8, 6i16, 7i32, 8i64, 9i, 10f32, 11f64);
|
|
|
|
test_getter!(x, val0, ref0, mut0, 0, 1, 1);
|
|
|
|
test_getter!(x, val1, ref1, mut1, 1, 1, 2);
|
|
|
|
test_getter!(x, val2, ref2, mut2, 2, 1, 3);
|
|
|
|
test_getter!(x, val3, ref3, mut3, 3, 1, 4);
|
|
|
|
test_getter!(x, val4, ref4, mut4, 4, 1, 5);
|
|
|
|
test_getter!(x, val5, ref5, mut5, 5, 1, 6);
|
|
|
|
test_getter!(x, val6, ref6, mut6, 6, 1, 7);
|
|
|
|
test_getter!(x, val7, ref7, mut7, 7, 1, 8);
|
|
|
|
test_getter!(x, val8, ref8, mut8, 8, 1, 9);
|
|
|
|
test_getter!(x, val9, ref9, mut9, 9, 1, 10);
|
|
|
|
test_getter!(x, val10, ref10, mut10, 10.0, 1.0, 11.0);
|
|
|
|
test_getter!(x, val11, ref11, mut11, 11.0, 1.0, 12.0);
|
2013-05-19 02:23:52 +10:00
|
|
|
}
|
2013-05-19 18:51:14 +10:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tuple_cmp() {
|
2013-06-04 21:43:41 -07:00
|
|
|
let (small, big) = ((1u, 2u, 3u), (3u, 2u, 1u));
|
2013-05-19 18:51:14 +10:00
|
|
|
|
2013-08-08 22:07:22 +02:00
|
|
|
let nan = 0.0/0.0;
|
|
|
|
|
2013-05-19 18:51:14 +10:00
|
|
|
// Eq
|
|
|
|
assert_eq!(small, small);
|
|
|
|
assert_eq!(big, big);
|
|
|
|
assert!(small != big);
|
|
|
|
assert!(big != small);
|
|
|
|
|
|
|
|
// Ord
|
|
|
|
assert!(small < big);
|
|
|
|
assert!(!(small < small));
|
|
|
|
assert!(!(big < small));
|
|
|
|
assert!(!(big < big));
|
|
|
|
|
|
|
|
assert!(small <= small);
|
|
|
|
assert!(big <= big);
|
|
|
|
|
|
|
|
assert!(big > small);
|
|
|
|
assert!(small >= small);
|
|
|
|
assert!(big >= small);
|
|
|
|
assert!(big >= big);
|
|
|
|
|
2013-08-08 22:07:22 +02:00
|
|
|
assert!(!((1.0, 2.0) < (nan, 3.0)));
|
|
|
|
assert!(!((1.0, 2.0) <= (nan, 3.0)));
|
|
|
|
assert!(!((1.0, 2.0) > (nan, 3.0)));
|
|
|
|
assert!(!((1.0, 2.0) >= (nan, 3.0)));
|
|
|
|
assert!(((1.0, 2.0) < (2.0, nan)));
|
|
|
|
assert!(!((2.0, 2.0) < (2.0, nan)));
|
|
|
|
|
2013-05-19 18:51:14 +10:00
|
|
|
// TotalOrd
|
2014-02-28 01:23:06 -08:00
|
|
|
assert!(small.cmp(&small) == Equal);
|
|
|
|
assert!(big.cmp(&big) == Equal);
|
|
|
|
assert!(small.cmp(&big) == Less);
|
|
|
|
assert!(big.cmp(&small) == Greater);
|
2013-05-19 18:51:14 +10:00
|
|
|
}
|
2014-02-15 01:20:43 +11:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_show() {
|
2014-04-15 18:17:48 -07:00
|
|
|
assert_eq!(format!("{}", (1,)), "(1,)".to_owned());
|
|
|
|
assert_eq!(format!("{}", (1, true)), "(1, true)".to_owned());
|
|
|
|
assert_eq!(format!("{}", (1, "hi".to_owned(), true)), "(1, hi, true)".to_owned());
|
2014-02-15 01:20:43 +11:00
|
|
|
}
|
2013-05-18 18:59:16 +10:00
|
|
|
}
|