//! tlnat; type level (natural) numbers for rust //! //! This project is essentially a stop-gap until the //! rust team implements generics that can be parameterized //! by values. The infrastructure exists to define other //! types of objects, but currently the only implemented values //! are natural numbers 0-1024. //! //! test/lib.rs: some test code that requires being in a separate //! file (for whatever reason, may be an ICE in rustc). //! //! author: Dalton Woodard //! contact: daltonmwoodard@gmail.com //! license: MIT License (c) 2016 by Dalton Woodard extern crate tlnat; // testing that these actually work; // _0 - _10 is reasonable for checking, // if these work then all the rest should. #[test] fn test_value_equality () -> () { assert_eq!(0, tlnat::_0::VALUE); assert_eq!(1, tlnat::_1::VALUE); assert_eq!(2, tlnat::_2::VALUE); assert_eq!(3, tlnat::_3::VALUE); assert_eq!(4, tlnat::_4::VALUE); assert_eq!(5, tlnat::_5::VALUE); assert_eq!(6, tlnat::_6::VALUE); assert_eq!(7, tlnat::_7::VALUE); assert_eq!(8, tlnat::_8::VALUE); assert_eq!(9, tlnat::_9::VALUE); } // testing that different types // indeed have different values #[test] fn test_different_not_equal () -> () { assert!(0 != tlnat::_5::VALUE); assert!(1 != tlnat::_9::VALUE); assert!(2 != tlnat::_3::VALUE); assert!(3 != tlnat::_10::VALUE); assert!(4 != tlnat::_2::VALUE); assert!(5 != tlnat::_7::VALUE); assert!(6 != tlnat::_1::VALUE); assert!(7 != tlnat::_4::VALUE); assert!(8 != tlnat::_6::VALUE); assert!(9 != tlnat::_8::VALUE); } // WARNING: This currently does not compile, I think // due to some internal evaluation order in rustc. // // test that this works with constant // sized arrays; /* #[test] fn test_constant_size_array () -> () { struct zero_arr { vals: [u8; tlnat::_0::evaluate()] } struct one_arr { vals: [u8; tlnat::_1::evaluate()] } struct two_arr { vals: [u8; tlnat::_2::VALUE] } struct three_arr { vals: [u8; tlnat::_3::VALUE] } struct four_arr { vals: [u8; tlnat::_4::VALUE] } struct five_arr { vals: [u8; tlnat::_5::VALUE] } assert_eq!(0, std::mem::size_of::()); assert_eq!(1, std::mem::size_of::()); assert_eq!(2, std::mem::size_of::()); assert_eq!(3, std::mem::size_of::()); assert_eq!(4, std::mem::size_of::()); assert_eq!(5, std::mem::size_of::()); } */