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

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

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

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

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

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

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