use lib_algorithms::nat::*; #[test] fn test_big() { assert_eq!(big(0).to_string(), "0"); assert_eq!(big(123456789).to_string(), "123456789"); assert_eq!(big(3 * 7).to_string(), "21"); assert_eq!( big(std::u128::MAX).to_string(), "340282366920938463463374607431768211455" ); } #[test] fn test_fib() { assert_eq!(fib(0).to_string(), "0"); assert_eq!(fib(1).to_string(), "1"); assert_eq!(fib(2).to_string(), "1"); assert_eq!(fib(3).to_string(), "2"); assert_eq!(fib(4).to_string(), "3"); assert_eq!(fib(5).to_string(), "5"); assert_eq!(fib(6).to_string(), "8"); assert_eq!( fib(185).to_string(), "205697230343233228174223751303346572685" ); assert_eq!( fib(1000).to_string(), "434665576869374564356885276750406258025646605173717804024817290895365\ 554179490518904038798400792551692959225930803226347752096896232398733224711616\ 42996440906533187938298969649928516003704476137795166849228875" ); } #[test] fn test_pythag() { assert_eq!(pythag(0), []); assert_eq!(pythag(1), []); assert_eq!(pythag(2), []); assert_eq!(pythag(3), []); assert_eq!(pythag(4), []); assert_eq!(pythag(5), [(3, 4, 5)]); assert_eq!(pythag(6), [(3, 4, 5)]); assert_eq!(pythag(12), [(3, 4, 5)]); assert_eq!(pythag(13), [(3, 4, 5), (5, 12, 13)]); assert_eq!( pythag(200), [ (3, 4, 5), (5, 12, 13), (8, 15, 17), (7, 24, 25), (20, 21, 29), (12, 35, 37), (9, 40, 41), (28, 45, 53), (11, 60, 61), (33, 56, 65), (16, 63, 65), (48, 55, 73), (36, 77, 85), (13, 84, 85), (39, 80, 89), (65, 72, 97), (20, 99, 101), (60, 91, 109), (15, 112, 113), (44, 117, 125), (88, 105, 137), (24, 143, 145), (17, 144, 145), (51, 140, 149), (85, 132, 157), (119, 120, 169), (52, 165, 173), (19, 180, 181), (104, 153, 185), (57, 176, 185), (95, 168, 193), (28, 195, 197) ] ); } #[test] fn test_pow() { assert_eq!(pow(big(0), 0).to_string(), "1"); assert_eq!(pow(big(1), 0).to_string(), "1"); assert_eq!(pow(big(0), 1).to_string(), "0"); assert_eq!(pow(big(333), 0).to_string(), "1"); assert_eq!(pow(big(0), 333).to_string(), "0"); assert_eq!(pow(big(333), 1).to_string(), "333"); assert_eq!( pow(big(2), 127).to_string(), "170141183460469231731687303715884105728" ); } #[test] fn test_mul() { assert_eq!(mul(big(0), big(0)).to_string(), "0"); assert_eq!(mul(big(0), big(5)).to_string(), "0"); assert_eq!(mul(big(5), big(0)).to_string(), "1"); assert_eq!(mul(big(5), big(1)).to_string(), "1"); assert_eq!(mul(big(1), big(5)).to_string(), "120"); assert_eq!(mul(big(4), big(5)).to_string(), "20"); assert_eq!( mul(big(std::u128::MAX), big(std::u128::MAX)).to_string(), "340282366920938463463374607431768211455" ); assert_eq!( mul(big(u128::MAX - 2), big(u128::MAX)).to_string(), "394020061963944792122790401001436138043849867350415494954068674941935\ 94324381333809456553193746267257440898662793210" ); assert_eq!( mul(big(61), big(80)).to_string(), "8601077741927290708534393031884800000" ); } #[test] fn test_fact() { assert_eq!(fact(0).to_string(), "1"); assert_eq!(fact(1).to_string(), "1"); assert_eq!(fact(2).to_string(), "2"); assert_eq!(fact(3).to_string(), "6"); assert_eq!(fact(4).to_string(), "24"); assert_eq!(fact(5).to_string(), "120"); assert_eq!( fact(34).to_string(), "295232799039604140847618609643520000000" ); assert_eq!( fact(100).to_string(), "933262154439441526816992388562667004907159682643816214685929638952175\ 999932299156089414639761565182862536979208272237582511852109168640000000000000\ 00000000000" ); } #[test] fn test_bin() { assert_eq!(bin(0, 0).to_string(), "0"); assert_eq!(bin(0, 1).to_string(), "0"); assert_eq!(bin(1, 0).to_string(), "0"); assert_eq!(bin(1, 1).to_string(), "1"); assert_eq!(bin(2, 0).to_string(), "0"); assert_eq!(bin(2, 1).to_string(), "2"); assert_eq!(bin(2, 2).to_string(), "1"); assert_eq!(bin(2, 0).to_string(), "0"); assert_eq!(bin(0, 2).to_string(), "0"); assert_eq!(bin(3, 1).to_string(), "3"); assert_eq!(bin(3, 2).to_string(), "3"); assert_eq!(bin(3, 3).to_string(), "1"); assert_eq!(bin(3, 4).to_string(), "0"); assert_eq!(bin(50, 20).to_string(), "47129212243960"); assert_eq!(bin(100, 45).to_string(), "61448471214136179596720592960"); } #[test] fn test_divisors() { assert_eq!(divisors(0), []); assert_eq!(divisors(1), [1]); assert_eq!(divisors(2), [1, 2]); assert_eq!(divisors(3), [1, 3]); assert_eq!(divisors(4), [1, 2, 4]); assert_eq!(divisors(30), [1, 2, 3, 5, 6, 10, 15, 30]); assert_eq!(divisors(102), [1, 2, 3, 6, 17, 34, 51, 102]); assert_eq!(divisors(9091), [1, 9091]); }