Merge pull request #16 from gifnksm/master

Convert statics to constants
This commit is contained in:
Alex Crichton 2014-10-10 09:59:47 -05:00
commit 5e2ece2f6f
3 changed files with 98 additions and 98 deletions

View File

@ -75,7 +75,7 @@ pub type BigDigit = u32;
/// size is the double of the size of `BigDigit`. /// size is the double of the size of `BigDigit`.
pub type DoubleBigDigit = u64; pub type DoubleBigDigit = u64;
pub static ZERO_BIG_DIGIT: BigDigit = 0; pub const ZERO_BIG_DIGIT: BigDigit = 0;
static ZERO_VEC: [BigDigit, ..1] = [ZERO_BIG_DIGIT]; static ZERO_VEC: [BigDigit, ..1] = [ZERO_BIG_DIGIT];
#[allow(non_snake_case)] #[allow(non_snake_case)]
@ -84,15 +84,15 @@ pub mod BigDigit {
use super::DoubleBigDigit; use super::DoubleBigDigit;
// `DoubleBigDigit` size dependent // `DoubleBigDigit` size dependent
pub static bits: uint = 32; pub const bits: uint = 32;
pub static base: DoubleBigDigit = 1 << bits; pub const base: DoubleBigDigit = 1 << bits;
static lo_mask: DoubleBigDigit = (-1 as DoubleBigDigit) >> bits; const LO_MASK: DoubleBigDigit = (-1 as DoubleBigDigit) >> bits;
#[inline] #[inline]
fn get_hi(n: DoubleBigDigit) -> BigDigit { (n >> bits) as BigDigit } fn get_hi(n: DoubleBigDigit) -> BigDigit { (n >> bits) as BigDigit }
#[inline] #[inline]
fn get_lo(n: DoubleBigDigit) -> BigDigit { (n & lo_mask) as BigDigit } fn get_lo(n: DoubleBigDigit) -> BigDigit { (n & LO_MASK) as BigDigit }
/// Split one `DoubleBigDigit` into two `BigDigit`s. /// Split one `DoubleBigDigit` into two `BigDigit`s.
#[inline] #[inline]
@ -1839,7 +1839,7 @@ mod biguint_tests {
BigInt::from_biguint(Plus, BigUint::new(vec!(1,2,3)))); BigInt::from_biguint(Plus, BigUint::new(vec!(1,2,3))));
} }
static sum_triples: &'static [(&'static [BigDigit], const SUM_TRIPLES: &'static [(&'static [BigDigit],
&'static [BigDigit], &'static [BigDigit],
&'static [BigDigit])] = &[ &'static [BigDigit])] = &[
(&[], &[], &[]), (&[], &[], &[]),
@ -1855,7 +1855,7 @@ mod biguint_tests {
#[test] #[test]
fn test_add() { fn test_add() {
for elm in sum_triples.iter() { for elm in SUM_TRIPLES.iter() {
let (a_vec, b_vec, c_vec) = *elm; let (a_vec, b_vec, c_vec) = *elm;
let a = BigUint::from_slice(a_vec); let a = BigUint::from_slice(a_vec);
let b = BigUint::from_slice(b_vec); let b = BigUint::from_slice(b_vec);
@ -1868,7 +1868,7 @@ mod biguint_tests {
#[test] #[test]
fn test_sub() { fn test_sub() {
for elm in sum_triples.iter() { for elm in SUM_TRIPLES.iter() {
let (a_vec, b_vec, c_vec) = *elm; let (a_vec, b_vec, c_vec) = *elm;
let a = BigUint::from_slice(a_vec); let a = BigUint::from_slice(a_vec);
let b = BigUint::from_slice(b_vec); let b = BigUint::from_slice(b_vec);
@ -1886,7 +1886,7 @@ mod biguint_tests {
a - b; a - b;
} }
static mul_triples: &'static [(&'static [BigDigit], const MUL_TRIPLES: &'static [(&'static [BigDigit],
&'static [BigDigit], &'static [BigDigit],
&'static [BigDigit])] = &[ &'static [BigDigit])] = &[
(&[], &[], &[]), (&[], &[], &[]),
@ -1912,7 +1912,7 @@ mod biguint_tests {
(&[ 0, 0, 1], &[ 0, 0, 0, 1], &[0, 0, 0, 0, 0, 1]) (&[ 0, 0, 1], &[ 0, 0, 0, 1], &[0, 0, 0, 0, 0, 1])
]; ];
static div_rem_quadruples: &'static [(&'static [BigDigit], const DIV_REM_QUADRUPLES: &'static [(&'static [BigDigit],
&'static [BigDigit], &'static [BigDigit],
&'static [BigDigit], &'static [BigDigit],
&'static [BigDigit])] &'static [BigDigit])]
@ -1926,7 +1926,7 @@ mod biguint_tests {
#[test] #[test]
fn test_mul() { fn test_mul() {
for elm in mul_triples.iter() { for elm in MUL_TRIPLES.iter() {
let (a_vec, b_vec, c_vec) = *elm; let (a_vec, b_vec, c_vec) = *elm;
let a = BigUint::from_slice(a_vec); let a = BigUint::from_slice(a_vec);
let b = BigUint::from_slice(b_vec); let b = BigUint::from_slice(b_vec);
@ -1936,7 +1936,7 @@ mod biguint_tests {
assert!(b * a == c); assert!(b * a == c);
} }
for elm in div_rem_quadruples.iter() { for elm in DIV_REM_QUADRUPLES.iter() {
let (a_vec, b_vec, c_vec, d_vec) = *elm; let (a_vec, b_vec, c_vec, d_vec) = *elm;
let a = BigUint::from_slice(a_vec); let a = BigUint::from_slice(a_vec);
let b = BigUint::from_slice(b_vec); let b = BigUint::from_slice(b_vec);
@ -1950,7 +1950,7 @@ mod biguint_tests {
#[test] #[test]
fn test_div_rem() { fn test_div_rem() {
for elm in mul_triples.iter() { for elm in MUL_TRIPLES.iter() {
let (a_vec, b_vec, c_vec) = *elm; let (a_vec, b_vec, c_vec) = *elm;
let a = BigUint::from_slice(a_vec); let a = BigUint::from_slice(a_vec);
let b = BigUint::from_slice(b_vec); let b = BigUint::from_slice(b_vec);
@ -1964,7 +1964,7 @@ mod biguint_tests {
} }
} }
for elm in div_rem_quadruples.iter() { for elm in DIV_REM_QUADRUPLES.iter() {
let (a_vec, b_vec, c_vec, d_vec) = *elm; let (a_vec, b_vec, c_vec, d_vec) = *elm;
let a = BigUint::from_slice(a_vec); let a = BigUint::from_slice(a_vec);
let b = BigUint::from_slice(b_vec); let b = BigUint::from_slice(b_vec);
@ -1977,7 +1977,7 @@ mod biguint_tests {
#[test] #[test]
fn test_checked_add() { fn test_checked_add() {
for elm in sum_triples.iter() { for elm in SUM_TRIPLES.iter() {
let (a_vec, b_vec, c_vec) = *elm; let (a_vec, b_vec, c_vec) = *elm;
let a = BigUint::from_slice(a_vec); let a = BigUint::from_slice(a_vec);
let b = BigUint::from_slice(b_vec); let b = BigUint::from_slice(b_vec);
@ -1990,7 +1990,7 @@ mod biguint_tests {
#[test] #[test]
fn test_checked_sub() { fn test_checked_sub() {
for elm in sum_triples.iter() { for elm in SUM_TRIPLES.iter() {
let (a_vec, b_vec, c_vec) = *elm; let (a_vec, b_vec, c_vec) = *elm;
let a = BigUint::from_slice(a_vec); let a = BigUint::from_slice(a_vec);
let b = BigUint::from_slice(b_vec); let b = BigUint::from_slice(b_vec);
@ -2010,7 +2010,7 @@ mod biguint_tests {
#[test] #[test]
fn test_checked_mul() { fn test_checked_mul() {
for elm in mul_triples.iter() { for elm in MUL_TRIPLES.iter() {
let (a_vec, b_vec, c_vec) = *elm; let (a_vec, b_vec, c_vec) = *elm;
let a = BigUint::from_slice(a_vec); let a = BigUint::from_slice(a_vec);
let b = BigUint::from_slice(b_vec); let b = BigUint::from_slice(b_vec);
@ -2020,7 +2020,7 @@ mod biguint_tests {
assert!(b.checked_mul(&a).unwrap() == c); assert!(b.checked_mul(&a).unwrap() == c);
} }
for elm in div_rem_quadruples.iter() { for elm in DIV_REM_QUADRUPLES.iter() {
let (a_vec, b_vec, c_vec, d_vec) = *elm; let (a_vec, b_vec, c_vec, d_vec) = *elm;
let a = BigUint::from_slice(a_vec); let a = BigUint::from_slice(a_vec);
let b = BigUint::from_slice(b_vec); let b = BigUint::from_slice(b_vec);
@ -2034,7 +2034,7 @@ mod biguint_tests {
#[test] #[test]
fn test_checked_div() { fn test_checked_div() {
for elm in mul_triples.iter() { for elm in MUL_TRIPLES.iter() {
let (a_vec, b_vec, c_vec) = *elm; let (a_vec, b_vec, c_vec) = *elm;
let a = BigUint::from_slice(a_vec); let a = BigUint::from_slice(a_vec);
let b = BigUint::from_slice(b_vec); let b = BigUint::from_slice(b_vec);
@ -2438,7 +2438,7 @@ mod bigint_tests {
assert_eq!(negative.to_biguint(), None); assert_eq!(negative.to_biguint(), None);
} }
static sum_triples: &'static [(&'static [BigDigit], const SUM_TRIPLES: &'static [(&'static [BigDigit],
&'static [BigDigit], &'static [BigDigit],
&'static [BigDigit])] = &[ &'static [BigDigit])] = &[
(&[], &[], &[]), (&[], &[], &[]),
@ -2454,7 +2454,7 @@ mod bigint_tests {
#[test] #[test]
fn test_add() { fn test_add() {
for elm in sum_triples.iter() { for elm in SUM_TRIPLES.iter() {
let (a_vec, b_vec, c_vec) = *elm; let (a_vec, b_vec, c_vec) = *elm;
let a = BigInt::from_slice(Plus, a_vec); let a = BigInt::from_slice(Plus, a_vec);
let b = BigInt::from_slice(Plus, b_vec); let b = BigInt::from_slice(Plus, b_vec);
@ -2473,7 +2473,7 @@ mod bigint_tests {
#[test] #[test]
fn test_sub() { fn test_sub() {
for elm in sum_triples.iter() { for elm in SUM_TRIPLES.iter() {
let (a_vec, b_vec, c_vec) = *elm; let (a_vec, b_vec, c_vec) = *elm;
let a = BigInt::from_slice(Plus, a_vec); let a = BigInt::from_slice(Plus, a_vec);
let b = BigInt::from_slice(Plus, b_vec); let b = BigInt::from_slice(Plus, b_vec);
@ -2490,7 +2490,7 @@ mod bigint_tests {
} }
} }
static mul_triples: &'static [(&'static [BigDigit], static MUL_TRIPLES: &'static [(&'static [BigDigit],
&'static [BigDigit], &'static [BigDigit],
&'static [BigDigit])] = &[ &'static [BigDigit])] = &[
(&[], &[], &[]), (&[], &[], &[]),
@ -2516,7 +2516,7 @@ mod bigint_tests {
(&[ 0, 0, 1], &[ 0, 0, 0, 1], &[0, 0, 0, 0, 0, 1]) (&[ 0, 0, 1], &[ 0, 0, 0, 1], &[0, 0, 0, 0, 0, 1])
]; ];
static div_rem_quadruples: &'static [(&'static [BigDigit], static DIV_REM_QUADRUPLES: &'static [(&'static [BigDigit],
&'static [BigDigit], &'static [BigDigit],
&'static [BigDigit], &'static [BigDigit],
&'static [BigDigit])] &'static [BigDigit])]
@ -2530,7 +2530,7 @@ mod bigint_tests {
#[test] #[test]
fn test_mul() { fn test_mul() {
for elm in mul_triples.iter() { for elm in MUL_TRIPLES.iter() {
let (a_vec, b_vec, c_vec) = *elm; let (a_vec, b_vec, c_vec) = *elm;
let a = BigInt::from_slice(Plus, a_vec); let a = BigInt::from_slice(Plus, a_vec);
let b = BigInt::from_slice(Plus, b_vec); let b = BigInt::from_slice(Plus, b_vec);
@ -2543,7 +2543,7 @@ mod bigint_tests {
assert!((-b) * a == -c); assert!((-b) * a == -c);
} }
for elm in div_rem_quadruples.iter() { for elm in DIV_REM_QUADRUPLES.iter() {
let (a_vec, b_vec, c_vec, d_vec) = *elm; let (a_vec, b_vec, c_vec, d_vec) = *elm;
let a = BigInt::from_slice(Plus, a_vec); let a = BigInt::from_slice(Plus, a_vec);
let b = BigInt::from_slice(Plus, b_vec); let b = BigInt::from_slice(Plus, b_vec);
@ -2582,7 +2582,7 @@ mod bigint_tests {
} }
} }
for elm in mul_triples.iter() { for elm in MUL_TRIPLES.iter() {
let (a_vec, b_vec, c_vec) = *elm; let (a_vec, b_vec, c_vec) = *elm;
let a = BigInt::from_slice(Plus, a_vec); let a = BigInt::from_slice(Plus, a_vec);
let b = BigInt::from_slice(Plus, b_vec); let b = BigInt::from_slice(Plus, b_vec);
@ -2592,7 +2592,7 @@ mod bigint_tests {
if !b.is_zero() { check(&c, &b, &a, &Zero::zero()); } if !b.is_zero() { check(&c, &b, &a, &Zero::zero()); }
} }
for elm in div_rem_quadruples.iter() { for elm in DIV_REM_QUADRUPLES.iter() {
let (a_vec, b_vec, c_vec, d_vec) = *elm; let (a_vec, b_vec, c_vec, d_vec) = *elm;
let a = BigInt::from_slice(Plus, a_vec); let a = BigInt::from_slice(Plus, a_vec);
let b = BigInt::from_slice(Plus, b_vec); let b = BigInt::from_slice(Plus, b_vec);
@ -2625,7 +2625,7 @@ mod bigint_tests {
check_sub(&a.neg(), b, &q.neg(), &r.neg()); check_sub(&a.neg(), b, &q.neg(), &r.neg());
check_sub(&a.neg(), &b.neg(), q, &r.neg()); check_sub(&a.neg(), &b.neg(), q, &r.neg());
} }
for elm in mul_triples.iter() { for elm in MUL_TRIPLES.iter() {
let (a_vec, b_vec, c_vec) = *elm; let (a_vec, b_vec, c_vec) = *elm;
let a = BigInt::from_slice(Plus, a_vec); let a = BigInt::from_slice(Plus, a_vec);
let b = BigInt::from_slice(Plus, b_vec); let b = BigInt::from_slice(Plus, b_vec);
@ -2635,7 +2635,7 @@ mod bigint_tests {
if !b.is_zero() { check(&c, &b, &a, &Zero::zero()); } if !b.is_zero() { check(&c, &b, &a, &Zero::zero()); }
} }
for elm in div_rem_quadruples.iter() { for elm in DIV_REM_QUADRUPLES.iter() {
let (a_vec, b_vec, c_vec, d_vec) = *elm; let (a_vec, b_vec, c_vec, d_vec) = *elm;
let a = BigInt::from_slice(Plus, a_vec); let a = BigInt::from_slice(Plus, a_vec);
let b = BigInt::from_slice(Plus, b_vec); let b = BigInt::from_slice(Plus, b_vec);
@ -2650,7 +2650,7 @@ mod bigint_tests {
#[test] #[test]
fn test_checked_add() { fn test_checked_add() {
for elm in sum_triples.iter() { for elm in SUM_TRIPLES.iter() {
let (a_vec, b_vec, c_vec) = *elm; let (a_vec, b_vec, c_vec) = *elm;
let a = BigInt::from_slice(Plus, a_vec); let a = BigInt::from_slice(Plus, a_vec);
let b = BigInt::from_slice(Plus, b_vec); let b = BigInt::from_slice(Plus, b_vec);
@ -2669,7 +2669,7 @@ mod bigint_tests {
#[test] #[test]
fn test_checked_sub() { fn test_checked_sub() {
for elm in sum_triples.iter() { for elm in SUM_TRIPLES.iter() {
let (a_vec, b_vec, c_vec) = *elm; let (a_vec, b_vec, c_vec) = *elm;
let a = BigInt::from_slice(Plus, a_vec); let a = BigInt::from_slice(Plus, a_vec);
let b = BigInt::from_slice(Plus, b_vec); let b = BigInt::from_slice(Plus, b_vec);
@ -2688,7 +2688,7 @@ mod bigint_tests {
#[test] #[test]
fn test_checked_mul() { fn test_checked_mul() {
for elm in mul_triples.iter() { for elm in MUL_TRIPLES.iter() {
let (a_vec, b_vec, c_vec) = *elm; let (a_vec, b_vec, c_vec) = *elm;
let a = BigInt::from_slice(Plus, a_vec); let a = BigInt::from_slice(Plus, a_vec);
let b = BigInt::from_slice(Plus, b_vec); let b = BigInt::from_slice(Plus, b_vec);
@ -2701,7 +2701,7 @@ mod bigint_tests {
assert!((-b).checked_mul(&a).unwrap() == -c); assert!((-b).checked_mul(&a).unwrap() == -c);
} }
for elm in div_rem_quadruples.iter() { for elm in DIV_REM_QUADRUPLES.iter() {
let (a_vec, b_vec, c_vec, d_vec) = *elm; let (a_vec, b_vec, c_vec, d_vec) = *elm;
let a = BigInt::from_slice(Plus, a_vec); let a = BigInt::from_slice(Plus, a_vec);
let b = BigInt::from_slice(Plus, b_vec); let b = BigInt::from_slice(Plus, b_vec);
@ -2714,7 +2714,7 @@ mod bigint_tests {
} }
#[test] #[test]
fn test_checked_div() { fn test_checked_div() {
for elm in mul_triples.iter() { for elm in MUL_TRIPLES.iter() {
let (a_vec, b_vec, c_vec) = *elm; let (a_vec, b_vec, c_vec) = *elm;
let a = BigInt::from_slice(Plus, a_vec); let a = BigInt::from_slice(Plus, a_vec);
let b = BigInt::from_slice(Plus, b_vec); let b = BigInt::from_slice(Plus, b_vec);

View File

@ -194,13 +194,13 @@ mod test {
use std::num::{Zero, One, Float}; use std::num::{Zero, One, Float};
use std::hash::hash; use std::hash::hash;
pub static _0_0i : Complex64 = Complex { re: 0.0, im: 0.0 }; pub const _0_0i : Complex64 = Complex { re: 0.0, im: 0.0 };
pub static _1_0i : Complex64 = Complex { re: 1.0, im: 0.0 }; pub const _1_0i : Complex64 = Complex { re: 1.0, im: 0.0 };
pub static _1_1i : Complex64 = Complex { re: 1.0, im: 1.0 }; pub const _1_1i : Complex64 = Complex { re: 1.0, im: 1.0 };
pub static _0_1i : Complex64 = Complex { re: 0.0, im: 1.0 }; pub const _0_1i : Complex64 = Complex { re: 0.0, im: 1.0 };
pub static _neg1_1i : Complex64 = Complex { re: -1.0, im: 1.0 }; pub const _neg1_1i : Complex64 = Complex { re: -1.0, im: 1.0 };
pub static _05_05i : Complex64 = Complex { re: 0.5, im: 0.5 }; pub const _05_05i : Complex64 = Complex { re: 0.5, im: 0.5 };
pub static all_consts : [Complex64, .. 5] = [_0_0i, _1_0i, _1_1i, _neg1_1i, _05_05i]; pub const all_consts : [Complex64, .. 5] = [_0_0i, _1_0i, _1_1i, _neg1_1i, _05_05i];
#[test] #[test]
fn test_consts() { fn test_consts() {
@ -219,7 +219,7 @@ mod test {
} }
#[test] #[test]
#[ignore(cfg(target_arch = "x86"))] #[cfg_attr(target_arch = "x86", ignore)]
// FIXME #7158: (maybe?) currently failing on x86. // FIXME #7158: (maybe?) currently failing on x86.
fn test_norm() { fn test_norm() {
fn test(c: Complex64, ns: f64) { fn test(c: Complex64, ns: f64) {

View File

@ -401,16 +401,16 @@ mod test {
use std::num; use std::num;
use std::i32; use std::i32;
pub static _0 : Rational = Ratio { numer: 0, denom: 1}; pub const _0 : Rational = Ratio { numer: 0, denom: 1};
pub static _1 : Rational = Ratio { numer: 1, denom: 1}; pub const _1 : Rational = Ratio { numer: 1, denom: 1};
pub static _2: Rational = Ratio { numer: 2, denom: 1}; pub const _2: Rational = Ratio { numer: 2, denom: 1};
pub static _1_2: Rational = Ratio { numer: 1, denom: 2}; pub const _1_2: Rational = Ratio { numer: 1, denom: 2};
pub static _3_2: Rational = Ratio { numer: 3, denom: 2}; pub const _3_2: Rational = Ratio { numer: 3, denom: 2};
pub static _neg1_2: Rational = Ratio { numer: -1, denom: 2}; pub const _NEG1_2: Rational = Ratio { numer: -1, denom: 2};
pub static _1_3: Rational = Ratio { numer: 1, denom: 3}; pub const _1_3: Rational = Ratio { numer: 1, denom: 3};
pub static _neg1_3: Rational = Ratio { numer: -1, denom: 3}; pub const _NEG1_3: Rational = Ratio { numer: -1, denom: 3};
pub static _2_3: Rational = Ratio { numer: 2, denom: 3}; pub const _2_3: Rational = Ratio { numer: 2, denom: 3};
pub static _neg2_3: Rational = Ratio { numer: -2, denom: 3}; pub const _NEG2_3: Rational = Ratio { numer: -2, denom: 3};
pub fn to_big(n: Rational) -> BigRational { pub fn to_big(n: Rational) -> BigRational {
Ratio::new( Ratio::new(
@ -427,7 +427,7 @@ mod test {
assert_eq!(_2, Ratio::from_integer(2i)); assert_eq!(_2, Ratio::from_integer(2i));
assert_eq!(_1_2, Ratio::new(1i,2i)); assert_eq!(_1_2, Ratio::new(1i,2i));
assert_eq!(_3_2, Ratio::new(3i,2i)); assert_eq!(_3_2, Ratio::new(3i,2i));
assert_eq!(_neg1_2, Ratio::new(-1i,2i)); assert_eq!(_NEG1_2, Ratio::new(-1i,2i));
} }
#[test] #[test]
@ -465,7 +465,7 @@ mod test {
assert_eq!(_2.to_integer(), 2); assert_eq!(_2.to_integer(), 2);
assert_eq!(_1_2.to_integer(), 0); assert_eq!(_1_2.to_integer(), 0);
assert_eq!(_3_2.to_integer(), 1); assert_eq!(_3_2.to_integer(), 1);
assert_eq!(_neg1_2.to_integer(), 0); assert_eq!(_NEG1_2.to_integer(), 0);
} }
@ -476,7 +476,7 @@ mod test {
assert_eq!(_2.numer(), &2); assert_eq!(_2.numer(), &2);
assert_eq!(_1_2.numer(), &1); assert_eq!(_1_2.numer(), &1);
assert_eq!(_3_2.numer(), &3); assert_eq!(_3_2.numer(), &3);
assert_eq!(_neg1_2.numer(), &(-1)); assert_eq!(_NEG1_2.numer(), &(-1));
} }
#[test] #[test]
fn test_denom() { fn test_denom() {
@ -485,7 +485,7 @@ mod test {
assert_eq!(_2.denom(), &1); assert_eq!(_2.denom(), &1);
assert_eq!(_1_2.denom(), &2); assert_eq!(_1_2.denom(), &2);
assert_eq!(_3_2.denom(), &2); assert_eq!(_3_2.denom(), &2);
assert_eq!(_neg1_2.denom(), &2); assert_eq!(_NEG1_2.denom(), &2);
} }
@ -496,7 +496,7 @@ mod test {
assert!(_2.is_integer()); assert!(_2.is_integer());
assert!(!_1_2.is_integer()); assert!(!_1_2.is_integer());
assert!(!_3_2.is_integer()); assert!(!_3_2.is_integer());
assert!(!_neg1_2.is_integer()); assert!(!_NEG1_2.is_integer());
} }
#[test] #[test]
@ -508,7 +508,7 @@ mod test {
} }
mod arith { mod arith {
use super::{_0, _1, _2, _1_2, _3_2, _neg1_2, to_big}; use super::{_0, _1, _2, _1_2, _3_2, _NEG1_2, to_big};
use super::super::{Ratio, Rational}; use super::super::{Ratio, Rational};
#[test] #[test]
@ -521,7 +521,7 @@ mod test {
test(_1, _1_2, _3_2); test(_1, _1_2, _3_2);
test(_1, _1, _2); test(_1, _1, _2);
test(_1_2, _3_2, _2); test(_1_2, _3_2, _2);
test(_1_2, _neg1_2, _0); test(_1_2, _NEG1_2, _0);
} }
#[test] #[test]
@ -533,7 +533,7 @@ mod test {
test(_1, _1_2, _1_2); test(_1, _1_2, _1_2);
test(_3_2, _1_2, _1); test(_3_2, _1_2, _1);
test(_1, _neg1_2, _3_2); test(_1, _NEG1_2, _3_2);
} }
#[test] #[test]
@ -545,7 +545,7 @@ mod test {
test(_1, _1_2, _1_2); test(_1, _1_2, _1_2);
test(_1_2, _3_2, Ratio::new(3i,4i)); test(_1_2, _3_2, Ratio::new(3i,4i));
test(_1_2, _neg1_2, Ratio::new(-1i, 4i)); test(_1_2, _NEG1_2, Ratio::new(-1i, 4i));
} }
#[test] #[test]
@ -557,7 +557,7 @@ mod test {
test(_1, _1_2, _2); test(_1, _1_2, _2);
test(_3_2, _1_2, _1 + _2); test(_3_2, _1_2, _1 + _2);
test(_1, _neg1_2, _neg1_2 + _neg1_2 + _neg1_2 + _neg1_2); test(_1, _NEG1_2, _NEG1_2 + _NEG1_2 + _NEG1_2 + _NEG1_2);
} }
#[test] #[test]
@ -568,7 +568,7 @@ mod test {
} }
test(_3_2, _1, _1_2); test(_3_2, _1, _1_2);
test(_2, _neg1_2, _0); test(_2, _NEG1_2, _0);
test(_1_2, _2, _1_2); test(_1_2, _2, _1_2);
} }
@ -580,7 +580,7 @@ mod test {
} }
test(_0, _0); test(_0, _0);
test(_1_2, _neg1_2); test(_1_2, _NEG1_2);
test(-_1, _1); test(-_1, _1);
} }
#[test] #[test]
@ -588,7 +588,7 @@ mod test {
assert_eq!(_0 + _0, _0); assert_eq!(_0 + _0, _0);
assert_eq!(_0 * _0, _0); assert_eq!(_0 * _0, _0);
assert_eq!(_0 * _1, _0); assert_eq!(_0 * _1, _0);
assert_eq!(_0 / _neg1_2, _0); assert_eq!(_0 / _NEG1_2, _0);
assert_eq!(_0 - _0, _0); assert_eq!(_0 - _0, _0);
} }
#[test] #[test]
@ -605,30 +605,30 @@ mod test {
assert_eq!(_1_3.round(), _0); assert_eq!(_1_3.round(), _0);
assert_eq!(_1_3.trunc(), _0); assert_eq!(_1_3.trunc(), _0);
assert_eq!(_neg1_3.ceil(), _0); assert_eq!(_NEG1_3.ceil(), _0);
assert_eq!(_neg1_3.floor(), -_1); assert_eq!(_NEG1_3.floor(), -_1);
assert_eq!(_neg1_3.round(), _0); assert_eq!(_NEG1_3.round(), _0);
assert_eq!(_neg1_3.trunc(), _0); assert_eq!(_NEG1_3.trunc(), _0);
assert_eq!(_2_3.ceil(), _1); assert_eq!(_2_3.ceil(), _1);
assert_eq!(_2_3.floor(), _0); assert_eq!(_2_3.floor(), _0);
assert_eq!(_2_3.round(), _1); assert_eq!(_2_3.round(), _1);
assert_eq!(_2_3.trunc(), _0); assert_eq!(_2_3.trunc(), _0);
assert_eq!(_neg2_3.ceil(), _0); assert_eq!(_NEG2_3.ceil(), _0);
assert_eq!(_neg2_3.floor(), -_1); assert_eq!(_NEG2_3.floor(), -_1);
assert_eq!(_neg2_3.round(), -_1); assert_eq!(_NEG2_3.round(), -_1);
assert_eq!(_neg2_3.trunc(), _0); assert_eq!(_NEG2_3.trunc(), _0);
assert_eq!(_1_2.ceil(), _1); assert_eq!(_1_2.ceil(), _1);
assert_eq!(_1_2.floor(), _0); assert_eq!(_1_2.floor(), _0);
assert_eq!(_1_2.round(), _1); assert_eq!(_1_2.round(), _1);
assert_eq!(_1_2.trunc(), _0); assert_eq!(_1_2.trunc(), _0);
assert_eq!(_neg1_2.ceil(), _0); assert_eq!(_NEG1_2.ceil(), _0);
assert_eq!(_neg1_2.floor(), -_1); assert_eq!(_NEG1_2.floor(), -_1);
assert_eq!(_neg1_2.round(), -_1); assert_eq!(_NEG1_2.round(), -_1);
assert_eq!(_neg1_2.trunc(), _0); assert_eq!(_NEG1_2.trunc(), _0);
assert_eq!(_1.ceil(), _1); assert_eq!(_1.ceil(), _1);
assert_eq!(_1.floor(), _1); assert_eq!(_1.floor(), _1);
@ -660,7 +660,7 @@ mod test {
#[test] #[test]
fn test_fract() { fn test_fract() {
assert_eq!(_1.fract(), _0); assert_eq!(_1.fract(), _0);
assert_eq!(_neg1_2.fract(), _neg1_2); assert_eq!(_NEG1_2.fract(), _NEG1_2);
assert_eq!(_1_2.fract(), _1_2); assert_eq!(_1_2.fract(), _1_2);
assert_eq!(_3_2.fract(), _1_2); assert_eq!(_3_2.fract(), _1_2);
} }
@ -671,7 +671,7 @@ mod test {
assert_eq!(_2 * _2.recip(), _1); assert_eq!(_2 * _2.recip(), _1);
assert_eq!(_1_2 * _1_2.recip(), _1); assert_eq!(_1_2 * _1_2.recip(), _1);
assert_eq!(_3_2 * _3_2.recip(), _1); assert_eq!(_3_2 * _3_2.recip(), _1);
assert_eq!(_neg1_2 * _neg1_2.recip(), _1); assert_eq!(_NEG1_2 * _NEG1_2.recip(), _1);
} }
#[test] #[test]
@ -685,7 +685,7 @@ mod test {
test(_1_2, "1/2".to_string()); test(_1_2, "1/2".to_string());
test(_3_2, "3/2".to_string()); test(_3_2, "3/2".to_string());
test(_2, "2".to_string()); test(_2, "2".to_string());
test(_neg1_2, "-1/2".to_string()); test(_NEG1_2, "-1/2".to_string());
} }
#[test] #[test]
fn test_from_str_fail() { fn test_from_str_fail() {
@ -715,16 +715,16 @@ mod test {
test3(_1_2, "1/2".to_string()); test3(_1_2, "1/2".to_string());
test3(_3_2, "10/2".to_string()); test3(_3_2, "10/2".to_string());
test3(_2, "2/1".to_string()); test3(_2, "2/1".to_string());
test3(_neg1_2, "-1/2".to_string()); test3(_NEG1_2, "-1/2".to_string());
test3(_neg1_2 / _2, "-1/11".to_string()); test3(_NEG1_2 / _2, "-1/11".to_string());
test16(_1, "1/1".to_string()); test16(_1, "1/1".to_string());
test16(_0, "0/1".to_string()); test16(_0, "0/1".to_string());
test16(_1_2, "1/2".to_string()); test16(_1_2, "1/2".to_string());
test16(_3_2, "3/2".to_string()); test16(_3_2, "3/2".to_string());
test16(_2, "2/1".to_string()); test16(_2, "2/1".to_string());
test16(_neg1_2, "-1/2".to_string()); test16(_NEG1_2, "-1/2".to_string());
test16(_neg1_2 / _2, "-1/4".to_string()); test16(_NEG1_2 / _2, "-1/4".to_string());
test16(Ratio::new(13i,15i), "d/f".to_string()); test16(Ratio::new(13i,15i), "d/f".to_string());
test16(_1_2*_1_2*_1_2*_1_2, "1/10".to_string()); test16(_1_2*_1_2*_1_2*_1_2, "1/10".to_string());
} }
@ -782,13 +782,13 @@ mod test {
#[test] #[test]
fn test_signed() { fn test_signed() {
assert_eq!(_neg1_2.abs(), _1_2); assert_eq!(_NEG1_2.abs(), _1_2);
assert_eq!(_3_2.abs_sub(&_1_2), _1); assert_eq!(_3_2.abs_sub(&_1_2), _1);
assert_eq!(_1_2.abs_sub(&_3_2), Zero::zero()); assert_eq!(_1_2.abs_sub(&_3_2), Zero::zero());
assert_eq!(_1_2.signum(), One::one()); assert_eq!(_1_2.signum(), One::one());
assert_eq!(_neg1_2.signum(), - num::one::<Ratio<int>>()); assert_eq!(_NEG1_2.signum(), - num::one::<Ratio<int>>());
assert!(_neg1_2.is_negative()); assert!(_NEG1_2.is_negative());
assert!(! _neg1_2.is_positive()); assert!(! _NEG1_2.is_positive());
assert!(! _1_2.is_negative()); assert!(! _1_2.is_negative());
} }