]> git.bitcoin.ninja Git - rust-lightning/commitdiff
add tests
authorMarty Jones <murtin.jones@gmail.com>
Wed, 22 Apr 2020 00:27:35 +0000 (20:27 -0400)
committerMarty Jones <murtin.jones@gmail.com>
Wed, 22 Apr 2020 00:27:35 +0000 (20:27 -0400)
lightning/src/util/byte_utils.rs

index 44445666f776644947320cacac39fd0c9b57c982..240480dff6a4b2ce6bad5e06c011134f4c1c94bd 100644 (file)
@@ -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