extern crate test; use self::test::Bencher; use num::BigUint; use Fibonacci; #[bench] fn fib_u64(b: &mut Bencher) { b.iter(|| Fibonacci::::default().take(92).collect::>()); } #[bench] fn fib_biguint(b: &mut Bencher) { b.iter(|| Fibonacci::::default().take(92).collect::>()); } #[test] fn first_ten() { let ten: Vec = Fibonacci::default().take(10).collect(); assert_eq!(ten, vec![1, 2, 3, 5, 8, 13, 21, 34, 55, 89]); } #[test] fn overflow() { assert_eq!(92, Fibonacci::::default().take(93).collect::>().len()); } #[test] fn non_overflow() { assert_eq!(300, Fibonacci::::default().take(300).collect::>().len()); } #[test] fn reset() { let mut fib: Fibonacci = Fibonacci::default(); for _ in 0..12 { fib.next(); } assert_eq!(None, fib.next()); fib.reset(); assert_eq!(Some(1), fib.next()); }