pub mod arena;
pub mod collector;
pub mod trace;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Color {
White0,
White1,
Gray,
Black,
}
impl Color {
#[inline]
pub fn is_white(self) -> bool {
matches!(self, Self::White0 | Self::White1)
}
#[inline]
pub fn is_black(self) -> bool {
self == Self::Black
}
#[inline]
pub fn is_gray(self) -> bool {
self == Self::Gray
}
#[inline]
#[must_use]
pub fn other_white(self) -> Self {
match self {
Self::White0 => Self::White1,
Self::White1 => Self::White0,
other => other,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn white_detection() {
assert!(Color::White0.is_white());
assert!(Color::White1.is_white());
assert!(!Color::Gray.is_white());
assert!(!Color::Black.is_white());
}
#[test]
fn black_detection() {
assert!(Color::Black.is_black());
assert!(!Color::White0.is_black());
assert!(!Color::Gray.is_black());
}
#[test]
fn gray_detection() {
assert!(Color::Gray.is_gray());
assert!(!Color::White0.is_gray());
assert!(!Color::Black.is_gray());
}
#[test]
fn other_white_flips() {
assert_eq!(Color::White0.other_white(), Color::White1);
assert_eq!(Color::White1.other_white(), Color::White0);
}
#[test]
fn other_white_non_white_unchanged() {
assert_eq!(Color::Gray.other_white(), Color::Gray);
assert_eq!(Color::Black.other_white(), Color::Black);
}
}