more tests

This commit is contained in:
Vinzenz Schroeter 2024-06-05 20:23:44 +02:00
parent b08fd97066
commit 894de966bc
3 changed files with 26 additions and 0 deletions

View file

@ -304,4 +304,16 @@ mod tests {
assert_eq!(None, vec.get_ref_mut_optional(2, 2)); assert_eq!(None, vec.get_ref_mut_optional(2, 2));
assert_eq!(Some(&mut 5), vec.get_ref_mut_optional(0, 0)); 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);
}
} }

View file

@ -69,4 +69,10 @@ mod tests {
let p = Packet::try_from(&*data).unwrap(); 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]));
} }
#[test]
fn too_small() {
let data = vec![0u8; 4];
assert_eq!(Packet::try_from(data.as_slice()), Err(()))
}
} }

View file

@ -281,4 +281,12 @@ mod tests {
} }
assert_eq!(grid.data_ref(), [0xAA, 0xAA]); 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));
}
} }