//! Construction of a `U384` from a six-element `[u64; 6]` limb array.
use super::U384;

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

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

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

    /// All limbs are stored in reversed (LE) positions.
    #[test]
    fn limb_order() {
        let v = U384::from_be_limbs([1, 2, 3, 4, 5, 6]);
        assert_eq!(v.0[0], 6); // BE[5] -> LE[0]
        assert_eq!(v.0[5], 1); // BE[0] -> LE[5]
    }

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