//! Construction of a [`U384`] from six little-endian `u64` limbs.
use super::U384;

impl U384 {
    /// Creates a new [`U384`] from a six-element array of `u64` limbs in
    /// little-endian order: `[w0, w1, w2, w3, w4, w5]` where `w0` is the
    /// least significant and `w5` is the most significant.
    ///
    /// Since the internal layout is already little-endian, the array is
    /// stored directly without reversal. This is the inverse of
    /// [`U384::to_le_limbs`].
    ///
    /// # Examples
    ///
    /// ```
    /// use cnfy_uint::u384::U384;
    ///
    /// let value = U384::from_le_limbs([42, 0, 0, 0, 0, 0]);
    /// assert_eq!(value, U384::from_be_limbs([0, 0, 0, 0, 0, 42]));
    /// ```
    #[inline]
    pub const fn from_le_limbs(value: [u64; 6]) -> Self {
        Self(value)
    }
}

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

    /// Constructing from six zeros yields a zero value.
    #[test]
    fn zero() {
        assert_eq!(U384::from_le_limbs([0; 6]), U384::ZERO);
    }

    /// LE limb order is the reverse of BE limb order.
    #[test]
    fn reverse_of_be() {
        let le = U384::from_le_limbs([6, 5, 4, 3, 2, 1]);
        let be = U384::from_be_limbs([1, 2, 3, 4, 5, 6]);
        assert_eq!(le, be);
    }

    /// Maximum value fills all six limbs.
    #[test]
    fn max_value() {
        assert_eq!(U384::from_le_limbs([u64::MAX; 6]), U384::MAX);
    }

    /// Round-trip with to_le_limbs.
    #[test]
    fn round_trip() {
        let limbs = [0xDEAD, 0xBEEF, 0xCAFE, 0xBABE, 0x42, 0xFF];
        assert_eq!(U384::from_le_limbs(limbs).to_le_limbs(), limbs);
    }
}
