//! Even parity check for [`U320`].
use super::U320;

impl U320 {
    /// Returns `true` if the value is even (least significant bit is 0).
    ///
    /// Checks bit 0 of limb `[0]` (the least significant limb in
    /// little-endian layout).
    ///
    /// # Examples
    ///
    /// ```
    /// use cnfy_uint::u320::U320;
    ///
    /// assert!(U320::ZERO.is_even());
    /// assert!(!U320::ONE.is_even());
    /// assert!(U320::from_be_limbs([0, 0, 0, 0, 2]).is_even());
    /// ```
    #[inline]
    pub fn is_even(&self) -> bool {
        self.0[0] & 1 == 0
    }
}

#[cfg(test)]
mod ai_tests {
    use super::*;

    /// Zero is even.
    #[test]
    fn zero_is_even() {
        assert!(U320::ZERO.is_even());
    }

    /// One is odd.
    #[test]
    fn one_is_odd() {
        assert!(!U320::ONE.is_even());
    }

    /// Two is even.
    #[test]
    fn two_is_even() {
        assert!(U320::from_be_limbs([0, 0, 0, 0, 2]).is_even());
    }

    /// MAX is odd (all bits set).
    #[test]
    fn max_is_odd() {
        assert!(!U320::MAX.is_even());
    }

    /// Even value with high limbs set.
    #[test]
    fn high_limbs_even() {
        assert!(U320::from_be_limbs([u64::MAX, u64::MAX, u64::MAX, u64::MAX, 4]).is_even());
    }
}
