standard_card 1.4.0

A Lightweight Library for Efficient Card Representation
Documentation
/// Given the deck of cards and the new position of each cards, return the new deck with new arrangement.
///
/// # Examples
/// ```
/// use standard_card::deck::arrange;
///
/// let cards = vec![98306, 164099, 295429];
/// let positions: [usize; 3] = [0, 2, 1];
///
/// let arrangement = arrange(&cards, &positions);
///
/// assert_eq!(arrangement, [98306, 295429, 164099]);
/// ```
pub fn arrange(cards: &Vec<i32>, positions: &[usize]) -> Vec<i32> {
    let mut result: Vec<i32> = vec![0; positions.len()];

    for (index, position) in positions.iter().enumerate() {
        result[index] = cards[*position];
    }

    result
}

#[cfg(test)]
mod arrange {
    use crate::deck::arrange;

    #[test]
    fn simple_arrangement() {
        // Arrange
        let cards = vec![98306, 164099, 295429];
        let positions: [usize; 3] = [0, 2, 1];

        // Act
        let actual = arrange(&cards, &positions);

        // Assert
        assert_eq!(actual, [98306, 295429, 164099])
    }
}