From 09a39725f8d0016112d10605230f35e1d14a2ae2 Mon Sep 17 00:00:00 2001 From: Marty Jones Date: Tue, 21 Apr 2020 20:27:35 -0400 Subject: [PATCH] add tests --- lightning/src/util/byte_utils.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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 -- 2.39.5