//! Conversion from [`U320`] into [`U512`].
use super::U512;
use crate::u320::U320;

/// Creates a [`U512`] from a [`U320`] value, embedding it in the lower
/// five limbs `[3..7]` with the upper three limbs `[0..2]` set to zero.
///
/// # Examples
///
/// ```
/// use cnfy_uint::u320::U320;
/// use cnfy_uint::u512::U512;
///
/// let v = U320::from_be_limbs([1, 2, 3, 4, 5]);
/// let wide = U512::from(v);
/// assert_eq!(wide, U512::from_be_limbs([0, 0, 0, 1, 2, 3, 4, 5]));
/// ```
impl From<U320> for U512 {
    #[inline]
    fn from(value: U320) -> Self {
        Self([value.0[0], value.0[1], value.0[2], value.0[3], value.0[4], 0, 0, 0])
    }
}

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

    /// Converting a zero U320 produces U512::ZERO.
    #[test]
    fn zero() {
        assert_eq!(
            U512::from(U320::from_be_limbs([0, 0, 0, 0, 0])),
            U512::ZERO,
        );
    }

    /// Converting U320 with value 1 in LSB produces U512::ONE.
    #[test]
    fn one() {
        assert_eq!(
            U512::from(U320::from_be_limbs([0, 0, 0, 0, 1])),
            U512::ONE,
        );
    }

    /// All five U320 limbs map to the correct U512 positions.
    #[test]
    fn limb_mapping() {
        let v = U320::from_be_limbs([0xAA, 0xBB, 0xCC, 0xDD, 0xEE]);
        let wide = U512::from(v);
        assert_eq!(
            wide,
            U512::from_be_limbs([0, 0, 0, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE]),
        );
    }

    /// Full U320 (all limbs MAX) fills limbs [3..7].
    #[test]
    fn max_u320() {
        let v = U320::from_be_limbs([u64::MAX; 5]);
        assert_eq!(
            U512::from(v),
            U512::from_be_limbs([0, 0, 0, u64::MAX, u64::MAX, u64::MAX, u64::MAX, u64::MAX]),
        );
    }
}
