From a6a399d52e3d3851c3f4f2e17f4c7cf126a4b18a Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 19 May 2015 09:22:06 -0700 Subject: [PATCH] Enable testing on stable Rust --- .travis.yml | 17 ++++-- Cargo.toml | 3 -- benches/bigint.rs | 64 ++++++++++++++++++++++ num-macros/Cargo.toml | 3 ++ {tests => num-macros/tests}/test_macro.rs | 0 src/bigint.rs | 66 ----------------------- src/lib.rs | 2 - 7 files changed, 81 insertions(+), 74 deletions(-) create mode 100644 benches/bigint.rs rename {tests => num-macros/tests}/test_macro.rs (100%) diff --git a/.travis.yml b/.travis.yml index 50d4ce9..887404c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,26 @@ language: rust +rust: + - 1.0.0 + - beta + - nightly +sudo: false script: - cargo build --verbose - cargo test --verbose + - | + [ $TRAVIS_RUST_VERSION != nightly ] || ( + cargo bench && + cargo test --verbose --manifest-path=num-macros/Cargo.toml + ) - cargo doc after_success: | [ $TRAVIS_BRANCH = master ] && [ $TRAVIS_PULL_REQUEST = false ] && + [ $TRAVIS_RUST_VERSION = nightly ] && echo '' > target/doc/index.html && - sudo pip install ghp-import && - ghp-import -n target/doc && - git push -fq https://${TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages + pip install ghp-import --user $USER && + $HOME/.local/bin/ghp-import -n target/doc && + git push -qf https://${TOKEN}@github.com/${TRAVIS_REPO_SLUG}.git gh-pages env: global: secure: NNQ8QgQFZ05OhljZiuCg39AEPU7Yhko/shFlJG1lqYFoFrELibSmBPd7zJsTubufHRddn0ed6IH7qPLnzWJ/cS+dxwAopuqCFzGMOcd/JW8DJgD5PUBA8EVh8x0tNFJVxxdnGac1ufRneWMvMIxH2hO1DMc+8FZBBd7u1DNG1Lk= diff --git a/Cargo.toml b/Cargo.toml index 8b20650..fb6e777 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,3 @@ rational, and complex types. [dependencies] rustc-serialize = "0.3.13" rand = "0.3.8" - -[dev-dependencies] -num-macros = { path = "num-macros", version = "0.1.22" } diff --git a/benches/bigint.rs b/benches/bigint.rs new file mode 100644 index 0000000..52b8590 --- /dev/null +++ b/benches/bigint.rs @@ -0,0 +1,64 @@ +#![feature(test)] + +extern crate test; +extern crate num; + +use std::mem::replace; +use test::Bencher; +use num::{BigUint, Zero, One, FromPrimitive}; + +fn factorial(n: usize) -> BigUint { + let mut f: BigUint = One::one(); + for i in 1..(n+1) { + let bu: BigUint = FromPrimitive::from_usize(i).unwrap(); + f = f * bu; + } + f +} + +fn fib(n: usize) -> BigUint { + let mut f0: BigUint = Zero::zero(); + let mut f1: BigUint = One::one(); + for _ in 0..n { + let f2 = f0 + &f1; + f0 = replace(&mut f1, f2); + } + f0 +} + +#[bench] +fn factorial_100(b: &mut Bencher) { + b.iter(|| { + factorial(100); + }); +} + +#[bench] +fn fib_100(b: &mut Bencher) { + b.iter(|| { + fib(100); + }); +} + +#[bench] +fn to_string(b: &mut Bencher) { + let fac = factorial(100); + let fib = fib(100); + b.iter(|| { + fac.to_string(); + }); + b.iter(|| { + fib.to_string(); + }); +} + +#[bench] +fn shr(b: &mut Bencher) { + let n = { let one : BigUint = One::one(); one << 1000 }; + b.iter(|| { + let mut m = n.clone(); + for _ in 0..10 { + m = m >> 1; + } + }) +} diff --git a/num-macros/Cargo.toml b/num-macros/Cargo.toml index dd1e8c6..234ebec 100644 --- a/num-macros/Cargo.toml +++ b/num-macros/Cargo.toml @@ -14,3 +14,6 @@ Numeric syntax extensions. [lib] name = "num_macros" plugin = true + +[dev-dependencies] +num = { path = "..", version = "*" } diff --git a/tests/test_macro.rs b/num-macros/tests/test_macro.rs similarity index 100% rename from tests/test_macro.rs rename to num-macros/tests/test_macro.rs diff --git a/src/bigint.rs b/src/bigint.rs index ed39e1d..22ed5ac 100644 --- a/src/bigint.rs +++ b/src/bigint.rs @@ -3450,69 +3450,3 @@ mod bigint_tests { let _n: BigInt = rng.gen_bigint_range(&u, &l); } } - -#[cfg(test)] -mod bench { - extern crate test; - use self::test::Bencher; - use super::BigUint; - use std::mem::replace; - - use {Zero, One, FromPrimitive}; - - fn factorial(n: usize) -> BigUint { - let mut f: BigUint = One::one(); - for i in 1..(n+1) { - let bu: BigUint = FromPrimitive::from_usize(i).unwrap(); - f = f * bu; - } - f - } - - fn fib(n: usize) -> BigUint { - let mut f0: BigUint = Zero::zero(); - let mut f1: BigUint = One::one(); - for _ in 0..n { - let f2 = f0 + &f1; - f0 = replace(&mut f1, f2); - } - f0 - } - - #[bench] - fn factorial_100(b: &mut Bencher) { - b.iter(|| { - factorial(100); - }); - } - - #[bench] - fn fib_100(b: &mut Bencher) { - b.iter(|| { - fib(100); - }); - } - - #[bench] - fn to_string(b: &mut Bencher) { - let fac = factorial(100); - let fib = fib(100); - b.iter(|| { - fac.to_string(); - }); - b.iter(|| { - fib.to_string(); - }); - } - - #[bench] - fn shr(b: &mut Bencher) { - let n = { let one : BigUint = One::one(); one << 1000 }; - b.iter(|| { - let mut m = n.clone(); - for _ in 0..10 { - m = m >> 1; - } - }) - } -} diff --git a/src/lib.rs b/src/lib.rs index c8218af..94477c4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,8 +42,6 @@ //! ``` //! //! [newt]: https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method -//#![cfg_attr(test, deny(warnings))] -#![cfg_attr(test, feature(test))] #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png", html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/num/",