sim_lib_discrete_graph/
intring.rs1use sim_lib_discrete_algebra::Semiring;
9
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
12pub struct IntRing(pub i64);
13
14impl Semiring for IntRing {
15 fn zero() -> Self {
16 IntRing(0)
17 }
18 fn one() -> Self {
19 IntRing(1)
20 }
21 fn add(&self, other: &Self) -> Self {
22 IntRing(self.0.saturating_add(other.0))
23 }
24 fn mul(&self, other: &Self) -> Self {
25 IntRing(self.0.saturating_mul(other.0))
26 }
27 fn is_zero(&self) -> bool {
28 self.0 == 0
29 }
30}
31
32#[cfg(test)]
33mod tests {
34 use super::*;
35
36 #[test]
37 fn ring_basics() {
38 assert_eq!(IntRing(3).add(&IntRing(-5)), IntRing(-2));
39 assert_eq!(IntRing(4).mul(&IntRing(-2)), IntRing(-8));
40 assert!(IntRing::zero().is_zero());
41 assert_eq!(IntRing(7).star(), None);
42 }
43}