diff --git a/examples/random_brightness/src/main.rs b/examples/random_brightness/src/main.rs index a9ccbcf..ea36370 100644 --- a/examples/random_brightness/src/main.rs +++ b/examples/random_brightness/src/main.rs @@ -3,11 +3,11 @@ use std::time::Duration; use clap::Parser; use rand::Rng; +use servicepoint2::Command::{BitmapLinearWin, Brightness, CharBrightness}; use servicepoint2::{ ByteGrid, CompressionCode, Connection, Origin, PixelGrid, TILE_HEIGHT, TILE_WIDTH, }; -use servicepoint2::Command::{BitmapLinearWin, Brightness, CharBrightness}; #[derive(Parser, Debug)] struct Cli { diff --git a/servicepoint2/src/bit_vec.rs b/servicepoint2/src/bit_vec.rs index 46c7e5e..449865e 100644 --- a/servicepoint2/src/bit_vec.rs +++ b/servicepoint2/src/bit_vec.rs @@ -237,15 +237,15 @@ mod tests { #[test] fn get_set() { let mut vec = BitVec::new(8 * 3); - assert_eq!(vec.get(1), false); - assert_eq!(vec.get(11), false); + assert!(!vec.get(1)); + assert!(!vec.get(11)); vec.set(1, true); vec.set(11, true); assert_eq!(vec.data, [0x40, 0x10, 0x00]); - assert_eq!(vec.get(0), false); - assert_eq!(vec.get(1), true); - assert_eq!(vec.get(11), true); + assert!(!vec.get(0)); + assert!(vec.get(1)); + assert!(vec.get(11)); } #[test] @@ -267,22 +267,22 @@ mod tests { } #[test] - fn mut_data_ref(){ + fn mut_data_ref() { let mut vec = BitVec::new(8 * 3); let data_ref = vec.mut_data_ref(); data_ref.copy_from_slice(&[0x40, 0x10, 0x00]); assert_eq!(vec.data, [0x40, 0x10, 0x00]); - assert_eq!(vec.get(1), true); + assert!(vec.get(1)); } #[test] fn is_empty() { let vec = BitVec::new(8 * 3); - assert_eq!(vec.is_empty(), false); + assert!(!vec.is_empty()); let vec = BitVec::new(0); - assert_eq!(vec.is_empty(), true); + assert!(vec.is_empty()); } -} \ No newline at end of file +} diff --git a/servicepoint2/src/byte_grid.rs b/servicepoint2/src/byte_grid.rs index 674c208..5509e46 100644 --- a/servicepoint2/src/byte_grid.rs +++ b/servicepoint2/src/byte_grid.rs @@ -222,12 +222,11 @@ mod tests { } } - assert_eq!(grid.data, [0, 1, 1, 2, 2, 3]); let data: Vec = grid.into(); - let grid = ByteGrid::load(2, 3, &*data); + let grid = ByteGrid::load(2, 3, &data); assert_eq!(grid.data, [0, 1, 1, 2, 2, 3]); } @@ -241,4 +240,4 @@ mod tests { assert_eq!(vec.data, [1, 2, 3, 4]); assert_eq!(vec.get(1, 0), 2) } -} \ No newline at end of file +} diff --git a/servicepoint2/src/command.rs b/servicepoint2/src/command.rs index 635b1a2..7832228 100644 --- a/servicepoint2/src/command.rs +++ b/servicepoint2/src/command.rs @@ -1,8 +1,8 @@ +use crate::command_code::CommandCode; +use crate::compression::{into_compressed, into_decompressed}; use crate::{ BitVec, ByteGrid, CompressionCode, Header, Packet, PixelGrid, TILE_SIZE, }; -use crate::command_code::CommandCode; -use crate::compression::{into_compressed, into_decompressed}; /// An origin marks the top left position of a window sent to the display. #[derive(Debug, Clone, Copy, PartialEq)] @@ -526,7 +526,9 @@ pub mod c_api { #[cfg(test)] mod tests { - use crate::{BitVec, ByteGrid, Command, CompressionCode, Origin, Packet, PixelGrid}; + use crate::{ + BitVec, ByteGrid, Command, CompressionCode, Origin, Packet, PixelGrid, + }; fn round_trip(original: Command) { let packet: Packet = original.clone().into(); @@ -538,20 +540,30 @@ mod tests { } #[test] - fn round_trip_clear() { round_trip(Command::Clear); } + fn round_trip_clear() { + round_trip(Command::Clear); + } #[test] - fn round_trip_hard_reset() { round_trip(Command::HardReset); } + fn round_trip_hard_reset() { + round_trip(Command::HardReset); + } #[test] - fn round_trip_fade_out() { round_trip(Command::FadeOut); } + fn round_trip_fade_out() { + round_trip(Command::FadeOut); + } #[test] - fn round_trip_brightness() { round_trip(Command::Brightness(6)); } + fn round_trip_brightness() { + round_trip(Command::Brightness(6)); + } #[test] #[allow(deprecated)] - fn round_trip_bitmap_legacy() { round_trip(Command::BitmapLegacy); } + fn round_trip_bitmap_legacy() { + round_trip(Command::BitmapLegacy); + } #[test] fn round_trip_char_brightness() { @@ -565,14 +577,35 @@ mod tests { #[test] fn round_trip_bitmap_linear() { - let codes = [CompressionCode::Uncompressed, CompressionCode::Lzma, - CompressionCode::Bzip2, CompressionCode::Zlib, CompressionCode::Zstd]; + let codes = [ + CompressionCode::Uncompressed, + CompressionCode::Lzma, + CompressionCode::Bzip2, + CompressionCode::Zlib, + CompressionCode::Zstd, + ]; for compression in codes { round_trip(Command::BitmapLinear(23, BitVec::new(40), compression)); - round_trip(Command::BitmapLinearAnd(23, BitVec::new(40), compression)); - round_trip(Command::BitmapLinearOr(23, BitVec::new(40), compression)); - round_trip(Command::BitmapLinearXor(23, BitVec::new(40), compression)); - round_trip(Command::BitmapLinearWin(Origin(0, 0), PixelGrid::max_sized(), compression)); + round_trip(Command::BitmapLinearAnd( + 23, + BitVec::new(40), + compression, + )); + round_trip(Command::BitmapLinearOr( + 23, + BitVec::new(40), + compression, + )); + round_trip(Command::BitmapLinearXor( + 23, + BitVec::new(40), + compression, + )); + round_trip(Command::BitmapLinearWin( + Origin(0, 0), + PixelGrid::max_sized(), + compression, + )); } } -} \ No newline at end of file +} diff --git a/servicepoint2/src/command_code.rs b/servicepoint2/src/command_code.rs index eb482c1..73edc9d 100644 --- a/servicepoint2/src/command_code.rs +++ b/servicepoint2/src/command_code.rs @@ -51,10 +51,18 @@ impl TryFrom for CommandCode { value if value == BitmapLinearAnd as u16 => Ok(BitmapLinearAnd), value if value == BitmapLinearOr as u16 => Ok(BitmapLinearOr), value if value == BitmapLinearXor as u16 => Ok(BitmapLinearXor), - value if value == BitmapLinearWinZstd as u16 => Ok(BitmapLinearWinZstd), - value if value == BitmapLinearWinLzma as u16 => Ok(BitmapLinearWinLzma), - value if value == BitmapLinearWinZlib as u16 => Ok(BitmapLinearWinZlib), - value if value == BitmapLinearWinBzip2 as u16 => Ok(BitmapLinearWinBzip2), + value if value == BitmapLinearWinZstd as u16 => { + Ok(BitmapLinearWinZstd) + } + value if value == BitmapLinearWinLzma as u16 => { + Ok(BitmapLinearWinLzma) + } + value if value == BitmapLinearWinZlib as u16 => { + Ok(BitmapLinearWinZlib) + } + value if value == BitmapLinearWinBzip2 as u16 => { + Ok(BitmapLinearWinBzip2) + } _ => Err(()), } } diff --git a/servicepoint2/src/packet.rs b/servicepoint2/src/packet.rs index 8af146a..11c0c03 100644 --- a/servicepoint2/src/packet.rs +++ b/servicepoint2/src/packet.rs @@ -104,9 +104,9 @@ mod tests { #[test] fn round_trip() { - let p = Packet(Header(0,1,2,3,4), vec![42u8; 23]); + let p = Packet(Header(0, 1, 2, 3, 4), vec![42u8; 23]); let data: Vec = p.into(); let p = Packet::try_from(&*data).unwrap(); - assert_eq!(p, Packet(Header(0,1,2,3,4), vec![42u8; 23])); + assert_eq!(p, Packet(Header(0, 1, 2, 3, 4), vec![42u8; 23])); } -} \ No newline at end of file +}