//! Even-value predicate for [`U384`].
use super::U384;

impl U384 {
    /// Returns `true` if the value is even (least significant bit is 0).
    ///
    /// Checks the LSB of limb `[0]` (the least significant limb).
    ///
    /// # Examples
    ///
    /// ```
    /// use cnfy_uint::u384::U384;
    ///
    /// assert!(U384::ZERO.is_even());
    /// assert!(!U384::ONE.is_even());
    /// assert!(U384::from_be_limbs([0, 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() {
        assert!(U384::ZERO.is_even());
    }

    /// One is not even.
    #[test]
    fn one() {
        assert!(!U384::ONE.is_even());
    }

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

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

    /// High-limb-only value with even LSB limb is even.
    #[test]
    fn high_limb_even() {
        assert!(U384::from_be_limbs([1, 0, 0, 0, 0, 0]).is_even());
    }
}
