rust_cards 0.1.2

Simulates playing cards
Documentation
pub mod cards;
pub mod hand;

#[cfg(test)]
mod tests {
    use std::time::Instant;

    use crate::hand;
    use crate::hand::Hand;

    use crate::cards;
    use crate::cards::Card;
    use crate::cards::Suit;
    use crate::cards::Value;

    #[test]
    fn full_hand() {
        print_hand(&hand::Hand::full_deck() )
    }

    #[test]
    fn stack_top() {
        let bottom = Hand::from(
            vec![
                Card::new(Value::Ace, Suit::Spade),
                Card::new(Value::Two, Suit::Spade),
                Card::new(Value::Three, Suit::Spade),
            ]
        );
        // A♠, 2♠, 3♠

        let top = Hand::from(
            vec![
                Card::new(Value::Jack, Suit::Spade),
                Card::new(Value::Queen, Suit::Spade),
                Card::new(Value::King, Suit::Spade),
            ]
        );
        // J♠, Q♠, K♠

        let stacked = bottom.stack_top(top);
        // J♠, Q♠, K♠, A♠, 2♠, 3♠

        print_hand(&stacked)
    }

    #[test]
    fn stack_bottom() {
        let top = Hand::from(
            vec![
                Card::new(Value::Ace, Suit::Spade),
                Card::new(Value::Two, Suit::Spade),
                Card::new(Value::Three, Suit::Spade),
            ]
        );
        // A♠, 2♠, 3♠

        let bottom = Hand::from(
            vec![
                Card::new(Value::Four, Suit::Spade),
                Card::new(Value::Five, Suit::Spade),
                Card::new(Value::Six, Suit::Spade),
            ]
        );
        // 4♠, 5♠, 6♠

        let stacked = top.stack_bottom(bottom);
        // A♠, 2♠, 3♠, 4♠, 5♠, 6♠

        print_hand(&stacked)
    }

    #[test]
    fn insert() {
        let mut h = Hand::from(
            vec![
                Card::new(Value::Ace, Suit::Spade),
                Card::new(Value::Three, Suit::Spade),
                Card::new(Value::Four, Suit::Spade),
            ]
        );
        // h == A♠, 3♠, 4♠

        h = h.insert(1, Card::new(Value::Two, Suit::Spade));
        // h == A♠, 2♠, 3♠, 4♠

        print_hand(&h)
    }

    #[test]
    fn random_cards() {
        let now = Instant::now();
        for _i in 0..100 {
            println!("{}", cards::Card::random().string())
        }

        println!("{} ms", now.elapsed().as_millis())
    }

    

    //not a test
    fn print_hand(hand: &hand::Hand) {
        for card in &hand.vec {
            println!("{}", card.string())
        }
    }
}