From 869fe69fdf947230ca4129d3d1f9749360035e64 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 18 Apr 2021 15:20:13 +0530 Subject: add RLE compression functions --- tests/serde.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/serde.rs b/tests/serde.rs index 295b8d0..3701707 100644 --- a/tests/serde.rs +++ b/tests/serde.rs @@ -11,13 +11,14 @@ fn size_of_image_info_header() { #[test] fn compression() { - let img = Image::new(50, 5); + let mut img = Image::new(50, 5); + img.use_compression(CompressionType::RLE); let encoded = img.encode().unwrap(); let mut cursor = Cursor::new(encoded); let decoded = Image::decode(&mut cursor).unwrap(); assert_eq!( CompressionType::from_u32(decoded.image_info_header.compression_type), - CompressionType::None + CompressionType::RLE ); } @@ -42,3 +43,20 @@ fn size_round_nearest() { assert_eq!(decoded.image_info_header.width, 50); assert_eq!(decoded.image_info_header.height, 5); } + +#[test] +fn size_compressed() { + let mut img = Image::new(100, 80); + img.use_compression(CompressionType::RLE); + let encoded = img.encode().unwrap(); + // 26 - headers + // 4 - first and only length + // 4 - separator zero + // 1 - first and only data point + assert_eq!(encoded.len(), 26 + 4 + 4 + 1); + let mut cursor = Cursor::new(encoded); + let decoded = Image::decode(&mut cursor).unwrap(); + assert_eq!(decoded.image_info_header.width, 100); + assert_eq!(decoded.image_info_header.height, 80); + assert!(decoded.data.iter().all(|x| !*x)); +} -- cgit v1.2.3