//! Leading zero byte count for [`U384`].
use super::U384;

impl U384 {
    /// Returns the number of leading zero bytes in the 48-byte big-endian
    /// representation.
    ///
    /// Computed as `leading_zeros() / 8`. Returns 48 for the zero value
    /// and 0 when the most significant byte is non-zero.
    ///
    /// # Examples
    ///
    /// ```
    /// use cnfy_uint::u384::U384;
    ///
    /// assert_eq!(U384::ZERO.leading_zero_bytes(), 48);
    /// assert_eq!(U384::ONE.leading_zero_bytes(), 47);
    /// assert_eq!(U384::MAX.leading_zero_bytes(), 0);
    /// ```
    #[inline]
    pub const fn leading_zero_bytes(&self) -> u32 {
        self.leading_zeros() / 8
    }
}

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

    /// Zero has 48 leading zero bytes.
    #[test]
    fn zero() {
        assert_eq!(U384::ZERO.leading_zero_bytes(), 48);
    }

    /// One has 47 leading zero bytes.
    #[test]
    fn one() {
        assert_eq!(U384::ONE.leading_zero_bytes(), 47);
    }

    /// MAX has 0 leading zero bytes.
    #[test]
    fn max() {
        assert_eq!(U384::MAX.leading_zero_bytes(), 0);
    }

    /// Value 0xFF has 47 leading zero bytes.
    #[test]
    fn byte_value() {
        let v = U384::from_be_limbs([0, 0, 0, 0, 0, 0xFF]);
        assert_eq!(v.leading_zero_bytes(), 47);
    }

    /// Value 0x100 has 46 leading zero bytes.
    #[test]
    fn two_byte_value() {
        let v = U384::from_be_limbs([0, 0, 0, 0, 0, 0x100]);
        assert_eq!(v.leading_zero_bytes(), 46);
    }
}
