use sim_lib_discrete_algebra::Semiring;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct IntRing(pub i64);
impl Semiring for IntRing {
fn zero() -> Self {
IntRing(0)
}
fn one() -> Self {
IntRing(1)
}
fn add(&self, other: &Self) -> Self {
IntRing(self.0.saturating_add(other.0))
}
fn mul(&self, other: &Self) -> Self {
IntRing(self.0.saturating_mul(other.0))
}
fn is_zero(&self) -> bool {
self.0 == 0
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn ring_basics() {
assert_eq!(IntRing(3).add(&IntRing(-5)), IntRing(-2));
assert_eq!(IntRing(4).mul(&IntRing(-2)), IntRing(-8));
assert!(IntRing::zero().is_zero());
assert_eq!(IntRing(7).star(), None);
}
}