//! Construction of a `U320` from a five-element `[u64; 5]` limb array.
use super::U320;

impl U320 {
    /// Creates a new [`U320`] from a five-element array of `u64` limbs in
    /// big-endian order: `[w0, w1, w2, w3, w4]` where `w0` is the most
    /// significant and `w4` is the least significant.
    ///
    /// The input is reversed into the internal little-endian layout.
    ///
    /// # Examples
    ///
    /// ```
    /// use cnfy_uint::u320::U320;
    ///
    /// let value = U320::from_be_limbs([0, 0, 0, 0, 42]);
    /// assert_eq!(value.to_be_limbs(), [0, 0, 0, 0, 42]);
    /// ```
    #[inline]
    pub const fn from_be_limbs(value: [u64; 5]) -> Self {
        Self([value[4], value[3], value[2], value[1], value[0]])
    }
}

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

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

    /// All limbs are stored in reversed (little-endian) positions.
    #[test]
    fn limb_order() {
        let v = U320::from_be_limbs([1, 2, 3, 4, 5]);
        assert_eq!(v.0[0], 5); // LSB
        assert_eq!(v.0[4], 1); // MSB
    }

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