From e6a7a8e163a22177629f1167ae311d2ac213c31f Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Sun, 9 Feb 2025 11:05:20 +0100 Subject: [PATCH] cargo-mutants reduce misses to 16 --- crates/servicepoint/src/brightness.rs | 7 ++ crates/servicepoint/src/command_code.rs | 113 +++++++++++++++++++- crates/servicepoint/src/compression_code.rs | 53 +++++++++ crates/servicepoint/src/value_grid.rs | 9 +- 4 files changed, 179 insertions(+), 3 deletions(-) diff --git a/crates/servicepoint/src/brightness.rs b/crates/servicepoint/src/brightness.rs index 4e12326..539a0a2 100644 --- a/crates/servicepoint/src/brightness.rs +++ b/crates/servicepoint/src/brightness.rs @@ -99,4 +99,11 @@ mod tests { assert_eq!(Brightness::MAX, Brightness::saturating_from(100)); assert_eq!(Brightness(5), Brightness::saturating_from(5)); } + + #[test] + #[cfg(feature = "rand")] + fn test() { + let mut rng = rand::thread_rng(); + assert_ne!(rng.gen::(), rng.gen()); + } } diff --git a/crates/servicepoint/src/command_code.rs b/crates/servicepoint/src/command_code.rs index 25ddfeb..a105522 100644 --- a/crates/servicepoint/src/command_code.rs +++ b/crates/servicepoint/src/command_code.rs @@ -1,6 +1,6 @@ /// The u16 command codes used for the [Command]s. #[repr(u16)] -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub(crate) enum CommandCode { Clear = 0x0002, Cp437Data = 0x0003, @@ -101,3 +101,114 @@ impl TryFrom for CommandCode { } } } + +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn clear() { + assert_eq!(CommandCode::try_from(0x0002), Ok(CommandCode::Clear)); + assert_eq!(u16::from(CommandCode::Clear), 0x0002); + } + + #[test] + fn cp437_data() { + assert_eq!(CommandCode::try_from(0x0003), Ok(CommandCode::Cp437Data)); + assert_eq!(u16::from(CommandCode::Cp437Data), 0x0003); + } + + #[test] + fn char_brightness() { + assert_eq!(CommandCode::try_from(0x0005), Ok(CommandCode::CharBrightness)); + assert_eq!(u16::from(CommandCode::CharBrightness), 0x0005); + } + + #[test] + fn brightness() { + assert_eq!(CommandCode::try_from(0x0007), Ok(CommandCode::Brightness)); + assert_eq!(u16::from(CommandCode::Brightness), 0x0007); + } + + #[test] + fn hard_reset() { + assert_eq!(CommandCode::try_from(0x000b), Ok(CommandCode::HardReset)); + assert_eq!(u16::from(CommandCode::HardReset), 0x000b); + } + + #[test] + fn fade_out() { + assert_eq!(CommandCode::try_from(0x000d), Ok(CommandCode::FadeOut)); + assert_eq!(u16::from(CommandCode::FadeOut), 0x000d); + } + + #[test] + #[allow(deprecated)] + fn bitmap_legacy() { + assert_eq!(CommandCode::try_from(0x0010), Ok(CommandCode::BitmapLegacy)); + assert_eq!(u16::from(CommandCode::BitmapLegacy), 0x0010); + } + + #[test] + fn linear() { + assert_eq!(CommandCode::try_from(0x0012), Ok(CommandCode::BitmapLinear)); + assert_eq!(u16::from(CommandCode::BitmapLinear), 0x0012); + } + + #[test] + fn linear_and() { + assert_eq!(CommandCode::try_from(0x0014), Ok(CommandCode::BitmapLinearAnd)); + assert_eq!(u16::from(CommandCode::BitmapLinearAnd), 0x0014); + } + + #[test] + fn linear_xor() { + assert_eq!(CommandCode::try_from(0x0016), Ok(CommandCode::BitmapLinearXor)); + assert_eq!(u16::from(CommandCode::BitmapLinearXor), 0x0016); + } + + #[test] + #[cfg(feature = "compression_zlib")] + fn bitmap_win_zlib() { + assert_eq!(CommandCode::try_from(0x0017), Ok(CommandCode::BitmapLinearWinZlib)); + assert_eq!(u16::from(CommandCode::BitmapLinearWinZlib), 0x0017); + } + + #[test] + #[cfg(feature = "compression_bzip2")] + fn bitmap_win_bzip2() { + assert_eq!(CommandCode::try_from(0x0018), Ok(CommandCode::BitmapLinearWinBzip2)); + assert_eq!(u16::from(CommandCode::BitmapLinearWinBzip2), 0x0018); + } + + #[test] + #[cfg(feature = "compression_lzma")] + fn bitmap_win_lzma() { + assert_eq!(CommandCode::try_from(0x0019), Ok(CommandCode::BitmapLinearWinLzma)); + assert_eq!(u16::from(CommandCode::BitmapLinearWinLzma), 0x0019); + } + + #[test] + #[cfg(feature = "compression_zstd")] + fn bitmap_win_zstd() { + assert_eq!(CommandCode::try_from(0x001A), Ok(CommandCode::BitmapLinearWinZstd)); + assert_eq!(u16::from(CommandCode::BitmapLinearWinZstd), 0x001A); + } + + #[test] + fn bitmap_win_uncompressed() { + assert_eq!(CommandCode::try_from(0x0013), Ok(CommandCode::BitmapLinearWinUncompressed)); + assert_eq!(u16::from(CommandCode::BitmapLinearWinUncompressed), 0x0013); + } + + #[test] + fn utf8_data() { + assert_eq!(CommandCode::try_from(0x0020), Ok(CommandCode::Utf8Data)); + assert_eq!(u16::from(CommandCode::Utf8Data), 0x0020); + } + + #[test] + fn linear_or() { + assert_eq!(CommandCode::try_from(0x0015), Ok(CommandCode::BitmapLinearOr)); + assert_eq!(u16::from(CommandCode::BitmapLinearOr), 0x0015); + } +} \ No newline at end of file diff --git a/crates/servicepoint/src/compression_code.rs b/crates/servicepoint/src/compression_code.rs index d7db7cd..db25221 100644 --- a/crates/servicepoint/src/compression_code.rs +++ b/crates/servicepoint/src/compression_code.rs @@ -65,3 +65,56 @@ impl TryFrom for CompressionCode { } } } + +#[cfg(test)] +mod test { + use super::*; + #[test] + fn uncompressed() { + assert_eq!( + CompressionCode::try_from(0x0000), + Ok(CompressionCode::Uncompressed) + ); + assert_eq!(u16::from(CompressionCode::Uncompressed), 0x0000); + } + + #[test] + #[cfg(feature = "compression_zlib")] + fn zlib() { + assert_eq!( + CompressionCode::try_from(0x677a), + Ok(CompressionCode::Zlib) + ); + assert_eq!(u16::from(CompressionCode::Zlib), 0x677a); + } + + #[test] + #[cfg(feature = "compression_bzip2")] + fn bzip2() { + assert_eq!( + CompressionCode::try_from(0x627a), + Ok(CompressionCode::Bzip2) + ); + assert_eq!(u16::from(CompressionCode::Bzip2), 0x627a); + } + + #[test] + #[cfg(feature = "compression_lzma")] + fn lzma() { + assert_eq!( + CompressionCode::try_from(0x6c7a), + Ok(CompressionCode::Lzma) + ); + assert_eq!(u16::from(CompressionCode::Lzma), 0x6c7a); + } + + #[test] + #[cfg(feature = "compression_zstd")] + fn zstd() { + assert_eq!( + CompressionCode::try_from(0x7a73), + Ok(CompressionCode::Zstd) + ); + assert_eq!(u16::from(CompressionCode::Zstd), 0x7a73); + } +} diff --git a/crates/servicepoint/src/value_grid.rs b/crates/servicepoint/src/value_grid.rs index 5c39f94..b9cfea5 100644 --- a/crates/servicepoint/src/value_grid.rs +++ b/crates/servicepoint/src/value_grid.rs @@ -511,13 +511,18 @@ mod tests { #[test] fn ref_mut() { - let mut vec = ValueGrid::load(2, 2, &[0, 1, 2, 3]); + let mut vec = ValueGrid::from_vec(3, vec![0, 1, 2, 3,4,5,6,7,8]); let top_left = vec.get_ref_mut(0, 0); *top_left += 5; + let somewhere = vec.get_ref_mut(2, 1); + *somewhere = 42; - assert_eq!(None, vec.get_ref_mut_optional(2, 2)); + assert_eq!(None, vec.get_ref_mut_optional(3, 2)); + assert_eq!(None, vec.get_ref_mut_optional(2, 3)); assert_eq!(Some(&mut 5), vec.get_ref_mut_optional(0, 0)); + assert_eq!(Some(&mut 42), vec.get_ref_mut_optional(2, 1)); + assert_eq!(Some(&mut 8), vec.get_ref_mut_optional(2, 2)); } #[test]