Skip to content

Commit

Permalink
Add some tests around TriColor
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-gilligan committed Feb 8, 2024
1 parent a083583 commit 9ed3427
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,33 @@ mod tests {
Ok((left, right))
);
}

#[test]
fn test_tricolor_bitmask() {
assert_eq!(
TriColor::Black.bitmask(false, 0),
(0b01111111, u16::from_le_bytes([0b00000000, 0b00000000]))
);
assert_eq!(
TriColor::White.bitmask(false, 0),
(0b01111111, u16::from_le_bytes([0b10000000, 0b00000000]))
);
assert_eq!(
TriColor::Chromatic.bitmask(false, 0),
(0b01111111, u16::from_le_bytes([0b10000000, 0b10000000]))
);

assert_eq!(
TriColor::Black.bitmask(true, 0),
(0b01111111, u16::from_le_bytes([0b00000000, 0b00000000]))
);
assert_eq!(
TriColor::White.bitmask(true, 0),
(0b01111111, u16::from_le_bytes([0b10000000, 0b00000000]))
);
assert_eq!(
TriColor::Chromatic.bitmask(true, 0),
(0b01111111, u16::from_le_bytes([0b00000000, 0b10000000]))
);
}
}
36 changes: 36 additions & 0 deletions src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,4 +449,40 @@ mod tests {
assert_eq!(byte, 0);
}
}

#[test]
fn graphics_set_pixel_tricolor_false() {
let mut display = Display::<4, 4, false, { 4 * 4 * 2 / 8 }, TriColor>::default();
display.set_pixel(Pixel(Point::new(0, 0), TriColor::White));
display.set_pixel(Pixel(Point::new(1, 0), TriColor::Chromatic));
display.set_pixel(Pixel(Point::new(2, 0), TriColor::Black));

let bw_buffer = display.bw_buffer();
let chromatic_buffer = display.chromatic_buffer();

extern crate std;
std::println!("{:?}", bw_buffer);
std::println!("{:?}", chromatic_buffer);

assert_eq!(bw_buffer, [192, 0]);
assert_eq!(chromatic_buffer, [64, 0]);
}

#[test]
fn graphics_set_pixel_tricolor_true() {
let mut display = Display::<4, 4, true, { 4 * 4 * 2 / 8 }, TriColor>::default();
display.set_pixel(Pixel(Point::new(0, 0), TriColor::White));
display.set_pixel(Pixel(Point::new(1, 0), TriColor::Chromatic));
display.set_pixel(Pixel(Point::new(2, 0), TriColor::Black));

let bw_buffer = display.bw_buffer();
let chromatic_buffer = display.chromatic_buffer();

extern crate std;
std::println!("{:?}", bw_buffer);
std::println!("{:?}", chromatic_buffer);

assert_eq!(bw_buffer, [128, 0]);
assert_eq!(chromatic_buffer, [64, 0]);
}
}

0 comments on commit 9ed3427

Please sign in to comment.