diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2013-04-16 01:08:52 +1000 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2013-04-16 09:57:47 +1000 |
| commit | d3be98e9f5e721b53dccd0a43c2ff58ddd32ac47 (patch) | |
| tree | 2c1730e5ca7b3352854e92b51a7d0b44e5984438 /src/libcore | |
| parent | f10cf26e25c75e148d86dd151a210d9f4a7ece2f (diff) | |
| download | rust-d3be98e9f5e721b53dccd0a43c2ff58ddd32ac47.tar.gz rust-d3be98e9f5e721b53dccd0a43c2ff58ddd32ac47.zip | |
libcore,std,syntax,rustc: move tests into `mod tests`, make them private (no pub mod or pub fn).
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/at_vec.rs | 71 | ||||
| -rw-r--r-- | src/libcore/cast.rs | 10 | ||||
| -rw-r--r-- | src/libcore/comm.rs | 6 | ||||
| -rw-r--r-- | src/libcore/hash.rs | 310 | ||||
| -rw-r--r-- | src/libcore/hashmap.rs | 28 | ||||
| -rw-r--r-- | src/libcore/num/float.rs | 395 | ||||
| -rw-r--r-- | src/libcore/num/int-template.rs | 317 | ||||
| -rw-r--r-- | src/libcore/num/uint-template.rs | 316 | ||||
| -rw-r--r-- | src/libcore/pipes.rs | 6 | ||||
| -rw-r--r-- | src/libcore/ptr.rs | 202 | ||||
| -rw-r--r-- | src/libcore/rand.rs | 40 | ||||
| -rw-r--r-- | src/libcore/run.rs | 16 | ||||
| -rw-r--r-- | src/libcore/sys.rs | 18 | ||||
| -rw-r--r-- | src/libcore/task/mod.rs | 2 | ||||
| -rw-r--r-- | src/libcore/unstable.rs | 6 |
15 files changed, 883 insertions, 860 deletions
diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index 38a663dc245..337b0722ce7 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -277,45 +277,48 @@ pub mod raw { pub unsafe fn reserve_at_least<T>(v: &mut @[T], n: uint) { reserve(v, uint::next_power_of_two(n)); } - } -#[test] -pub fn test() { - // Some code that could use that, then: - fn seq_range(lo: uint, hi: uint) -> @[uint] { - do build |push| { - for uint::range(lo, hi) |i| { - push(i); +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test() { + // Some code that could use that, then: + fn seq_range(lo: uint, hi: uint) -> @[uint] { + do build |push| { + for uint::range(lo, hi) |i| { + push(i); + } } } - } - assert_eq!(seq_range(10, 15), @[10, 11, 12, 13, 14]); - assert!(from_fn(5, |x| x+1) == @[1, 2, 3, 4, 5]); - assert!(from_elem(5, 3.14) == @[3.14, 3.14, 3.14, 3.14, 3.14]); -} - -#[test] -pub fn append_test() { - assert!(@[1,2,3] + @[4,5,6] == @[1,2,3,4,5,6]); -} + assert_eq!(seq_range(10, 15), @[10, 11, 12, 13, 14]); + assert!(from_fn(5, |x| x+1) == @[1, 2, 3, 4, 5]); + assert!(from_elem(5, 3.14) == @[3.14, 3.14, 3.14, 3.14, 3.14]); + } -#[test] -pub fn test_from_owned() { - assert!(from_owned::<int>(~[]) == @[]); - assert!(from_owned(~[true]) == @[true]); - assert!(from_owned(~[1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]); - assert!(from_owned(~[~"abc", ~"123"]) == @[~"abc", ~"123"]); - assert!(from_owned(~[~[42]]) == @[~[42]]); -} + #[test] + fn append_test() { + assert!(@[1,2,3] + @[4,5,6] == @[1,2,3,4,5,6]); + } -#[test] -pub fn test_from_slice() { - assert!(from_slice::<int>([]) == @[]); - assert!(from_slice([true]) == @[true]); - assert!(from_slice([1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]); - assert!(from_slice([@"abc", @"123"]) == @[@"abc", @"123"]); - assert!(from_slice([@[42]]) == @[@[42]]); -} + #[test] + fn test_from_owned() { + assert!(from_owned::<int>(~[]) == @[]); + assert!(from_owned(~[true]) == @[true]); + assert!(from_owned(~[1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]); + assert!(from_owned(~[~"abc", ~"123"]) == @[~"abc", ~"123"]); + assert!(from_owned(~[~[42]]) == @[~[42]]); + } + #[test] + fn test_from_slice() { + assert!(from_slice::<int>([]) == @[]); + assert!(from_slice([true]) == @[true]); + assert!(from_slice([1, 2, 3, 4, 5]) == @[1, 2, 3, 4, 5]); + assert!(from_slice([@"abc", @"123"]) == @[@"abc", @"123"]); + assert!(from_slice([@[42]]) == @[@[42]]); + } +} \ No newline at end of file diff --git a/src/libcore/cast.rs b/src/libcore/cast.rs index 42464c848ef..1d214f402f5 100644 --- a/src/libcore/cast.rs +++ b/src/libcore/cast.rs @@ -111,16 +111,16 @@ pub unsafe fn copy_lifetime_vec<'a,S,T>(_ptr: &'a [S], ptr: &T) -> &'a T { ****************************************************************************/ #[cfg(test)] -pub mod tests { +mod tests { use cast::{bump_box_refcount, reinterpret_cast, transmute}; #[test] - pub fn test_reinterpret_cast() { + fn test_reinterpret_cast() { assert!(1u == unsafe { reinterpret_cast(&1) }); } #[test] - pub fn test_bump_box_refcount() { + fn test_bump_box_refcount() { unsafe { let box = @~"box box box"; // refcount 1 bump_box_refcount(box); // refcount 2 @@ -135,7 +135,7 @@ pub mod tests { } #[test] - pub fn test_transmute() { + fn test_transmute() { use managed::raw::BoxRepr; unsafe { let x = @100u8; @@ -146,7 +146,7 @@ pub mod tests { } #[test] - pub fn test_transmute2() { + fn test_transmute2() { unsafe { assert!(~[76u8, 0u8] == transmute(~"L")); } diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index d665bf311f3..f8b046e5b8c 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -426,12 +426,12 @@ pub fn try_send_one<T: Owned>(chan: ChanOne<T>, data: T) } #[cfg(test)] -pub mod test { +mod test { use either::Right; use super::{Chan, Port, oneshot, recv_one, stream}; #[test] - pub fn test_select2() { + fn test_select2() { let (p1, c1) = stream(); let (p2, c2) = stream(); @@ -446,7 +446,7 @@ pub mod test { } #[test] - pub fn test_oneshot() { + fn test_oneshot() { let (c, p) = oneshot::init(); oneshot::client::send(c, ()); diff --git a/src/libcore/hash.rs b/src/libcore/hash.rs index c229bc17311..ba1f8cebdb0 100644 --- a/src/libcore/hash.rs +++ b/src/libcore/hash.rs @@ -357,170 +357,176 @@ impl Streaming for SipState { } } -#[test] -pub fn test_siphash() { - let vecs : [[u8, ..8], ..64] = [ - [ 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72, ], - [ 0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74, ], - [ 0x5a, 0x4f, 0xa9, 0xd9, 0x09, 0x80, 0x6c, 0x0d, ], - [ 0x2d, 0x7e, 0xfb, 0xd7, 0x96, 0x66, 0x67, 0x85, ], - [ 0xb7, 0x87, 0x71, 0x27, 0xe0, 0x94, 0x27, 0xcf, ], - [ 0x8d, 0xa6, 0x99, 0xcd, 0x64, 0x55, 0x76, 0x18, ], - [ 0xce, 0xe3, 0xfe, 0x58, 0x6e, 0x46, 0xc9, 0xcb, ], - [ 0x37, 0xd1, 0x01, 0x8b, 0xf5, 0x00, 0x02, 0xab, ], - [ 0x62, 0x24, 0x93, 0x9a, 0x79, 0xf5, 0xf5, 0x93, ], - [ 0xb0, 0xe4, 0xa9, 0x0b, 0xdf, 0x82, 0x00, 0x9e, ], - [ 0xf3, 0xb9, 0xdd, 0x94, 0xc5, 0xbb, 0x5d, 0x7a, ], - [ 0xa7, 0xad, 0x6b, 0x22, 0x46, 0x2f, 0xb3, 0xf4, ], - [ 0xfb, 0xe5, 0x0e, 0x86, 0xbc, 0x8f, 0x1e, 0x75, ], - [ 0x90, 0x3d, 0x84, 0xc0, 0x27, 0x56, 0xea, 0x14, ], - [ 0xee, 0xf2, 0x7a, 0x8e, 0x90, 0xca, 0x23, 0xf7, ], - [ 0xe5, 0x45, 0xbe, 0x49, 0x61, 0xca, 0x29, 0xa1, ], - [ 0xdb, 0x9b, 0xc2, 0x57, 0x7f, 0xcc, 0x2a, 0x3f, ], - [ 0x94, 0x47, 0xbe, 0x2c, 0xf5, 0xe9, 0x9a, 0x69, ], - [ 0x9c, 0xd3, 0x8d, 0x96, 0xf0, 0xb3, 0xc1, 0x4b, ], - [ 0xbd, 0x61, 0x79, 0xa7, 0x1d, 0xc9, 0x6d, 0xbb, ], - [ 0x98, 0xee, 0xa2, 0x1a, 0xf2, 0x5c, 0xd6, 0xbe, ], - [ 0xc7, 0x67, 0x3b, 0x2e, 0xb0, 0xcb, 0xf2, 0xd0, ], - [ 0x88, 0x3e, 0xa3, 0xe3, 0x95, 0x67, 0x53, 0x93, ], - [ 0xc8, 0xce, 0x5c, 0xcd, 0x8c, 0x03, 0x0c, 0xa8, ], - [ 0x94, 0xaf, 0x49, 0xf6, 0xc6, 0x50, 0xad, 0xb8, ], - [ 0xea, 0xb8, 0x85, 0x8a, 0xde, 0x92, 0xe1, 0xbc, ], - [ 0xf3, 0x15, 0xbb, 0x5b, 0xb8, 0x35, 0xd8, 0x17, ], - [ 0xad, 0xcf, 0x6b, 0x07, 0x63, 0x61, 0x2e, 0x2f, ], - [ 0xa5, 0xc9, 0x1d, 0xa7, 0xac, 0xaa, 0x4d, 0xde, ], - [ 0x71, 0x65, 0x95, 0x87, 0x66, 0x50, 0xa2, 0xa6, ], - [ 0x28, 0xef, 0x49, 0x5c, 0x53, 0xa3, 0x87, 0xad, ], - [ 0x42, 0xc3, 0x41, 0xd8, 0xfa, 0x92, 0xd8, 0x32, ], - [ 0xce, 0x7c, 0xf2, 0x72, 0x2f, 0x51, 0x27, 0x71, ], - [ 0xe3, 0x78, 0x59, 0xf9, 0x46, 0x23, 0xf3, 0xa7, ], - [ 0x38, 0x12, 0x05, 0xbb, 0x1a, 0xb0, 0xe0, 0x12, ], - [ 0xae, 0x97, 0xa1, 0x0f, 0xd4, 0x34, 0xe0, 0x15, ], - [ 0xb4, 0xa3, 0x15, 0x08, 0xbe, 0xff, 0x4d, 0x31, ], - [ 0x81, 0x39, 0x62, 0x29, 0xf0, 0x90, 0x79, 0x02, ], - [ 0x4d, 0x0c, 0xf4, 0x9e, 0xe5, 0xd4, 0xdc, 0xca, ], - [ 0x5c, 0x73, 0x33, 0x6a, 0x76, 0xd8, 0xbf, 0x9a, ], - [ 0xd0, 0xa7, 0x04, 0x53, 0x6b, 0xa9, 0x3e, 0x0e, ], - [ 0x92, 0x59, 0x58, 0xfc, 0xd6, 0x42, 0x0c, 0xad, ], - [ 0xa9, 0x15, 0xc2, 0x9b, 0xc8, 0x06, 0x73, 0x18, ], - [ 0x95, 0x2b, 0x79, 0xf3, 0xbc, 0x0a, 0xa6, 0xd4, ], - [ 0xf2, 0x1d, 0xf2, 0xe4, 0x1d, 0x45, 0x35, 0xf9, ], - [ 0x87, 0x57, 0x75, 0x19, 0x04, 0x8f, 0x53, 0xa9, ], - [ 0x10, 0xa5, 0x6c, 0xf5, 0xdf, 0xcd, 0x9a, 0xdb, ], - [ 0xeb, 0x75, 0x09, 0x5c, 0xcd, 0x98, 0x6c, 0xd0, ], - [ 0x51, 0xa9, 0xcb, 0x9e, 0xcb, 0xa3, 0x12, 0xe6, ], - [ 0x96, 0xaf, 0xad, 0xfc, 0x2c, 0xe6, 0x66, 0xc7, ], - [ 0x72, 0xfe, 0x52, 0x97, 0x5a, 0x43, 0x64, 0xee, ], - [ 0x5a, 0x16, 0x45, 0xb2, 0x76, 0xd5, 0x92, 0xa1, ], - [ 0xb2, 0x74, 0xcb, 0x8e, 0xbf, 0x87, 0x87, 0x0a, ], - [ 0x6f, 0x9b, 0xb4, 0x20, 0x3d, 0xe7, 0xb3, 0x81, ], - [ 0xea, 0xec, 0xb2, 0xa3, 0x0b, 0x22, 0xa8, 0x7f, ], - [ 0x99, 0x24, 0xa4, 0x3c, 0xc1, 0x31, 0x57, 0x24, ], - [ 0xbd, 0x83, 0x8d, 0x3a, 0xaf, 0xbf, 0x8d, 0xb7, ], - [ 0x0b, 0x1a, 0x2a, 0x32, 0x65, 0xd5, 0x1a, 0xea, ], - [ 0x13, 0x50, 0x79, 0xa3, 0x23, 0x1c, 0xe6, 0x60, ], - [ 0x93, 0x2b, 0x28, 0x46, 0xe4, 0xd7, 0x06, 0x66, ], - [ 0xe1, 0x91, 0x5f, 0x5c, 0xb1, 0xec, 0xa4, 0x6c, ], - [ 0xf3, 0x25, 0x96, 0x5c, 0xa1, 0x6d, 0x62, 0x9f, ], - [ 0x57, 0x5f, 0xf2, 0x8e, 0x60, 0x38, 0x1b, 0xe5, ], - [ 0x72, 0x45, 0x06, 0xeb, 0x4c, 0x32, 0x8a, 0x95, ] - ]; - - let k0 = 0x_07_06_05_04_03_02_01_00_u64; - let k1 = 0x_0f_0e_0d_0c_0b_0a_09_08_u64; - let mut buf : ~[u8] = ~[]; - let mut t = 0; - let stream_inc = &State(k0,k1); - let stream_full = &State(k0,k1); - - fn to_hex_str(r: &[u8, ..8]) -> ~str { - let mut s = ~""; - for vec::each(*r) |b| { - s += uint::to_str_radix(*b as uint, 16u); +#[cfg(test)] +mod tests { + use super::*; + use prelude::*; + + #[test] + fn test_siphash() { + let vecs : [[u8, ..8], ..64] = [ + [ 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72, ], + [ 0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74, ], + [ 0x5a, 0x4f, 0xa9, 0xd9, 0x09, 0x80, 0x6c, 0x0d, ], + [ 0x2d, 0x7e, 0xfb, 0xd7, 0x96, 0x66, 0x67, 0x85, ], + [ 0xb7, 0x87, 0x71, 0x27, 0xe0, 0x94, 0x27, 0xcf, ], + [ 0x8d, 0xa6, 0x99, 0xcd, 0x64, 0x55, 0x76, 0x18, ], + [ 0xce, 0xe3, 0xfe, 0x58, 0x6e, 0x46, 0xc9, 0xcb, ], + [ 0x37, 0xd1, 0x01, 0x8b, 0xf5, 0x00, 0x02, 0xab, ], + [ 0x62, 0x24, 0x93, 0x9a, 0x79, 0xf5, 0xf5, 0x93, ], + [ 0xb0, 0xe4, 0xa9, 0x0b, 0xdf, 0x82, 0x00, 0x9e, ], + [ 0xf3, 0xb9, 0xdd, 0x94, 0xc5, 0xbb, 0x5d, 0x7a, ], + [ 0xa7, 0xad, 0x6b, 0x22, 0x46, 0x2f, 0xb3, 0xf4, ], + [ 0xfb, 0xe5, 0x0e, 0x86, 0xbc, 0x8f, 0x1e, 0x75, ], + [ 0x90, 0x3d, 0x84, 0xc0, 0x27, 0x56, 0xea, 0x14, ], + [ 0xee, 0xf2, 0x7a, 0x8e, 0x90, 0xca, 0x23, 0xf7, ], + [ 0xe5, 0x45, 0xbe, 0x49, 0x61, 0xca, 0x29, 0xa1, ], + [ 0xdb, 0x9b, 0xc2, 0x57, 0x7f, 0xcc, 0x2a, 0x3f, ], + [ 0x94, 0x47, 0xbe, 0x2c, 0xf5, 0xe9, 0x9a, 0x69, ], + [ 0x9c, 0xd3, 0x8d, 0x96, 0xf0, 0xb3, 0xc1, 0x4b, ], + [ 0xbd, 0x61, 0x79, 0xa7, 0x1d, 0xc9, 0x6d, 0xbb, ], + [ 0x98, 0xee, 0xa2, 0x1a, 0xf2, 0x5c, 0xd6, 0xbe, ], + [ 0xc7, 0x67, 0x3b, 0x2e, 0xb0, 0xcb, 0xf2, 0xd0, ], + [ 0x88, 0x3e, 0xa3, 0xe3, 0x95, 0x67, 0x53, 0x93, ], + [ 0xc8, 0xce, 0x5c, 0xcd, 0x8c, 0x03, 0x0c, 0xa8, ], + [ 0x94, 0xaf, 0x49, 0xf6, 0xc6, 0x50, 0xad, 0xb8, ], + [ 0xea, 0xb8, 0x85, 0x8a, 0xde, 0x92, 0xe1, 0xbc, ], + [ 0xf3, 0x15, 0xbb, 0x5b, 0xb8, 0x35, 0xd8, 0x17, ], + [ 0xad, 0xcf, 0x6b, 0x07, 0x63, 0x61, 0x2e, 0x2f, ], + [ 0xa5, 0xc9, 0x1d, 0xa7, 0xac, 0xaa, 0x4d, 0xde, ], + [ 0x71, 0x65, 0x95, 0x87, 0x66, 0x50, 0xa2, 0xa6, ], + [ 0x28, 0xef, 0x49, 0x5c, 0x53, 0xa3, 0x87, 0xad, ], + [ 0x42, 0xc3, 0x41, 0xd8, 0xfa, 0x92, 0xd8, 0x32, ], + [ 0xce, 0x7c, 0xf2, 0x72, 0x2f, 0x51, 0x27, 0x71, ], + [ 0xe3, 0x78, 0x59, 0xf9, 0x46, 0x23, 0xf3, 0xa7, ], + [ 0x38, 0x12, 0x05, 0xbb, 0x1a, 0xb0, 0xe0, 0x12, ], + [ 0xae, 0x97, 0xa1, 0x0f, 0xd4, 0x34, 0xe0, 0x15, ], + [ 0xb4, 0xa3, 0x15, 0x08, 0xbe, 0xff, 0x4d, 0x31, ], + [ 0x81, 0x39, 0x62, 0x29, 0xf0, 0x90, 0x79, 0x02, ], + [ 0x4d, 0x0c, 0xf4, 0x9e, 0xe5, 0xd4, 0xdc, 0xca, ], + [ 0x5c, 0x73, 0x33, 0x6a, 0x76, 0xd8, 0xbf, 0x9a, ], + [ 0xd0, 0xa7, 0x04, 0x53, 0x6b, 0xa9, 0x3e, 0x0e, ], + [ 0x92, 0x59, 0x58, 0xfc, 0xd6, 0x42, 0x0c, 0xad, ], + [ 0xa9, 0x15, 0xc2, 0x9b, 0xc8, 0x06, 0x73, 0x18, ], + [ 0x95, 0x2b, 0x79, 0xf3, 0xbc, 0x0a, 0xa6, 0xd4, ], + [ 0xf2, 0x1d, 0xf2, 0xe4, 0x1d, 0x45, 0x35, 0xf9, ], + [ 0x87, 0x57, 0x75, 0x19, 0x04, 0x8f, 0x53, 0xa9, ], + [ 0x10, 0xa5, 0x6c, 0xf5, 0xdf, 0xcd, 0x9a, 0xdb, ], + [ 0xeb, 0x75, 0x09, 0x5c, 0xcd, 0x98, 0x6c, 0xd0, ], + [ 0x51, 0xa9, 0xcb, 0x9e, 0xcb, 0xa3, 0x12, 0xe6, ], + [ 0x96, 0xaf, 0xad, 0xfc, 0x2c, 0xe6, 0x66, 0xc7, ], + [ 0x72, 0xfe, 0x52, 0x97, 0x5a, 0x43, 0x64, 0xee, ], + [ 0x5a, 0x16, 0x45, 0xb2, 0x76, 0xd5, 0x92, 0xa1, ], + [ 0xb2, 0x74, 0xcb, 0x8e, 0xbf, 0x87, 0x87, 0x0a, ], + [ 0x6f, 0x9b, 0xb4, 0x20, 0x3d, 0xe7, 0xb3, 0x81, ], + [ 0xea, 0xec, 0xb2, 0xa3, 0x0b, 0x22, 0xa8, 0x7f, ], + [ 0x99, 0x24, 0xa4, 0x3c, 0xc1, 0x31, 0x57, 0x24, ], + [ 0xbd, 0x83, 0x8d, 0x3a, 0xaf, 0xbf, 0x8d, 0xb7, ], + [ 0x0b, 0x1a, 0x2a, 0x32, 0x65, 0xd5, 0x1a, 0xea, ], + [ 0x13, 0x50, 0x79, 0xa3, 0x23, 0x1c, 0xe6, 0x60, ], + [ 0x93, 0x2b, 0x28, 0x46, 0xe4, 0xd7, 0x06, 0x66, ], + [ 0xe1, 0x91, 0x5f, 0x5c, 0xb1, 0xec, 0xa4, 0x6c, ], + [ 0xf3, 0x25, 0x96, 0x5c, 0xa1, 0x6d, 0x62, 0x9f, ], + [ 0x57, 0x5f, 0xf2, 0x8e, 0x60, 0x38, 0x1b, 0xe5, ], + [ 0x72, 0x45, 0x06, 0xeb, 0x4c, 0x32, 0x8a, 0x95, ] + ]; + + let k0 = 0x_07_06_05_04_03_02_01_00_u64; + let k1 = 0x_0f_0e_0d_0c_0b_0a_09_08_u64; + let mut buf : ~[u8] = ~[]; + let mut t = 0; + let stream_inc = &State(k0,k1); + let stream_full = &State(k0,k1); + + fn to_hex_str(r: &[u8, ..8]) -> ~str { + let mut s = ~""; + for vec::each(*r) |b| { + s += uint::to_str_radix(*b as uint, 16u); + } + s } - s - } - while t < 64 { - debug!("siphash test %?", t); - let vec = u8to64_le!(vecs[t], 0); - let out = buf.hash_keyed(k0, k1); - debug!("got %?, expected %?", out, vec); - assert!(vec == out); + while t < 64 { + debug!("siphash test %?", t); + let vec = u8to64_le!(vecs[t], 0); + let out = buf.hash_keyed(k0, k1); + debug!("got %?, expected %?", out, vec); + assert!(vec == out); - stream_full.reset(); - stream_full.input(buf); - let f = stream_full.result_str(); - let i = stream_inc.result_str(); - let v = to_hex_str(&vecs[t]); - debug!("%d: (%s) => inc=%s full=%s", t, v, i, f); + stream_full.reset(); + stream_full.input(buf); + let f = stream_full.result_str(); + let i = stream_inc.result_str(); + let v = to_hex_str(&vecs[t]); + debug!("%d: (%s) => inc=%s full=%s", t, v, i, f); - assert!(f == i && f == v); + assert!(f == i && f == v); - buf += ~[t as u8]; - stream_inc.input(~[t as u8]); + buf += ~[t as u8]; + stream_inc.input(~[t as u8]); - t += 1; + t += 1; + } } -} -#[test] #[cfg(target_arch = "arm")] -pub fn test_hash_uint() { - let val = 0xdeadbeef_deadbeef_u64; - assert!((val as u64).hash() != (val as uint).hash()); - assert!((val as u32).hash() == (val as uint).hash()); -} -#[test] #[cfg(target_arch = "x86_64")] -pub fn test_hash_uint() { - let val = 0xdeadbeef_deadbeef_u64; - assert!((val as u64).hash() == (val as uint).hash()); - assert!((val as u32).hash() != (val as uint).hash()); -} -#[test] #[cfg(target_arch = "x86")] -pub fn test_hash_uint() { - let val = 0xdeadbeef_deadbeef_u64; - assert!((val as u64).hash() != (val as uint).hash()); - assert!((val as u32).hash() == (val as uint).hash()); -} + #[test] #[cfg(target_arch = "arm")] + fn test_hash_uint() { + let val = 0xdeadbeef_deadbeef_u64; + assert!((val as u64).hash() != (val as uint).hash()); + assert!((val as u32).hash() == (val as uint).hash()); + } + #[test] #[cfg(target_arch = "x86_64")] + fn test_hash_uint() { + let val = 0xdeadbeef_deadbeef_u64; + assert!((val as u64).hash() == (val as uint).hash()); + assert!((val as u32).hash() != (val as uint).hash()); + } + #[test] #[cfg(target_arch = "x86")] + fn test_hash_uint() { + let val = 0xdeadbeef_deadbeef_u64; + assert!((val as u64).hash() != (val as uint).hash()); + assert!((val as u32).hash() == (val as uint).hash()); + } -#[test] -pub fn test_hash_idempotent() { - let val64 = 0xdeadbeef_deadbeef_u64; - val64.hash() == val64.hash(); - let val32 = 0xdeadbeef_u32; - val32.hash() == val32.hash(); -} + #[test] + fn test_hash_idempotent() { + let val64 = 0xdeadbeef_deadbeef_u64; + val64.hash() == val64.hash(); + let val32 = 0xdeadbeef_u32; + val32.hash() == val32.hash(); + } -#[test] -pub fn test_hash_no_bytes_dropped_64() { - let val = 0xdeadbeef_deadbeef_u64; - - assert!(val.hash() != zero_byte(val, 0).hash()); - assert!(val.hash() != zero_byte(val, 1).hash()); - assert!(val.hash() != zero_byte(val, 2).hash()); - assert!(val.hash() != zero_byte(val, 3).hash()); - assert!(val.hash() != zero_byte(val, 4).hash()); - assert!(val.hash() != zero_byte(val, 5).hash()); - assert!(val.hash() != zero_byte(val, 6).hash()); - assert!(val.hash() != zero_byte(val, 7).hash()); - - fn zero_byte(val: u64, byte: uint) -> u64 { - assert!(byte < 8); - val & !(0xff << (byte * 8)) + #[test] + fn test_hash_no_bytes_dropped_64() { + let val = 0xdeadbeef_deadbeef_u64; + + assert!(val.hash() != zero_byte(val, 0).hash()); + assert!(val.hash() != zero_byte(val, 1).hash()); + assert!(val.hash() != zero_byte(val, 2).hash()); + assert!(val.hash() != zero_byte(val, 3).hash()); + assert!(val.hash() != zero_byte(val, 4).hash()); + assert!(val.hash() != zero_byte(val, 5).hash()); + assert!(val.hash() != zero_byte(val, 6).hash()); + assert!(val.hash() != zero_byte(val, 7).hash()); + + fn zero_byte(val: u64, byte: uint) -> u64 { + assert!(byte < 8); + val & !(0xff << (byte * 8)) + } } -} -#[test] -pub fn test_hash_no_bytes_dropped_32() { - let val = 0xdeadbeef_u32; + #[test] + fn test_hash_no_bytes_dropped_32() { + let val = 0xdeadbeef_u32; - assert!(val.hash() != zero_byte(val, 0).hash()); - assert!(val.hash() != zero_byte(val, 1).hash()); - assert!(val.hash() != zero_byte(val, 2).hash()); - assert!(val.hash() != zero_byte(val, 3).hash()); + assert!(val.hash() != zero_byte(val, 0).hash()); + assert!(val.hash() != zero_byte(val, 1).hash()); + assert!(val.hash() != zero_byte(val, 2).hash()); + assert!(val.hash() != zero_byte(val, 3).hash()); - fn zero_byte(val: u32, byte: uint) -> u32 { - assert!(byte < 4); - val & !(0xff << (byte * 8)) + fn zero_byte(val: u32, byte: uint) -> u32 { + assert!(byte < 4); + val & !(0xff << (byte * 8)) + } } -} +} \ No newline at end of file diff --git a/src/libcore/hashmap.rs b/src/libcore/hashmap.rs index 2869c198ca2..3efe21fc42c 100644 --- a/src/libcore/hashmap.rs +++ b/src/libcore/hashmap.rs @@ -847,7 +847,7 @@ mod test_map { use uint; #[test] - pub fn test_insert() { + fn test_insert() { let mut m = HashMap::new(); assert!(m.insert(1, 2)); assert!(m.insert(2, 4)); @@ -869,7 +869,7 @@ mod test_map { } #[test] - pub fn test_insert_overwrite() { + fn test_insert_overwrite() { let mut m = HashMap::new(); assert!(m.insert(1, 2)); assert!(*m.get(&1) == 2); @@ -878,7 +878,7 @@ mod test_map { } #[test] - pub fn test_insert_conflicts() { + fn test_insert_conflicts() { let mut m = linear_map_with_capacity(4); assert!(m.insert(1, 2)); assert!(m.insert(5, 3)); @@ -889,7 +889,7 @@ mod test_map { } #[test] - pub fn test_conflict_remove() { + fn test_conflict_remove() { let mut m = linear_map_with_capacity(4); assert!(m.insert(1, 2)); assert!(m.insert(5, 3)); @@ -900,7 +900,7 @@ mod test_map { } #[test] - pub fn test_is_empty() { + fn test_is_empty() { let mut m = linear_map_with_capacity(4); assert!(m.insert(1, 2)); assert!(!m.is_empty()); @@ -909,7 +909,7 @@ mod test_map { } #[test] - pub fn test_pop() { + fn test_pop() { let mut m = HashMap::new(); m.insert(1, 2); assert!(m.pop(&1) == Some(2)); @@ -917,7 +917,7 @@ mod test_map { } #[test] - pub fn test_swap() { + fn test_swap() { let mut m = HashMap::new(); assert!(m.swap(1, 2) == None); assert!(m.swap(1, 3) == Some(2)); @@ -925,21 +925,21 @@ mod test_map { } #[test] - pub fn test_find_or_insert() { + fn test_find_or_insert() { let mut m = HashMap::new::<int, int>(); assert!(m.find_or_insert(1, 2) == &2); assert!(m.find_or_insert(1, 3) == &2); } #[test] - pub fn test_find_or_insert_with() { + fn test_find_or_insert_with() { let mut m = HashMap::new::<int, int>(); assert!(m.find_or_insert_with(1, |_| 2) == &2); assert!(m.find_or_insert_with(1, |_| 3) == &2); } #[test] - pub fn test_consume() { + fn test_consume() { let mut m = HashMap::new(); assert!(m.insert(1, 2)); assert!(m.insert(2, 3)); @@ -954,7 +954,7 @@ mod test_map { } #[test] - pub fn test_iterate() { + fn test_iterate() { let mut m = linear_map_with_capacity(4); for uint::range(0, 32) |i| { assert!(m.insert(i, i*2)); @@ -968,7 +968,7 @@ mod test_map { } #[test] - pub fn test_find() { + fn test_find() { let mut m = HashMap::new(); assert!(m.find(&1).is_none()); m.insert(1, 2); @@ -979,7 +979,7 @@ mod test_map { } #[test] - pub fn test_eq() { + fn test_eq() { let mut m1 = HashMap::new(); m1.insert(1, 2); m1.insert(2, 3); @@ -997,7 +997,7 @@ mod test_map { } #[test] - pub fn test_expand() { + fn test_expand() { let mut m = HashMap::new(); assert!(m.len() == 0); diff --git a/src/libcore/num/float.rs b/src/libcore/num/float.rs index 87d04b05087..488756787b5 100644 --- a/src/libcore/num/float.rs +++ b/src/libcore/num/float.rs @@ -29,7 +29,6 @@ use from_str; #[cfg(notest)] use cmp::{Eq, Ord}; #[cfg(notest)] use ops; -#[cfg(test)] use option::{Some, None}; pub use f64::{add, sub, mul, div, rem, lt, le, eq, ne, ge, gt}; pub use f64::logarithm; @@ -142,7 +141,7 @@ pub fn to_str_radix(num: float, radix: uint) -> ~str { let (r, special) = strconv::to_str_common( &num, radix, true, strconv::SignNeg, strconv::DigAll); if special { fail!(~"number has a special value, \ - try to_str_radix_special() if those are expected") } + try to_str_radix_special() if those are expected") } r } @@ -177,12 +176,6 @@ pub fn to_str_exact(num: float, digits: uint) -> ~str { r } -#[test] -pub fn test_to_str_exact_do_decimal() { - let s = to_str_exact(5.0, 4u); - assert!(s == ~"5.0000"); -} - /** * Converts a float to a string with a maximum number of * significant digits @@ -474,195 +467,205 @@ impl ops::Neg<float> for float { fn neg(&self) -> float { -*self } } -#[test] -pub fn test_from_str() { - assert!(from_str(~"3") == Some(3.)); - assert!(from_str(~"3.14") == Some(3.14)); - assert!(from_str(~"+3.14") == Some(3.14)); - assert!(from_str(~"-3.14") == Some(-3.14)); - assert!(from_str(~"2.5E10") == Some(25000000000.)); - assert!(from_str(~"2.5e10") == Some(25000000000.)); - assert!(from_str(~"25000000000.E-10") == Some(2.5)); - assert!(from_str(~".") == Some(0.)); - assert!(from_str(~".e1") == Some(0.)); - assert!(from_str(~".e-1") == Some(0.)); - assert!(from_str(~"5.") == Some(5.)); - assert!(from_str(~".5") == Some(0.5)); - assert!(from_str(~"0.5") == Some(0.5)); - assert!(from_str(~"-.5") == Some(-0.5)); - assert!(from_str(~"-5") == Some(-5.)); - assert!(from_str(~"inf") == Some(infinity)); - assert!(from_str(~"+inf") == Some(infinity)); - assert!(from_str(~"-inf") == Some(neg_infinity)); - // note: NaN != NaN, hence this slightly complex test - match from_str(~"NaN") { - Some(f) => assert!(is_NaN(f)), - None => fail!() - } - // note: -0 == 0, hence these slightly more complex tests - match from_str(~"-0") { - Some(v) if is_zero(v) => assert!(is_negative(v)), - _ => fail!() - } - match from_str(~"0") { - Some(v) if is_zero(v) => assert!(is_positive(v)), - _ => fail!() - } - - assert!(from_str(~"").is_none()); - assert!(from_str(~"x").is_none()); - assert!(from_str(~" ").is_none()); - assert!(from_str(~" ").is_none()); - assert!(from_str(~"e").is_none()); - assert!(from_str(~"E").is_none()); - assert!(from_str(~"E1").is_none()); - assert!(from_str(~"1e1e1").is_none()); - assert!(from_str(~"1e1.1").is_none()); - assert!(from_str(~"1e1-1").is_none()); -} - -#[test] -pub fn test_from_str_hex() { - assert!(from_str_hex(~"a4") == Some(164.)); - assert!(from_str_hex(~"a4.fe") == Some(164.9921875)); - assert!(from_str_hex(~"-a4.fe") == Some(-164.9921875)); - assert!(from_str_hex(~"+a4.fe") == Some(164.9921875)); - assert!(from_str_hex(~"ff0P4") == Some(0xff00 as float)); - assert!(from_str_hex(~"ff0p4") == Some(0xff00 as float)); - assert!(from_str_hex(~"ff0p-4") == Some(0xff as float)); - assert!(from_str_hex(~".") == Some(0.)); - assert!(from_str_hex(~".p1") == Some(0.)); - assert!(from_str_hex(~".p-1") == Some(0.)); - assert!(from_str_hex(~"f.") == Some(15.)); - assert!(from_str_hex(~".f") == Some(0.9375)); - assert!(from_str_hex(~"0.f") == Some(0.9375)); - assert!(from_str_hex(~"-.f") == Some(-0.9375)); - assert!(from_str_hex(~"-f") == Some(-15.)); - assert!(from_str_hex(~"inf") == Some(infinity)); - assert!(from_str_hex(~"+inf") == Some(infinity)); - assert!(from_str_hex(~"-inf") == Some(neg_infinity)); - // note: NaN != NaN, hence this slightly complex test - match from_str_hex(~"NaN") { - Some(f) => assert!(is_NaN(f)), - None => fail!() - } - // note: -0 == 0, hence these slightly more complex tests - match from_str_hex(~"-0") { - Some(v) if is_zero(v) => assert!(is_negative(v)), - _ => fail!() - } - match from_str_hex(~"0") { - Some(v) if is_zero(v) => assert!(is_positive(v)), - _ => fail!() - } - assert!(from_str_hex(~"e") == Some(14.)); - assert!(from_str_hex(~"E") == Some(14.)); - assert!(from_str_hex(~"E1") == Some(225.)); - assert!(from_str_hex(~"1e1e1") == Some(123361.)); - assert!(from_str_hex(~"1e1.1") == Some(481.0625)); - - assert!(from_str_hex(~"").is_none()); - assert!(from_str_hex(~"x").is_none()); - assert!(from_str_hex(~" ").is_none()); - assert!(from_str_hex(~" ").is_none()); - assert!(from_str_hex(~"p").is_none()); - assert!(from_str_hex(~"P").is_none()); - assert!(from_str_hex(~"P1").is_none()); - assert!(from_str_hex(~"1p1p1").is_none()); - assert!(from_str_hex(~"1p1.1").is_none()); - assert!(from_str_hex(~"1p1-1").is_none()); -} - -#[test] -pub fn test_to_str_hex() { - assert!(to_str_hex(164.) == ~"a4"); - assert!(to_str_hex(164.9921875) == ~"a4.fe"); - assert!(to_str_hex(-164.9921875) == ~"-a4.fe"); - assert!(to_str_hex(0xff00 as float) == ~"ff00"); - assert!(to_str_hex(-(0xff00 as float)) == ~"-ff00"); - assert!(to_str_hex(0.) == ~"0"); - assert!(to_str_hex(15.) == ~"f"); - assert!(to_str_hex(-15.) == ~"-f"); - assert!(to_str_hex(0.9375) == ~"0.f"); - assert!(to_str_hex(-0.9375) == ~"-0.f"); - assert!(to_str_hex(infinity) == ~"inf"); - assert!(to_str_hex(neg_infinity) == ~"-inf"); - assert!(to_str_hex(NaN) == ~"NaN"); - assert!(to_str_hex(0.) == ~"0"); - assert!(to_str_hex(-0.) == ~"-0"); -} - -#[test] -pub fn test_to_str_radix() { - assert!(to_str_radix(36., 36u) == ~"10"); - assert!(to_str_radix(8.125, 2u) == ~"1000.001"); -} - -#[test] -pub fn test_from_str_radix() { - assert!(from_str_radix(~"10", 36u) == Some(36.)); - assert!(from_str_radix(~"1000.001", 2u) == Some(8.125)); -} - -#[test] -pub fn test_positive() { - assert!((is_positive(infinity))); - assert!((is_positive(1.))); - assert!((is_positive(0.))); - assert!((!is_positive(-1.))); - assert!((!is_positive(neg_infinity))); - assert!((!is_positive(1./neg_infinity))); - assert!((!is_positive(NaN))); -} - -#[test] -pub fn test_negative() { - assert!((!is_negative(infinity))); - assert!((!is_negative(1.))); - assert!((!is_negative(0.))); - assert!((is_negative(-1.))); - assert!((is_negative(neg_infinity))); - assert!((is_negative(1./neg_infinity))); - assert!((!is_negative(NaN))); -} - -#[test] -pub fn test_nonpositive() { - assert!((!is_nonpositive(infinity))); - assert!((!is_nonpositive(1.))); - assert!((!is_nonpositive(0.))); - assert!((is_nonpositive(-1.))); - assert!((is_nonpositive(neg_infinity))); - assert!((is_nonpositive(1./neg_infinity))); - assert!((!is_nonpositive(NaN))); -} - -#[test] -pub fn test_nonnegative() { - assert!((is_nonnegative(infinity))); - assert!((is_nonnegative(1.))); - assert!((is_nonnegative(0.))); - assert!((!is_nonnegative(-1.))); - assert!((!is_nonnegative(neg_infinity))); - assert!((!is_nonnegative(1./neg_infinity))); - assert!((!is_nonnegative(NaN))); -} - -#[test] -pub fn test_to_str_inf() { - assert!(to_str_digits(infinity, 10u) == ~"inf"); - assert!(to_str_digits(-infinity, 10u) == ~"-inf"); -} - -#[test] -pub fn test_round() { - assert!(round(5.8) == 6.0); - assert!(round(5.2) == 5.0); - assert!(round(3.0) == 3.0); - assert!(round(2.5) == 3.0); - assert!(round(-3.5) == -4.0); -} +#[cfg(test)] +mod tests { + use super::*; + use prelude::*; + #[test] + pub fn test_to_str_exact_do_decimal() { + let s = to_str_exact(5.0, 4u); + assert!(s == ~"5.0000"); + } + + #[test] + pub fn test_from_str() { + assert!(from_str(~"3") == Some(3.)); + assert!(from_str(~"3.14") == Some(3.14)); + assert!(from_str(~"+3.14") == Some(3.14)); + assert!(from_str(~"-3.14") == Some(-3.14)); + assert!(from_str(~"2.5E10") == Some(25000000000.)); + assert!(from_str(~"2.5e10") == Some(25000000000.)); + assert!(from_str(~"25000000000.E-10") == Some(2.5)); + assert!(from_str(~".") == Some(0.)); + assert!(from_str(~".e1") == Some(0.)); + assert!(from_str(~".e-1") == Some(0.)); + assert!(from_str(~"5.") == Some(5.)); + assert!(from_str(~".5") == Some(0.5)); + assert!(from_str(~"0.5") == Some(0.5)); + assert!(from_str(~"-.5") == Some(-0.5)); + assert!(from_str(~"-5") == Some(-5.)); + assert!(from_str(~"inf") == Some(infinity)); + assert!(from_str(~"+inf") == Some(infinity)); + assert!(from_str(~"-inf") == Some(neg_infinity)); + // note: NaN != NaN, hence this slightly complex test + match from_str(~"NaN") { + Some(f) => assert!(is_NaN(f)), + None => fail!() + } + // note: -0 == 0, hence these slightly more complex tests + match from_str(~"-0") { + Some(v) if is_zero(v) => assert!(is_negative(v)), + _ => fail!() + } + match from_str(~"0") { + Some(v) if is_zero(v) => assert!(is_positive(v)), + _ => fail!() + } + + assert!(from_str(~"").is_none()); + assert!(from_str(~"x").is_none()); + assert!(from_str(~" ").is_none()); + assert!(from_str(~" ").is_none()); + assert!(from_str(~"e").is_none()); + assert!(from_str(~"E").is_none()); + assert!(from_str(~"E1").is_none()); + assert!(from_str(~"1e1e1").is_none()); + assert!(from_str(~"1e1.1").is_none()); + assert!(from_str(~"1e1-1").is_none()); + } + + #[test] + pub fn test_from_str_hex() { + assert!(from_str_hex(~"a4") == Some(164.)); + assert!(from_str_hex(~"a4.fe") == Some(164.9921875)); + assert!(from_str_hex(~"-a4.fe") == Some(-164.9921875)); + assert!(from_str_hex(~"+a4.fe") == Some(164.9921875)); + assert!(from_str_hex(~"ff0P4") == Some(0xff00 as float)); + assert!(from_str_hex(~"ff0p4") == Some(0xff00 as float)); + assert!(from_str_hex(~"ff0p-4") == Some(0xff as float)); + assert!(from_str_hex(~".") == Some(0.)); + assert!(from_str_hex(~".p1") == Some(0.)); + assert!(from_str_hex(~".p-1") == Some(0.)); + assert!(from_str_hex(~"f.") == Some(15.)); + assert!(from_str_hex(~".f") == Some(0.9375)); + assert!(from_str_hex(~"0.f") == Some(0.9375)); + assert!(from_str_hex(~"-.f") == Some(-0.9375)); + assert!(from_str_hex(~"-f") == Some(-15.)); + assert!(from_str_hex(~"inf") == Some(infinity)); + assert!(from_str_hex(~"+inf") == Some(infinity)); + assert!(from_str_hex(~"-inf") == Some(neg_infinity)); + // note: NaN != NaN, hence this slightly complex test + match from_str_hex(~"NaN") { + Some(f) => assert!(is_NaN(f)), + None => fail!() + } + // note: -0 == 0, hence these slightly more complex tests + match from_str_hex(~"-0") { + Some(v) if is_zero(v) => assert!(is_negative(v)), + _ => fail!() + } + match from_str_hex(~"0") { + Some(v) if is_zero(v) => assert!(is_positive(v)), + _ => fail!() + } + assert!(from_str_hex(~"e") == Some(14.)); + assert!(from_str_hex(~"E") == Some(14.)); + assert!(from_str_hex(~"E1") == Some(225.)); + assert!(from_str_hex(~"1e1e1") == Some(123361.)); + assert!(from_str_hex(~"1e1.1") == Some(481.0625)); + + assert!(from_str_hex(~"").is_none()); + assert!(from_str_hex(~"x").is_none()); + assert!(from_str_hex(~" ").is_none()); + assert!(from_str_hex(~" ").is_none()); + assert!(from_str_hex(~"p").is_none()); + assert!(from_str_hex(~"P").is_none()); + assert!(from_str_hex(~"P1").is_none()); + assert!(from_str_hex(~"1p1p1").is_none()); + assert!(from_str_hex(~"1p1.1").is_none()); + assert!(from_str_hex(~"1p1-1").is_none()); + } + + #[test] + pub fn test_to_str_hex() { + assert!(to_str_hex(164.) == ~"a4"); + assert!(to_str_hex(164.9921875) == ~"a4.fe"); + assert!(to_str_hex(-164.9921875) == ~"-a4.fe"); + assert!(to_str_hex(0xff00 as float) == ~"ff00"); + assert!(to_str_hex(-(0xff00 as float)) == ~"-ff00"); + assert!(to_str_hex(0.) == ~"0"); + assert!(to_str_hex(15.) == ~"f"); + assert!(to_str_hex(-15.) == ~"-f"); + assert!(to_str_hex(0.9375) == ~"0.f"); + assert!(to_str_hex(-0.9375) == ~"-0.f"); + assert!(to_str_hex(infinity) == ~"inf"); + assert!(to_str_hex(neg_infinity) == ~"-inf"); + assert!(to_str_hex(NaN) == ~"NaN"); + assert!(to_str_hex(0.) == ~"0"); + assert!(to_str_hex(-0.) == ~"-0"); + } + #[test] + pub fn test_to_str_radix() { + assert!(to_str_radix(36., 36u) == ~"10"); + assert!(to_str_radix(8.125, 2u) == ~"1000.001"); + } + + #[test] + pub fn test_from_str_radix() { + assert!(from_str_radix(~"10", 36u) == Some(36.)); + assert!(from_str_radix(~"1000.001", 2u) == Some(8.125)); + } + + #[test] + pub fn test_positive() { + assert!((is_positive(infinity))); + assert!((is_positive(1.))); + assert!((is_positive(0.))); + assert!((!is_positive(-1.))); + assert!((!is_positive(neg_infinity))); + assert!((!is_positive(1./neg_infinity))); + assert!((!is_positive(NaN))); + } + + #[test] + pub fn test_negative() { + assert!((!is_negative(infinity))); + assert!((!is_negative(1.))); + assert!((!is_negative(0.))); + assert!((is_negative(-1.))); + assert!((is_negative(neg_infinity))); + assert!((is_negative(1./neg_infinity))); + assert!((!is_negative(NaN))); + } + + #[test] + pub fn test_nonpositive() { + assert!((!is_nonpositive(infinity))); + assert!((!is_nonpositive(1.))); + assert!((!is_nonpositive(0.))); + assert!((is_nonpositive(-1.))); + assert!((is_nonpositive(neg_infinity))); + assert!((is_nonpositive(1./neg_infinity))); + assert!((!is_nonpositive(NaN))); + } + + #[test] + pub fn test_nonnegative() { + assert!((is_nonnegative(infinity))); + assert!((is_nonnegative(1.))); + assert!((is_nonnegative(0.))); + assert!((!is_nonnegative(-1.))); + assert!((!is_nonnegative(neg_infinity))); + assert!((!is_nonnegative(1./neg_infinity))); + assert!((!is_nonnegative(NaN))); + } + + #[test] + pub fn test_to_str_inf() { + assert!(to_str_digits(infinity, 10u) == ~"inf"); + assert!(to_str_digits(-infinity, 10u) == ~"-inf"); + } + + #[test] + pub fn test_round() { + assert!(round(5.8) == 6.0); + assert!(round(5.2) == 5.0); + assert!(round(3.0) == 3.0); + assert!(round(2.5) == 3.0); + assert!(round(-3.5) == -4.0); + } +} // // Local Variables: diff --git a/src/libcore/num/int-template.rs b/src/libcore/num/int-template.rs index 6fbe44737d1..b495f9e7088 100644 --- a/src/libcore/num/int-template.rs +++ b/src/libcore/num/int-template.rs @@ -277,181 +277,188 @@ impl ToStrRadix for T { } } -#[test] -fn test_from_str() { - assert!(from_str(~"0") == Some(0 as T)); - assert!(from_str(~"3") == Some(3 as T)); - assert!(from_str(~"10") == Some(10 as T)); - assert!(i32::from_str(~"123456789") == Some(123456789 as i32)); - assert!(from_str(~"00100") == Some(100 as T)); - - assert!(from_str(~"-1") == Some(-1 as T)); - assert!(from_str(~"-3") == Some(-3 as T)); - assert!(from_str(~"-10") == Some(-10 as T)); - assert!(i32::from_str(~"-123456789") == Some(-123456789 as i32)); - assert!(from_str(~"-00100") == Some(-100 as T)); - - assert!(from_str(~" ").is_none()); - assert!(from_str(~"x").is_none()); -} +#[cfg(test)] +mod tests { + use super::*; + use super::inst::T; + use prelude::*; + + #[test] + fn test_from_str() { + assert!(from_str(~"0") == Some(0 as T)); + assert!(from_str(~"3") == Some(3 as T)); + assert!(from_str(~"10") == Some(10 as T)); + assert!(i32::from_str(~"123456789") == Some(123456789 as i32)); + assert!(from_str(~"00100") == Some(100 as T)); + + assert!(from_str(~"-1") == Some(-1 as T)); + assert!(from_str(~"-3") == Some(-3 as T)); + assert!(from_str(~"-10") == Some(-10 as T)); + assert!(i32::from_str(~"-123456789") == Some(-123456789 as i32)); + assert!(from_str(~"-00100") == Some(-100 as T)); + + assert!(from_str(~" ").is_none()); + assert!(from_str(~"x").is_none()); + } -#[test] -fn test_parse_bytes() { - use str::to_bytes; - assert!(parse_bytes(to_bytes(~"123"), 10u) == Some(123 as T)); - assert!(parse_bytes(to_bytes(~"1001"), 2u) == Some(9 as T)); - assert!(parse_bytes(to_bytes(~"123"), 8u) == Some(83 as T)); - assert!(i32::parse_bytes(to_bytes(~"123"), 16u) == Some(291 as i32)); - assert!(i32::parse_bytes(to_bytes(~"ffff"), 16u) == - Some(65535 as i32)); - assert!(i32::parse_bytes(to_bytes(~"FFFF"), 16u) == - Some(65535 as i32)); - assert!(parse_bytes(to_bytes(~"z"), 36u) == Some(35 as T)); - assert!(parse_bytes(to_bytes(~"Z"), 36u) == Some(35 as T)); - - assert!(parse_bytes(to_bytes(~"-123"), 10u) == Some(-123 as T)); - assert!(parse_bytes(to_bytes(~"-1001"), 2u) == Some(-9 as T)); - assert!(parse_bytes(to_bytes(~"-123"), 8u) == Some(-83 as T)); - assert!(i32::parse_bytes(to_bytes(~"-123"), 16u) == - Some(-291 as i32)); - assert!(i32::parse_bytes(to_bytes(~"-ffff"), 16u) == - Some(-65535 as i32)); - assert!(i32::parse_bytes(to_bytes(~"-FFFF"), 16u) == - Some(-65535 as i32)); - assert!(parse_bytes(to_bytes(~"-z"), 36u) == Some(-35 as T)); - assert!(parse_bytes(to_bytes(~"-Z"), 36u) == Some(-35 as T)); - - assert!(parse_bytes(to_bytes(~"Z"), 35u).is_none()); - assert!(parse_bytes(to_bytes(~"-9"), 2u).is_none()); -} + #[test] + fn test_parse_bytes() { + use str::to_bytes; + assert!(parse_bytes(to_bytes(~"123"), 10u) == Some(123 as T)); + assert!(parse_bytes(to_bytes(~"1001"), 2u) == Some(9 as T)); + assert!(parse_bytes(to_bytes(~"123"), 8u) == Some(83 as T)); + assert!(i32::parse_bytes(to_bytes(~"123"), 16u) == Some(291 as i32)); + assert!(i32::parse_bytes(to_bytes(~"ffff"), 16u) == + Some(65535 as i32)); + assert!(i32::parse_bytes(to_bytes(~"FFFF"), 16u) == + Some(65535 as i32)); + assert!(parse_bytes(to_bytes(~"z"), 36u) == Some(35 as T)); + assert!(parse_bytes(to_bytes(~"Z"), 36u) == Some(35 as T)); + + assert!(parse_bytes(to_bytes(~"-123"), 10u) == Some(-123 as T)); + assert!(parse_bytes(to_bytes(~"-1001"), 2u) == Some(-9 as T)); + assert!(parse_bytes(to_bytes(~"-123"), 8u) == Some(-83 as T)); + assert!(i32::parse_bytes(to_bytes(~"-123"), 16u) == + Some(-291 as i32)); + assert!(i32::parse_bytes(to_bytes(~"-ffff"), 16u) == + Some(-65535 as i32)); + assert!(i32::parse_bytes(to_bytes(~"-FFFF"), 16u) == + Some(-65535 as i32)); + assert!(parse_bytes(to_bytes(~"-z"), 36u) == Some(-35 as T)); + assert!(parse_bytes(to_bytes(~"-Z"), 36u) == Some(-35 as T)); + + assert!(parse_bytes(to_bytes(~"Z"), 35u).is_none()); + assert!(parse_bytes(to_bytes(~"-9"), 2u).is_none()); + } -#[test] -fn test_to_str() { - assert!((to_str_radix(0 as T, 10u) == ~"0")); - assert!((to_str_radix(1 as T, 10u) == ~"1")); - assert!((to_str_radix(-1 as T, 10u) == ~"-1")); - assert!((to_str_radix(127 as T, 16u) == ~"7f")); - assert!((to_str_radix(100 as T, 10u) == ~"100")); + #[test] + fn test_to_str() { + assert!((to_str_radix(0 as T, 10u) == ~"0")); + assert!((to_str_radix(1 as T, 10u) == ~"1")); + assert!((to_str_radix(-1 as T, 10u) == ~"-1")); + assert!((to_str_radix(127 as T, 16u) == ~"7f")); + assert!((to_str_radix(100 as T, 10u) == ~"100")); -} + } -#[test] -fn test_int_to_str_overflow() { - let mut i8_val: i8 = 127_i8; - assert!((i8::to_str(i8_val) == ~"127")); + #[test] + fn test_int_to_str_overflow() { + let mut i8_val: i8 = 127_i8; + assert!((i8::to_str(i8_val) == ~"127")); - i8_val += 1 as i8; - assert!((i8::to_str(i8_val) == ~"-128")); + i8_val += 1 as i8; + assert!((i8::to_str(i8_val) == ~"-128")); - let mut i16_val: i16 = 32_767_i16; - assert!((i16::to_str(i16_val) == ~"32767")); + let mut i16_val: i16 = 32_767_i16; + assert!((i16::to_str(i16_val) == ~"32767")); - i16_val += 1 as i16; - assert!((i16::to_str(i16_val) == ~"-32768")); + i16_val += 1 as i16; + assert!((i16::to_str(i16_val) == ~"-32768")); - let mut i32_val: i32 = 2_147_483_647_i32; - assert!((i32::to_str(i32_val) == ~"2147483647")); + let mut i32_val: i32 = 2_147_483_647_i32; + assert!((i32::to_str(i32_val) == ~"2147483647")); - i32_val += 1 as i32; - assert!((i32::to_str(i32_val) == ~"-2147483648")); + i32_val += 1 as i32; + assert!((i32::to_str(i32_val) == ~"-2147483648")); - let mut i64_val: i64 = 9_223_372_036_854_775_807_i64; - assert!((i64::to_str(i64_val) == ~"9223372036854775807")); + let mut i64_val: i64 = 9_223_372_036_854_775_807_i64; + assert!((i64::to_str(i64_val) == ~"9223372036854775807")); - i64_val += 1 as i64; - assert!((i64::to_str(i64_val) == ~"-9223372036854775808")); -} + i64_val += 1 as i64; + assert!((i64::to_str(i64_val) == ~"-9223372036854775808")); + } -#[test] -fn test_int_from_str_overflow() { - let mut i8_val: i8 = 127_i8; - assert!((i8::from_str(~"127") == Some(i8_val))); - assert!((i8::from_str(~"128").is_none())); + #[test] + fn test_int_from_str_overflow() { + let mut i8_val: i8 = 127_i8; + assert!((i8::from_str(~"127") == Some(i8_val))); + assert!((i8::from_str(~"128").is_none())); - i8_val += 1 as i8; - assert!((i8::from_str(~"-128") == Some(i8_val))); - assert!((i8::from_str(~"-129").is_none())); + i8_val += 1 as i8; + assert!((i8::from_str(~"-128") == Some(i8_val))); + assert!((i8::from_str(~"-129").is_none())); - let mut i16_val: i16 = 32_767_i16; - assert!((i16::from_str(~"32767") == Some(i16_val))); - assert!((i16::from_str(~"32768").is_none())); + let mut i16_val: i16 = 32_767_i16; + assert!((i16::from_str(~"32767") == Some(i16_val))); + assert!((i16::from_str(~"32768").is_none())); - i16_val += 1 as i16; - assert!((i16::from_str(~"-32768") == Some(i16_val))); - assert!((i16::from_str(~"-32769").is_none())); + i16_val += 1 as i16; + assert!((i16::from_str(~"-32768") == Some(i16_val))); + assert!((i16::from_str(~"-32769").is_none())); - let mut i32_val: i32 = 2_147_483_647_i32; - assert!((i32::from_str(~"2147483647") == Some(i32_val))); - assert!((i32::from_str(~"2147483648").is_none())); + let mut i32_val: i32 = 2_147_483_647_i32; + assert!((i32::from_str(~"2147483647") == Some(i32_val))); + assert!((i32::from_str(~"2147483648").is_none())); - i32_val += 1 as i32; - assert!((i32::from_str(~"-2147483648") == Some(i32_val))); - assert!((i32::from_str(~"-2147483649").is_none())); + i32_val += 1 as i32; + assert!((i32::from_str(~"-2147483648") == Some(i32_val))); + assert!((i32::from_str(~"-2147483649").is_none())); - let mut i64_val: i64 = 9_223_372_036_854_775_807_i64; - assert!((i64::from_str(~"9223372036854775807") == Some(i64_val))); - assert!((i64::from_str(~"9223372036854775808").is_none())); + let mut i64_val: i64 = 9_223_372_036_854_775_807_i64; + assert!((i64::from_str(~"9223372036854775807") == Some(i64_val))); + assert!((i64::from_str(~"9223372036854775808").is_none())); - i64_val += 1 as i64; - assert!((i64::from_str(~"-9223372036854775808") == Some(i64_val))); - assert!((i64::from_str(~"-9223372036854775809").is_none())); -} + i64_val += 1 as i64; + assert!((i64::from_str(~"-9223372036854775808") == Some(i64_val))); + assert!((i64::from_str(~"-9223372036854775809").is_none())); + } -#[test] -pub fn test_ranges() { - let mut l = ~[]; + #[test] + fn test_ranges() { + let mut l = ~[]; - for range(0,3) |i| { - l.push(i); - } - for range_rev(13,10) |i| { - l.push(i); - } - for range_step(20,26,2) |i| { - l.push(i); - } - for range_step(36,30,-2) |i| { - l.push(i); - } - for range_step(max_value - 2, max_value, 2) |i| { - l.push(i); - } - for range_step(max_value - 3, max_value, 2) |i| { - l.push(i); - } - for range_step(min_value + 2, min_value, -2) |i| { - l.push(i); - } - for range_step(min_value + 3, min_value, -2) |i| { - l.push(i); - } - assert_eq!(l, ~[0,1,2, - 13,12,11, - 20,22,24, - 36,34,32, - max_value-2, - max_value-3,max_value-1, - min_value+2, - min_value+3,min_value+1]); - - // None of the `fail`s should execute. - for range(10,0) |_i| { - fail!(~"unreachable"); - } - for range_rev(0,10) |_i| { - fail!(~"unreachable"); - } - for range_step(10,0,1) |_i| { - fail!(~"unreachable"); - } - for range_step(0,10,-1) |_i| { - fail!(~"unreachable"); + for range(0,3) |i| { + l.push(i); + } + for range_rev(13,10) |i| { + l.push(i); + } + for range_step(20,26,2) |i| { + l.push(i); + } + for range_step(36,30,-2) |i| { + l.push(i); + } + for range_step(max_value - 2, max_value, 2) |i| { + l.push(i); + } + for range_step(max_value - 3, max_value, 2) |i| { + l.push(i); + } + for range_step(min_value + 2, min_value, -2) |i| { + l.push(i); + } + for range_step(min_value + 3, min_value, -2) |i| { + l.push(i); + } + assert_eq!(l, ~[0,1,2, + 13,12,11, + 20,22,24, + 36,34,32, + max_value-2, + max_value-3,max_value-1, + min_value+2, + min_value+3,min_value+1]); + + // None of the `fail`s should execute. + for range(10,0) |_i| { + fail!(~"unreachable"); + } + for range_rev(0,10) |_i| { + fail!(~"unreachable"); + } + for range_step(10,0,1) |_i| { + fail!(~"unreachable"); + } + for range_step(0,10,-1) |_i| { + fail!(~"unreachable"); + } } -} -#[test] -#[should_fail] -#[ignore(cfg(windows))] -fn test_range_step_zero_step() { - for range_step(0,10,0) |_i| {} -} + #[test] + #[should_fail] + #[ignore(cfg(windows))] + fn test_range_step_zero_step() { + for range_step(0,10,0) |_i| {} + } +} \ No newline at end of file diff --git a/src/libcore/num/uint-template.rs b/src/libcore/num/uint-template.rs index 1cbdabafdab..af6557e9881 100644 --- a/src/libcore/num/uint-template.rs +++ b/src/libcore/num/uint-template.rs @@ -242,184 +242,190 @@ impl ToStrRadix for T { } } -#[test] -pub fn test_to_str() { - assert!(to_str_radix(0 as T, 10u) == ~"0"); - assert!(to_str_radix(1 as T, 10u) == ~"1"); - assert!(to_str_radix(2 as T, 10u) == ~"2"); - assert!(to_str_radix(11 as T, 10u) == ~"11"); - assert!(to_str_radix(11 as T, 16u) == ~"b"); - assert!(to_str_radix(255 as T, 16u) == ~"ff"); - assert!(to_str_radix(0xff as T, 10u) == ~"255"); -} +#[cfg(test)] +mod tests { + use super::*; + use super::inst::T; + use prelude::*; + #[test] + pub fn test_to_str() { + assert!(to_str_radix(0 as T, 10u) == ~"0"); + assert!(to_str_radix(1 as T, 10u) == ~"1"); + assert!(to_str_radix(2 as T, 10u) == ~"2"); + assert!(to_str_radix(11 as T, 10u) == ~"11"); + assert!(to_str_radix(11 as T, 16u) == ~"b"); + assert!(to_str_radix(255 as T, 16u) == ~"ff"); + assert!(to_str_radix(0xff as T, 10u) == ~"255"); + } -#[test] -pub fn test_from_str() { - assert!(from_str(~"0") == Some(0u as T)); - assert!(from_str(~"3") == Some(3u as T)); - assert!(from_str(~"10") == Some(10u as T)); - assert!(u32::from_str(~"123456789") == Some(123456789 as u32)); - assert!(from_str(~"00100") == Some(100u as T)); - - assert!(from_str(~"").is_none()); - assert!(from_str(~" ").is_none()); - assert!(from_str(~"x").is_none()); -} + #[test] + pub fn test_from_str() { + assert!(from_str(~"0") == Some(0u as T)); + assert!(from_str(~"3") == Some(3u as T)); + assert!(from_str(~"10") == Some(10u as T)); + assert!(u32::from_str(~"123456789") == Some(123456789 as u32)); + assert!(from_str(~"00100") == Some(100u as T)); + + assert!(from_str(~"").is_none()); + assert!(from_str(~" ").is_none()); + assert!(from_str(~"x").is_none()); + } -#[test] -pub fn test_parse_bytes() { - use str::to_bytes; - assert!(parse_bytes(to_bytes(~"123"), 10u) == Some(123u as T)); - assert!(parse_bytes(to_bytes(~"1001"), 2u) == Some(9u as T)); - assert!(parse_bytes(to_bytes(~"123"), 8u) == Some(83u as T)); - assert!(u16::parse_bytes(to_bytes(~"123"), 16u) == - Some(291u as u16)); - assert!(u16::parse_bytes(to_bytes(~"ffff"), 16u) == - Some(65535u as u16)); - assert!(parse_bytes(to_bytes(~"z"), 36u) == Some(35u as T)); - - assert!(parse_bytes(to_bytes(~"Z"), 10u).is_none()); - assert!(parse_bytes(to_bytes(~"_"), 2u).is_none()); -} + #[test] + pub fn test_parse_bytes() { + use str::to_bytes; + assert!(parse_bytes(to_bytes(~"123"), 10u) == Some(123u as T)); + assert!(parse_bytes(to_bytes(~"1001"), 2u) == Some(9u as T)); + assert!(parse_bytes(to_bytes(~"123"), 8u) == Some(83u as T)); + assert!(u16::parse_bytes(to_bytes(~"123"), 16u) == + Some(291u as u16)); + assert!(u16::parse_bytes(to_bytes(~"ffff"), 16u) == + Some(65535u as u16)); + assert!(parse_bytes(to_bytes(~"z"), 36u) == Some(35u as T)); + + assert!(parse_bytes(to_bytes(~"Z"), 10u).is_none()); + assert!(parse_bytes(to_bytes(~"_"), 2u).is_none()); + } -#[test] -fn test_uint_to_str_overflow() { - let mut u8_val: u8 = 255_u8; - assert!((u8::to_str(u8_val) == ~"255")); + #[test] + fn test_uint_to_str_overflow() { + let mut u8_val: u8 = 255_u8; + assert!((u8::to_str(u8_val) == ~"255")); - u8_val += 1 as u8; - assert!((u8::to_str(u8_val) == ~"0")); + u8_val += 1 as u8; + assert!((u8::to_str(u8_val) == ~"0")); - let mut u16_val: u16 = 65_535_u16; - assert!((u16::to_str(u16_val) == ~"65535")); + let mut u16_val: u16 = 65_535_u16; + assert!((u16::to_str(u16_val) == ~"65535")); - u16_val += 1 as u16; - assert!((u16::to_str(u16_val) == ~"0")); + u16_val += 1 as u16; + assert!((u16::to_str(u16_val) == ~"0")); - let mut u32_val: u32 = 4_294_967_295_u32; - assert!((u32::to_str(u32_val) == ~"4294967295")); + let mut u32_val: u32 = 4_294_967_295_u32; + assert!((u32::to_str(u32_val) == ~"4294967295")); - u32_val += 1 as u32; - assert!((u32::to_str(u32_val) == ~"0")); + u32_val += 1 as u32; + assert!((u32::to_str(u32_val) == ~"0")); - let mut u64_val: u64 = 18_446_744_073_709_551_615_u64; - assert!((u64::to_str(u64_val) == ~"18446744073709551615")); + let mut u64_val: u64 = 18_446_744_073_709_551_615_u64; + assert!((u64::to_str(u64_val) == ~"18446744073709551615")); - u64_val += 1 as u64; - assert!((u64::to_str(u64_val) == ~"0")); -} + u64_val += 1 as u64; + assert!((u64::to_str(u64_val) == ~"0")); + } -#[test] -fn test_uint_from_str_overflow() { - let mut u8_val: u8 = 255_u8; - assert!((u8::from_str(~"255") == Some(u8_val))); - assert!((u8::from_str(~"256").is_none())); + #[test] + fn test_uint_from_str_overflow() { + let mut u8_val: u8 = 255_u8; + assert!((u8::from_str(~"255") == Some(u8_val))); + assert!((u8::from_str(~"256").is_none())); - u8_val += 1 as u8; - assert!((u8::from_str(~"0") == Some(u8_val))); - assert!((u8::from_str(~"-1").is_none())); + u8_val += 1 as u8; + assert!((u8::from_str(~"0") == Some(u8_val))); + assert!((u8::from_str(~"-1").is_none())); - let mut u16_val: u16 = 65_535_u16; - assert!((u16::from_str(~"65535") == Some(u16_val))); - assert!((u16::from_str(~"65536").is_none())); + let mut u16_val: u16 = 65_535_u16; + assert!((u16::from_str(~"65535") == Some(u16_val))); + assert!((u16::from_str(~"65536").is_none())); - u16_val += 1 as u16; - assert!((u16::from_str(~"0") == Some(u16_val))); - assert!((u16::from_str(~"-1").is_none())); + u16_val += 1 as u16; + assert!((u16::from_str(~"0") == Some(u16_val))); + assert!((u16::from_str(~"-1").is_none())); - let mut u32_val: u32 = 4_294_967_295_u32; - assert!((u32::from_str(~"4294967295") == Some(u32_val))); - assert!((u32::from_str(~"4294967296").is_none())); + let mut u32_val: u32 = 4_294_967_295_u32; + assert!((u32::from_str(~"4294967295") == Some(u32_val))); + assert!((u32::from_str(~"4294967296").is_none())); - u32_val += 1 as u32; - assert!((u32::from_str(~"0") == Some(u32_val))); - assert!((u32::from_str(~"-1").is_none())); + u32_val += 1 as u32; + assert!((u32::from_str(~"0") == Some(u32_val))); + assert!((u32::from_str(~"-1").is_none())); - let mut u64_val: u64 = 18_446_744_073_709_551_615_u64; - assert!((u64::from_str(~"18446744073709551615") == Some(u64_val))); - assert!((u64::from_str(~"18446744073709551616").is_none())); + let mut u64_val: u64 = 18_446_744_073_709_551_615_u64; + assert!((u64::from_str(~"18446744073709551615") == Some(u64_val))); + assert!((u64::from_str(~"18446744073709551616").is_none())); - u64_val += 1 as u64; - assert!((u64::from_str(~"0") == Some(u64_val))); - assert!((u64::from_str(~"-1").is_none())); -} + u64_val += 1 as u64; + assert!((u64::from_str(~"0") == Some(u64_val))); + assert!((u64::from_str(~"-1").is_none())); + } -#[test] -#[should_fail] -#[ignore(cfg(windows))] -pub fn to_str_radix1() { - uint::to_str_radix(100u, 1u); -} + #[test] + #[should_fail] + #[ignore(cfg(windows))] + pub fn to_str_radix1() { + uint::to_str_radix(100u, 1u); + } -#[test] -#[should_fail] -#[ignore(cfg(windows))] -pub fn to_str_radix37() { - uint::to_str_radix(100u, 37u); -} + #[test] + #[should_fail] + #[ignore(cfg(windows))] + pub fn to_str_radix37() { + uint::to_str_radix(100u, 37u); + } -#[test] -pub fn test_ranges() { - let mut l = ~[]; + #[test] + pub fn test_ranges() { + let mut l = ~[]; - for range(0,3) |i| { - l.push(i); - } - for range_rev(13,10) |i| { - l.push(i); - } - for range_step(20,26,2) |i| { - l.push(i); - } - for range_step(36,30,-2) |i| { - l.push(i); - } - for range_step(max_value - 2, max_value, 2) |i| { - l.push(i); - } - for range_step(max_value - 3, max_value, 2) |i| { - l.push(i); - } - for range_step(min_value + 2, min_value, -2) |i| { - l.push(i); - } - for range_step(min_value + 3, min_value, -2) |i| { - l.push(i); - } + for range(0,3) |i| { + l.push(i); + } + for range_rev(13,10) |i| { + l.push(i); + } + for range_step(20,26,2) |i| { + l.push(i); + } + for range_step(36,30,-2) |i| { + l.push(i); + } + for range_step(max_value - 2, max_value, 2) |i| { + l.push(i); + } + for range_step(max_value - 3, max_value, 2) |i| { + l.push(i); + } + for range_step(min_value + 2, min_value, -2) |i| { + l.push(i); + } + for range_step(min_value + 3, min_value, -2) |i| { + l.push(i); + } - assert_eq!(l, ~[0,1,2, - 13,12,11, - 20,22,24, - 36,34,32, - max_value-2, - max_value-3,max_value-1, - min_value+2, - min_value+3,min_value+1]); - - // None of the `fail`s should execute. - for range(0,0) |_i| { - fail!(~"unreachable"); - } - for range_rev(0,0) |_i| { - fail!(~"unreachable"); + assert_eq!(l, ~[0,1,2, + 13,12,11, + 20,22,24, + 36,34,32, + max_value-2, + max_value-3,max_value-1, + min_value+2, + min_value+3,min_value+1]); + + // None of the `fail`s should execute. + for range(0,0) |_i| { + fail!(~"unreachable"); + } + for range_rev(0,0) |_i| { + fail!(~"unreachable"); + } + for range_step(10,0,1) |_i| { + fail!(~"unreachable"); + } + for range_step(0,1,-10) |_i| { + fail!(~"unreachable"); + } } - for range_step(10,0,1) |_i| { - fail!(~"unreachable"); + + #[test] + #[should_fail] + #[ignore(cfg(windows))] + fn test_range_step_zero_step_up() { + for range_step(0,10,0) |_i| {} } - for range_step(0,1,-10) |_i| { - fail!(~"unreachable"); + #[test] + #[should_fail] + #[ignore(cfg(windows))] + fn test_range_step_zero_step_down() { + for range_step(0,-10,0) |_i| {} } -} - -#[test] -#[should_fail] -#[ignore(cfg(windows))] -fn test_range_step_zero_step_up() { - for range_step(0,10,0) |_i| {} -} -#[test] -#[should_fail] -#[ignore(cfg(windows))] -fn test_range_step_zero_step_down() { - for range_step(0,-10,0) |_i| {} -} +} \ No newline at end of file diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 18f8030d5b8..fddb2af5587 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -957,13 +957,13 @@ pub mod rt { } #[cfg(test)] -pub mod test { +mod test { use either::Right; use comm::{Chan, Port, oneshot, recv_one, stream, Select2, GenericChan, Peekable}; #[test] - pub fn test_select2() { + fn test_select2() { let (p1, c1) = stream(); let (p2, c2) = stream(); @@ -978,7 +978,7 @@ pub mod test { } #[test] - pub fn test_oneshot() { + fn test_oneshot() { let (c, p) = oneshot::init(); oneshot::client::send(c, ()); diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 14e17de4fbd..ebde37e77b4 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -15,8 +15,6 @@ use libc; use libc::{c_void, size_t}; use sys; -#[cfg(test)] use vec; -#[cfg(test)] use str; #[cfg(notest)] use cmp::{Eq, Ord}; use uint; @@ -341,101 +339,101 @@ impl<'self,T:Ord> Ord for &'self const T { } } -#[test] -pub fn test() { - unsafe { - struct Pair {mut fst: int, mut snd: int}; - let mut p = Pair {fst: 10, snd: 20}; - let pptr: *mut Pair = &mut p; - let iptr: *mut int = cast::reinterpret_cast(&pptr); - assert!((*iptr == 10));; - *iptr = 30; - assert!((*iptr == 30)); - assert!((p.fst == 30));; - - *pptr = Pair {fst: 50, snd: 60}; - assert!((*iptr == 50)); - assert!((p.fst == 50)); - assert!((p.snd == 60)); - - let mut v0 = ~[32000u16, 32001u16, 32002u16]; - let mut v1 = ~[0u16, 0u16, 0u16]; - - copy_memory(mut_offset(vec::raw::to_mut_ptr(v1), 1u), - offset(vec::raw::to_ptr(v0), 1u), 1u); - assert!((v1[0] == 0u16 && v1[1] == 32001u16 && v1[2] == 0u16)); - copy_memory(vec::raw::to_mut_ptr(v1), - offset(vec::raw::to_ptr(v0), 2u), 1u); - assert!((v1[0] == 32002u16 && v1[1] == 32001u16 && - v1[2] == 0u16)); - copy_memory(mut_offset(vec::raw::to_mut_ptr(v1), 2u), - vec::raw::to_ptr(v0), 1u); - assert!((v1[0] == 32002u16 && v1[1] == 32001u16 && - v1[2] == 32000u16)); +#[cfg(test)] +pub mod ptr_tests { + use super::*; + use prelude::*; + + #[test] + fn test() { + unsafe { + struct Pair {mut fst: int, mut snd: int}; + let mut p = Pair {fst: 10, snd: 20}; + let pptr: *mut Pair = &mut p; + let iptr: *mut int = cast::reinterpret_cast(&pptr); + assert!((*iptr == 10));; + *iptr = 30; + assert!((*iptr == 30)); + assert!((p.fst == 30));; + + *pptr = Pair {fst: 50, snd: 60}; + assert!((*iptr == 50)); + assert!((p.fst == 50)); + assert!((p.snd == 60)); + + let mut v0 = ~[32000u16, 32001u16, 32002u16]; + let mut v1 = ~[0u16, 0u16, 0u16]; + + copy_memory(mut_offset(vec::raw::to_mut_ptr(v1), 1u), + offset(vec::raw::to_ptr(v0), 1u), 1u); + assert!((v1[0] == 0u16 && v1[1] == 32001u16 && v1[2] == 0u16)); + copy_memory(vec::raw::to_mut_ptr(v1), + offset(vec::raw::to_ptr(v0), 2u), 1u); + assert!((v1[0] == 32002u16 && v1[1] == 32001u16 && + v1[2] == 0u16)); + copy_memory(mut_offset(vec::raw::to_mut_ptr(v1), 2u), + vec::raw::to_ptr(v0), 1u); + assert!((v1[0] == 32002u16 && v1[1] == 32001u16 && + v1[2] == 32000u16)); + } } -} -#[test] -pub fn test_position() { - use str::as_c_str; - use libc::c_char; + #[test] + fn test_position() { + use str::as_c_str; + use libc::c_char; - let s = ~"hello"; - unsafe { - assert!(2u == as_c_str(s, |p| position(p, - |c| *c == 'l' as c_char))); - assert!(4u == as_c_str(s, |p| position(p, - |c| *c == 'o' as c_char))); - assert!(5u == as_c_str(s, |p| position(p, - |c| *c == 0 as c_char))); + let s = ~"hello"; + unsafe { + assert!(2u == as_c_str(s, |p| position(p, + |c| *c == 'l' as c_char))); + assert!(4u == as_c_str(s, |p| position(p, + |c| *c == 'o' as c_char))); + assert!(5u == as_c_str(s, |p| position(p, + |c| *c == 0 as c_char))); + } } -} -#[test] -pub fn test_buf_len() { - let s0 = ~"hello"; - let s1 = ~"there"; - let s2 = ~"thing"; - do str::as_c_str(s0) |p0| { - do str::as_c_str(s1) |p1| { - do str::as_c_str(s2) |p2| { - let v = ~[p0, p1, p2, null()]; - do vec::as_imm_buf(v) |vp, len| { - assert!(unsafe { buf_len(vp) } == 3u); - assert!(len == 4u); + #[test] + fn test_buf_len() { + let s0 = ~"hello"; + let s1 = ~"there"; + let s2 = ~"thing"; + do str::as_c_str(s0) |p0| { + do str::as_c_str(s1) |p1| { + do str::as_c_str(s2) |p2| { + let v = ~[p0, p1, p2, null()]; + do vec::as_imm_buf(v) |vp, len| { + assert!(unsafe { buf_len(vp) } == 3u); + assert!(len == 4u); + } } } } } -} - -#[test] -pub fn test_is_null() { - let p: *int = null(); - assert!(p.is_null()); - assert!(!p.is_not_null()); - let q = offset(p, 1u); - assert!(!q.is_null()); - assert!(q.is_not_null()); - - let mp: *mut int = mut_null(); - assert!(mp.is_null()); - assert!(!mp.is_not_null()); + #[test] + fn test_is_null() { + let p: *int = null(); + assert!(p.is_null()); + assert!(!p.is_not_null()); + + let q = offset(p, 1u); + assert!(!q.is_null()); + assert!(q.is_not_null()); + + let mp: *mut int = mut_null(); + assert!(mp.is_null()); + assert!(!mp.is_not_null()); + + let mq = mp.offset(1u); + assert!(!mq.is_null()); + assert!(mq.is_not_null()); + } - let mq = mp.offset(1u); - assert!(!mq.is_null()); - assert!(mq.is_not_null()); -} -#[cfg(test)] -pub mod ptr_tests { - use ptr; - use str; - use libc; - use vec; #[test] - pub fn test_ptr_array_each_with_len() { + fn test_ptr_array_each_with_len() { unsafe { let one = ~"oneOne"; let two = ~"twoTwo"; @@ -451,22 +449,22 @@ pub mod ptr_tests { let arr_ptr = &arr[0]; let mut ctr = 0; let mut iteration_count = 0; - ptr::array_each_with_len(arr_ptr, vec::len(arr), - |e| { - let actual = str::raw::from_c_str(e); - let expected = copy expected_arr[ctr]; - debug!( - "test_ptr_array_each e: %s, a: %s", - expected, actual); - assert!(actual == expected); - ctr += 1; - iteration_count += 1; - }); + array_each_with_len(arr_ptr, vec::len(arr), + |e| { + let actual = str::raw::from_c_str(e); + let expected = copy expected_arr[ctr]; + debug!( + "test_ptr_array_each e: %s, a: %s", + expected, actual); + assert!(actual == expected); + ctr += 1; + iteration_count += 1; + }); assert!(iteration_count == 3u); } } #[test] - pub fn test_ptr_array_each() { + fn test_ptr_array_each() { unsafe { let one = ~"oneOne"; let two = ~"twoTwo"; @@ -484,12 +482,12 @@ pub mod ptr_tests { let arr_ptr = &arr[0]; let mut ctr = 0; let mut iteration_count = 0; - ptr::array_each(arr_ptr, |e| { + array_each(arr_ptr, |e| { let actual = str::raw::from_c_str(e); let expected = copy expected_arr[ctr]; debug!( "test_ptr_array_each e: %s, a: %s", - expected, actual); + expected, actual); assert!(actual == expected); ctr += 1; iteration_count += 1; @@ -500,9 +498,9 @@ pub mod ptr_tests { #[test] #[should_fail] #[ignore(cfg(windows))] - pub fn test_ptr_array_each_with_len_null_ptr() { + fn test_ptr_array_each_with_len_null_ptr() { unsafe { - ptr::array_each_with_len(0 as **libc::c_char, 1, |e| { + array_each_with_len(0 as **libc::c_char, 1, |e| { str::raw::from_c_str(e); }); } @@ -510,9 +508,9 @@ pub mod ptr_tests { #[test] #[should_fail] #[ignore(cfg(windows))] - pub fn test_ptr_array_each_null_ptr() { + fn test_ptr_array_each_null_ptr() { unsafe { - ptr::array_each(0 as **libc::c_char, |e| { + array_each(0 as **libc::c_char, |e| { str::raw::from_c_str(e); }); } diff --git a/src/libcore/rand.rs b/src/libcore/rand.rs index c6400ccded8..0a93a651a85 100644 --- a/src/libcore/rand.rs +++ b/src/libcore/rand.rs @@ -747,12 +747,12 @@ pub fn random() -> uint { #[cfg(test)] -pub mod tests { +mod tests { use option::{Option, Some}; use rand; #[test] - pub fn rng_seeded() { + fn rng_seeded() { let seed = rand::seed(); let ra = rand::seeded_rng(seed); let rb = rand::seeded_rng(seed); @@ -760,7 +760,7 @@ pub mod tests { } #[test] - pub fn rng_seeded_custom_seed() { + fn rng_seeded_custom_seed() { // much shorter than generated seeds which are 1024 bytes let seed = [2u8, 32u8, 4u8, 32u8, 51u8]; let ra = rand::seeded_rng(seed); @@ -769,7 +769,7 @@ pub mod tests { } #[test] - pub fn rng_seeded_custom_seed2() { + fn rng_seeded_custom_seed2() { let seed = [2u8, 32u8, 4u8, 32u8, 51u8]; let ra = rand::seeded_rng(seed); // Regression test that isaac is actually using the above vector @@ -780,7 +780,7 @@ pub mod tests { } #[test] - pub fn gen_int_range() { + fn gen_int_range() { let r = rand::Rng(); let a = r.gen_int_range(-3, 42); assert!(a >= -3 && a < 42); @@ -791,12 +791,12 @@ pub mod tests { #[test] #[should_fail] #[ignore(cfg(windows))] - pub fn gen_int_from_fail() { + fn gen_int_from_fail() { rand::Rng().gen_int_range(5, -2); } #[test] - pub fn gen_uint_range() { + fn gen_uint_range() { let r = rand::Rng(); let a = r.gen_uint_range(3u, 42u); assert!(a >= 3u && a < 42u); @@ -807,12 +807,12 @@ pub mod tests { #[test] #[should_fail] #[ignore(cfg(windows))] - pub fn gen_uint_range_fail() { + fn gen_uint_range_fail() { rand::Rng().gen_uint_range(5u, 2u); } #[test] - pub fn gen_float() { + fn gen_float() { let r = rand::Rng(); let a = r.gen_float(); let b = r.gen_float(); @@ -820,14 +820,14 @@ pub mod tests { } #[test] - pub fn gen_weighted_bool() { + fn gen_weighted_bool() { let r = rand::Rng(); assert!(r.gen_weighted_bool(0u) == true); assert!(r.gen_weighted_bool(1u) == true); } #[test] - pub fn gen_str() { + fn gen_str() { let r = rand::Rng(); debug!(r.gen_str(10u)); debug!(r.gen_str(10u)); @@ -838,7 +838,7 @@ pub mod tests { } #[test] - pub fn gen_bytes() { + fn gen_bytes() { let r = rand::Rng(); assert!(r.gen_bytes(0u).len() == 0u); assert!(r.gen_bytes(10u).len() == 10u); @@ -846,13 +846,13 @@ pub mod tests { } #[test] - pub fn choose() { + fn choose() { let r = rand::Rng(); assert!(r.choose([1, 1, 1]) == 1); } #[test] - pub fn choose_option() { + fn choose_option() { let r = rand::Rng(); let x: Option<int> = r.choose_option([]); assert!(x.is_none()); @@ -860,7 +860,7 @@ pub mod tests { } #[test] - pub fn choose_weighted() { + fn choose_weighted() { let r = rand::Rng(); assert!(r.choose_weighted(~[ rand::Weighted { weight: 1u, item: 42 }, @@ -872,7 +872,7 @@ pub mod tests { } #[test] - pub fn choose_weighted_option() { + fn choose_weighted_option() { let r = rand::Rng(); assert!(r.choose_weighted_option(~[ rand::Weighted { weight: 1u, item: 42 }, @@ -886,7 +886,7 @@ pub mod tests { } #[test] - pub fn weighted_vec() { + fn weighted_vec() { let r = rand::Rng(); let empty: ~[int] = ~[]; assert!(r.weighted_vec(~[]) == empty); @@ -898,7 +898,7 @@ pub mod tests { } #[test] - pub fn shuffle() { + fn shuffle() { let r = rand::Rng(); let empty: ~[int] = ~[]; assert!(r.shuffle(~[]) == empty); @@ -906,7 +906,7 @@ pub mod tests { } #[test] - pub fn task_rng() { + fn task_rng() { let r = rand::task_rng(); r.gen_int(); assert!(r.shuffle(~[1, 1, 1]) == ~[1, 1, 1]); @@ -914,7 +914,7 @@ pub mod tests { } #[test] - pub fn random() { + fn random() { // not sure how to test this aside from just getting a number let _n : uint = rand::random(); } diff --git a/src/libcore/run.rs b/src/libcore/run.rs index 49df2938afd..8e247a25012 100644 --- a/src/libcore/run.rs +++ b/src/libcore/run.rs @@ -521,7 +521,7 @@ mod tests { // Regression test for memory leaks #[ignore(cfg(windows))] // FIXME (#2626) - pub fn test_leaks() { + fn test_leaks() { run::run_program("echo", []); run::start_program("echo", []); run::program_output("echo", []); @@ -529,7 +529,7 @@ mod tests { #[test] #[allow(non_implicitly_copyable_typarams)] - pub fn test_pipes() { + fn test_pipes() { let pipe_in = os::pipe(); let pipe_out = os::pipe(); let pipe_err = os::pipe(); @@ -555,7 +555,7 @@ mod tests { } #[test] - pub fn waitpid() { + fn waitpid() { let pid = run::spawn_process("false", [], &None, &None, 0i32, 0i32, 0i32); @@ -564,20 +564,20 @@ mod tests { } #[test] - pub fn test_destroy_once() { + fn test_destroy_once() { let mut p = run::start_program("echo", []); p.destroy(); // this shouldn't crash (and nor should the destructor) } #[test] - pub fn test_destroy_twice() { + fn test_destroy_twice() { let mut p = run::start_program("echo", []); p.destroy(); // this shouldnt crash... p.destroy(); // ...and nor should this (and nor should the destructor) } #[cfg(unix)] // there is no way to sleep on windows from inside libcore... - pub fn test_destroy_actually_kills(force: bool) { + fn test_destroy_actually_kills(force: bool) { let path = Path(fmt!("test/core-run-test-destroy-actually-kills-%?.tmp", force)); os::remove_file(&path); @@ -598,13 +598,13 @@ mod tests { #[test] #[cfg(unix)] - pub fn test_unforced_destroy_actually_kills() { + fn test_unforced_destroy_actually_kills() { test_destroy_actually_kills(false); } #[test] #[cfg(unix)] - pub fn test_forced_destroy_actually_kills() { + fn test_forced_destroy_actually_kills() { test_destroy_actually_kills(true); } } diff --git a/src/libcore/sys.rs b/src/libcore/sys.rs index 678005ce06f..04f96f5eb22 100644 --- a/src/libcore/sys.rs +++ b/src/libcore/sys.rs @@ -160,12 +160,12 @@ pub fn fail_assert(msg: &str, file: &str, line: uint) -> ! { } #[cfg(test)] -pub mod tests { +mod tests { use cast; use sys::{Closure, pref_align_of, size_of, nonzero_size_of}; #[test] - pub fn size_of_basic() { + fn size_of_basic() { assert!(size_of::<u8>() == 1u); assert!(size_of::<u16>() == 2u); assert!(size_of::<u32>() == 4u); @@ -176,20 +176,20 @@ pub mod tests { #[cfg(target_arch = "x86")] #[cfg(target_arch = "arm")] #[cfg(target_arch = "mips")] - pub fn size_of_32() { + fn size_of_32() { assert!(size_of::<uint>() == 4u); assert!(size_of::<*uint>() == 4u); } #[test] #[cfg(target_arch = "x86_64")] - pub fn size_of_64() { + fn size_of_64() { assert!(size_of::<uint>() == 8u); assert!(size_of::<*uint>() == 8u); } #[test] - pub fn nonzero_size_of_basic() { + fn nonzero_size_of_basic() { type Z = [i8, ..0]; assert!(size_of::<Z>() == 0u); assert!(nonzero_size_of::<Z>() == 1u); @@ -197,7 +197,7 @@ pub mod tests { } #[test] - pub fn align_of_basic() { + fn align_of_basic() { assert!(pref_align_of::<u8>() == 1u); assert!(pref_align_of::<u16>() == 2u); assert!(pref_align_of::<u32>() == 4u); @@ -207,20 +207,20 @@ pub mod tests { #[cfg(target_arch = "x86")] #[cfg(target_arch = "arm")] #[cfg(target_arch = "mips")] - pub fn align_of_32() { + fn align_of_32() { assert!(pref_align_of::<uint>() == 4u); assert!(pref_align_of::<*uint>() == 4u); } #[test] #[cfg(target_arch = "x86_64")] - pub fn align_of_64() { + fn align_of_64() { assert!(pref_align_of::<uint>() == 8u); assert!(pref_align_of::<*uint>() == 8u); } #[test] - pub fn synthesize_closure() { + fn synthesize_closure() { unsafe { let x = 10; let f: &fn(int) -> int = |y| x + y; diff --git a/src/libcore/task/mod.rs b/src/libcore/task/mod.rs index d712bf8f98f..a6c4b6c5268 100644 --- a/src/libcore/task/mod.rs +++ b/src/libcore/task/mod.rs @@ -925,7 +925,7 @@ fn test_spawn_sched_childs_on_default_sched() { } #[cfg(test)] -pub mod testrt { +mod testrt { use libc; #[nolink] diff --git a/src/libcore/unstable.rs b/src/libcore/unstable.rs index e43d321dc4d..c057fce0abd 100644 --- a/src/libcore/unstable.rs +++ b/src/libcore/unstable.rs @@ -286,14 +286,14 @@ pub impl<T:Owned> Exclusive<T> { } #[cfg(test)] -pub mod tests { +mod tests { use comm; use super::exclusive; use task; use uint; #[test] - pub fn exclusive_arc() { + fn exclusive_arc() { let mut futures = ~[]; let num_tasks = 10; @@ -324,7 +324,7 @@ pub mod tests { } #[test] #[should_fail] #[ignore(cfg(windows))] - pub fn exclusive_poison() { + fn exclusive_poison() { // Tests that if one task fails inside of an exclusive, subsequent // accesses will also fail. let x = exclusive(1); |
