From: Marty Jones Date: Wed, 22 Apr 2020 00:27:35 +0000 (-0400) Subject: add tests X-Git-Tag: v0.0.12~79^2~1 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=09a39725f8d0016112d10605230f35e1d14a2ae2;p=rust-lightning add tests --- diff --git a/lightning/src/util/byte_utils.rs b/lightning/src/util/byte_utils.rs index 44445666f..240480dff 100644 --- a/lightning/src/util/byte_utils.rs +++ b/lightning/src/util/byte_utils.rs @@ -104,3 +104,24 @@ pub fn le64_to_array(u: u64) -> [u8; 8] { v[7] = ((u >> 8*7) & 0xff) as u8; v } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_all() { + assert_eq!(slice_to_be16(&[0xde, 0xad]), 0xdead); + assert_eq!(slice_to_be32(&[0xde, 0xad, 0xbe, 0xef]), 0xdeadbeef); + assert_eq!(slice_to_le32(&[0xef, 0xbe, 0xad, 0xde]), 0xdeadbeef); + assert_eq!(slice_to_be48(&[0xde, 0xad, 0xbe, 0xef, 0x1b, 0xad]), 0xdeadbeef1bad); + assert_eq!(slice_to_be64(&[0xde, 0xad, 0xbe, 0xef, 0x1b, 0xad, 0x1d, 0xea]), 0xdeadbeef1bad1dea); + assert_eq!(be16_to_array(0xdead), [0xde, 0xad]); + assert_eq!(be32_to_array(0xdeadbeef), [0xde, 0xad, 0xbe, 0xef]); + assert_eq!(le32_to_array(0xdeadbeef), [0xef, 0xbe, 0xad, 0xde]); + assert_eq!(be48_to_array(0xdeadbeef1bad), [0xde, 0xad, 0xbe, 0xef, 0x1b, 0xad]); + assert_eq!(be64_to_array(0xdeadbeef1bad1dea), [0xde, 0xad, 0xbe, 0xef, 0x1b, 0xad, 0x1d, 0xea]); + assert_eq!(le64_to_array(0xdeadbeef1bad1dea), [0xea, 0x1d, 0xad, 0x1b, 0xef, 0xbe, 0xad, 0xde]); + + } +} \ No newline at end of file