//! Conversion from `[u64; 5]` into [`U320`] via the [`From`] trait.
use super::U320;

/// Creates a [`U320`] from a five-element `u64` array in big-endian order.
///
/// This is equivalent to [`U320::from_be_limbs`] but available through
/// the standard [`From`] trait for ergonomic conversions.
///
/// # Examples
///
/// ```
/// use cnfy_uint::u320::U320;
///
/// let v: U320 = [0, 0, 0, 0, 42u64].into();
/// assert_eq!(v, U320::from_be_limbs([0, 0, 0, 0, 42]));
/// ```
impl From<[u64; 5]> for U320 {
    #[inline]
    fn from(value: [u64; 5]) -> Self {
        Self::from_be_limbs(value)
    }
}

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

    /// Round-trip from array through U320 back to limbs.
    #[test]
    fn round_trip() {
        let arr = [1u64, 2, 3, 4, 5];
        let v = U320::from(arr);
        assert_eq!(v.to_be_limbs(), arr);
    }

    /// Zero array produces zero value.
    #[test]
    fn zero() {
        assert_eq!(U320::from([0u64; 5]), U320::from_be_limbs([0; 5]));
    }

    /// Matches from_be_limbs behavior.
    #[test]
    fn matches_from_be_limbs() {
        let arr = [0xA, 0xB, 0xC, 0xD, 0xE];
        assert_eq!(U320::from(arr), U320::from_be_limbs(arr));
    }
}
