mirror of
https://github.com/cccb/servicepoint.git
synced 2025-01-18 18:10:14 +01:00
add tests
This commit is contained in:
parent
3d47b41106
commit
5f8f691464
|
@ -77,8 +77,8 @@ impl From<BrightnessGrid> for Vec<u8> {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<BrightnessGrid> for PrimitiveGrid<u8> {
|
||||
fn from(value: PrimitiveGrid<Brightness>) -> Self {
|
||||
impl From<&BrightnessGrid> for PrimitiveGrid<u8> {
|
||||
fn from(value: &PrimitiveGrid<Brightness>) -> Self {
|
||||
let u8s = value
|
||||
.iter()
|
||||
.map(|brightness| (*brightness).into())
|
||||
|
@ -109,3 +109,33 @@ impl Distribution<Brightness> for Standard {
|
|||
Brightness(rng.gen_range(Brightness::MIN.0..=Brightness::MAX.0))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::DataRef;
|
||||
|
||||
#[test]
|
||||
fn brightness_from_u8() {
|
||||
assert_eq!(Err(100), Brightness::try_from(100));
|
||||
assert_eq!(Ok(Brightness(1)), Brightness::try_from(1))
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "rand")]
|
||||
fn rand_brightness() {
|
||||
let mut rng = rand::thread_rng();
|
||||
for _ in 0..100 {
|
||||
let _: Brightness = rng.gen();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn to_u8_grid() {
|
||||
let mut grid = BrightnessGrid::new(2, 2);
|
||||
grid.set(1, 0, Brightness::MIN);
|
||||
grid.set(0, 1, Brightness::MAX);
|
||||
let actual = PrimitiveGrid::from(&grid);
|
||||
assert_eq!(actual.data_ref(), &[11, 0, 11, 11]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -331,7 +331,7 @@ mod tests {
|
|||
payload: vec![42u8; 23],
|
||||
};
|
||||
let data: Vec<u8> = p.into();
|
||||
let p = Packet::try_from(&*data).unwrap();
|
||||
let p = Packet::try_from(data).unwrap();
|
||||
assert_eq!(
|
||||
p,
|
||||
Packet {
|
||||
|
|
Loading…
Reference in a new issue