#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone)]
pub enum Status {
Dead,
Alive,
}
#[derive(Debug, Clone)]
pub struct Cell(pub Status);
impl Cell {
pub fn alive(&self) -> bool {
self.0 == Status::Alive
}
pub fn update(&mut self, status: Status) {
self.0 = status;
}
pub const fn next_status(&self, neighbours_cnt: usize) -> Status {
match (&self.0, neighbours_cnt) {
(_, 3) | (&Status::Alive, 2) => Status::Alive,
_ => Status::Dead,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_next_status() {
let cell = Cell(Status::Alive);
assert_eq!(cell.next_status(0), Status::Dead);
assert_eq!(cell.next_status(5), Status::Dead);
assert_eq!(cell.next_status(3), Status::Alive);
assert_eq!(cell.next_status(2), Status::Alive);
}
}