diff --git a/crates/servicepoint/src/byte_grid.rs b/crates/servicepoint/src/byte_grid.rs index 1912bb3..74b9e3c 100644 --- a/crates/servicepoint/src/byte_grid.rs +++ b/crates/servicepoint/src/byte_grid.rs @@ -304,4 +304,16 @@ mod tests { assert_eq!(None, vec.get_ref_mut_optional(2, 2)); assert_eq!(Some(&mut 5), vec.get_ref_mut_optional(0, 0)); } + + #[test] + fn optional() { + let mut grid = ByteGrid::load(2, 2, &[0, 1, 2, 3]); + grid.set_optional(0, 0, 5); + grid.set_optional(-1, 0, 8); + grid.set_optional(0, 8, 42); + assert_eq!(grid.data, [5, 1, 2, 3]); + + assert_eq!(grid.get_optional(0, 0), Some(5)); + assert_eq!(grid.get_optional(0, 8), None); + } } diff --git a/crates/servicepoint/src/packet.rs b/crates/servicepoint/src/packet.rs index d6cb78b..5ad80f1 100644 --- a/crates/servicepoint/src/packet.rs +++ b/crates/servicepoint/src/packet.rs @@ -69,4 +69,10 @@ mod tests { let p = Packet::try_from(&*data).unwrap(); assert_eq!(p, Packet(Header(0, 1, 2, 3, 4), vec![42u8; 23])); } + + #[test] + fn too_small() { + let data = vec![0u8; 4]; + assert_eq!(Packet::try_from(data.as_slice()), Err(())) + } } diff --git a/crates/servicepoint/src/pixel_grid.rs b/crates/servicepoint/src/pixel_grid.rs index f078a00..f8c34b4 100644 --- a/crates/servicepoint/src/pixel_grid.rs +++ b/crates/servicepoint/src/pixel_grid.rs @@ -281,4 +281,12 @@ mod tests { } assert_eq!(grid.data_ref(), [0xAA, 0xAA]); } + + #[test] + fn data_ref_mut() { + let mut grid = PixelGrid::new(8, 2); + let data = grid.data_ref_mut(); + data[1] = 0x0F; + assert!(grid.get(7, 1)); + } }