//! Construction of a `U512` from an eight-element `[u64; 8]` limb array.
use super::U512;

impl U512 {
    /// Creates a new [`U512`] from an eight-element array of `u64` limbs in
    /// big-endian order: `[w0, w1, w2, w3, w4, w5, w6, w7]` where `w0` is
    /// the most significant and `w7` is the least significant.
    ///
    /// # Examples
    ///
    /// ```
    /// use cnfy_uint::u512::U512;
    ///
    /// let value = U512::from_be_limbs([0, 0, 0, 0, 0, 0, 0, 42]);
    /// assert_eq!(value.to_be_limbs(), [0, 0, 0, 0, 0, 0, 0, 42]);
    /// ```
    #[inline]
    pub const fn from_be_limbs(value: [u64; 8]) -> Self {
        Self([value[7], value[6], value[5], value[4], value[3], value[2], value[1], value[0]])
    }
}

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

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

    /// All limbs are stored in the correct positions (LE: index 0 = LSB).
    #[test]
    fn limb_order() {
        let v = U512::from_be_limbs([1, 2, 3, 4, 5, 6, 7, 8]);
        assert_eq!(v.0[0], 8);
        assert_eq!(v.0[7], 1);
    }

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