algebraeon_groups/examples/
c2.rs

1use crate::group::Group;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
4pub enum C2 {
5    Identity,
6    Flip,
7}
8
9impl Group for C2 {
10    fn identity() -> Self {
11        Self::Identity
12    }
13
14    fn inverse(self) -> Self {
15        self
16    }
17
18    fn compose_mut(&mut self, other: &Self) {
19        match other {
20            C2::Identity => {}
21            C2::Flip => match self {
22                C2::Identity => {
23                    *self = Self::Flip;
24                }
25                C2::Flip => *self = Self::Identity,
26            },
27        }
28    }
29}
30
31#[cfg(test)]
32mod tests {
33    use super::*;
34
35    #[test]
36    fn test_c2() {
37        debug_assert_eq!(C2::identity(), C2::Identity);
38        debug_assert_eq!(C2::Identity.inverse(), C2::Identity);
39        debug_assert_eq!(C2::Flip.inverse(), C2::Flip);
40        debug_assert_eq!(C2::compose(C2::Identity, C2::Identity), C2::Identity);
41        debug_assert_eq!(C2::compose(C2::Flip, C2::Identity), C2::Flip);
42        debug_assert_eq!(C2::compose(C2::Identity, C2::Flip), C2::Flip);
43        debug_assert_eq!(C2::compose(C2::Flip, C2::Flip), C2::Identity);
44    }
45}