tic_tac_toe_rust/logic/models/
mark.rs1#[derive(Clone, Copy, Eq, PartialEq, Debug)]
6pub enum Mark {
7 Cross,
9 Naught,
11}
12
13impl Mark {
14 pub(super) fn other(&self) -> Self {
16 match self {
17 Mark::Cross => Mark::Naught,
18 Mark::Naught => Mark::Cross,
19 }
20 }
21}
22
23impl std::fmt::Display for Mark {
24 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
25 match *self {
26 Mark::Cross => write!(f, "X"),
27 Mark::Naught => write!(f, "O"),
28 }
29 }
30}
31
32#[cfg(test)]
33mod tests {
34 use super::*;
35
36 #[test]
37 fn test_other_naught() {
38 let cross = Mark::Cross;
39 let naught = cross.other();
40 assert_eq!(naught, Mark::Naught);
41 }
42
43 #[test]
44 fn test_other_cross() {
45 let naught = Mark::Naught;
46 let cross = naught.other();
47 assert_eq!(cross, Mark::Cross);
48 }
49}