#[derive(Clone, Copy, Eq, PartialEq, Debug)]
pub enum Mark {
Cross,
Naught,
}
impl Mark {
pub(super) fn other(&self) -> Self {
match self {
Mark::Cross => Mark::Naught,
Mark::Naught => Mark::Cross,
}
}
}
impl std::fmt::Display for Mark {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match *self {
Mark::Cross => write!(f, "X"),
Mark::Naught => write!(f, "O"),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_other_naught() {
let cross = Mark::Cross;
let naught = cross.other();
assert_eq!(naught, Mark::Naught);
}
#[test]
fn test_other_cross() {
let naught = Mark::Naught;
let cross = naught.other();
assert_eq!(cross, Mark::Cross);
}
}