initial commit
This commit is contained in:
commit
94b1f06590
16 changed files with 631 additions and 0 deletions
10
src/tests/deck_test.rs
Normal file
10
src/tests/deck_test.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::models::deck::Deck;
|
||||
|
||||
#[test]
|
||||
fn test_new_deck_has_52_cards() {
|
||||
let deck = Deck::new();
|
||||
assert_eq!(deck.cards.len(), 52);
|
||||
}
|
||||
}
|
160
src/tests/hand_test.rs
Normal file
160
src/tests/hand_test.rs
Normal file
|
@ -0,0 +1,160 @@
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::models::deck::{Card, Deck};
|
||||
use crate::models::hand::Hand;
|
||||
use crate::models::player::Player;
|
||||
|
||||
#[test]
|
||||
fn test_hand_has_correct_amount_of_cards_after_drawing() {
|
||||
let mut deck = Deck::new();
|
||||
let mut player = Player {
|
||||
name: String::from("Testy McTestFace"),
|
||||
hand: Hand::new(),
|
||||
};
|
||||
|
||||
player.hand.draw(5, &mut deck);
|
||||
assert_eq!(player.hand.cards.len(), 5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_hand_adds_cards_to_exhasting_hand() {
|
||||
let mut deck = Deck::new();
|
||||
let mut player = Player {
|
||||
name: String::from("Testy McTestFace"),
|
||||
hand: Hand::new(),
|
||||
};
|
||||
|
||||
player.hand.draw(5, &mut deck);
|
||||
player.hand.draw(3, &mut deck);
|
||||
assert_eq!(player.hand.cards.len(), 8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_has_single_pair() {
|
||||
let mut hand = Hand::new();
|
||||
|
||||
hand.cards.push(Card { rank: "A".to_string(), value: 14, suit: "♥".to_string() });
|
||||
hand.cards.push(Card { rank: "2".to_string(), value: 2, suit: "♠".to_string() });
|
||||
hand.cards.push(Card { rank: "4".to_string(), value: 4, suit: "♥".to_string() });
|
||||
hand.cards.push(Card { rank: "A".to_string(), value: 14, suit: "◆".to_string() });
|
||||
hand.cards.push(Card { rank: "5".to_string(), value: 5, suit: "♣".to_string() });
|
||||
|
||||
assert_eq!(hand.has_single_pair(), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_has_two_pair() {
|
||||
let mut hand = Hand::new();
|
||||
|
||||
hand.cards.push(Card { rank: "A".to_string(), value: 14, suit: "♥".to_string() });
|
||||
hand.cards.push(Card { rank: "2".to_string(), value: 2, suit: "♠".to_string() });
|
||||
hand.cards.push(Card { rank: "2".to_string(), value: 2, suit: "♥".to_string() });
|
||||
hand.cards.push(Card { rank: "A".to_string(), value: 14, suit: "◆".to_string() });
|
||||
hand.cards.push(Card { rank: "5".to_string(), value: 5, suit: "♣".to_string() });
|
||||
|
||||
assert_eq!(hand.has_two_pair(), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_has_three_of_a_kind() {
|
||||
let mut hand = Hand::new();
|
||||
|
||||
hand.cards.push(Card { rank: "A".to_string(), value: 14, suit: "♥".to_string() });
|
||||
hand.cards.push(Card { rank: "2".to_string(), value: 2, suit: "♠".to_string() });
|
||||
hand.cards.push(Card { rank: "2".to_string(), value: 4, suit: "♥".to_string() });
|
||||
hand.cards.push(Card { rank: "5".to_string(), value: 14, suit: "◆".to_string() });
|
||||
hand.cards.push(Card { rank: "2".to_string(), value: 5, suit: "♣".to_string() });
|
||||
|
||||
assert_eq!(hand.has_three_of_a_kind(), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_has_four_of_a_kind() {
|
||||
let mut hand = Hand::new();
|
||||
|
||||
hand.cards.push(Card { rank: "2".to_string(), value: 14, suit: "♥".to_string() });
|
||||
hand.cards.push(Card { rank: "2".to_string(), value: 2, suit: "♠".to_string() });
|
||||
hand.cards.push(Card { rank: "2".to_string(), value: 4, suit: "◆".to_string() });
|
||||
hand.cards.push(Card { rank: "5".to_string(), value: 14, suit: "◆".to_string() });
|
||||
hand.cards.push(Card { rank: "2".to_string(), value: 5, suit: "♣".to_string() });
|
||||
|
||||
assert_eq!(hand.has_four_of_a_kind(), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_has_straight() {
|
||||
let mut hand = Hand::new();
|
||||
hand.cards.push(Card { rank: "9".to_string(), value: 9, suit: "◆".to_string() });
|
||||
hand.cards.push(Card { rank: "7".to_string(), value: 7, suit: "♥".to_string() });
|
||||
hand.cards.push(Card { rank: "J".to_string(), value: 11, suit: "♣".to_string() });
|
||||
hand.cards.push(Card { rank: "8".to_string(), value: 8, suit: "♠".to_string() });
|
||||
hand.cards.push(Card { rank: "10".to_string(), value: 10, suit: "◆".to_string() });
|
||||
|
||||
assert_eq!(hand.has_straight(), true);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_has_straight_ace_low() {
|
||||
let mut hand = Hand::new();
|
||||
|
||||
hand.cards.push(Card { rank: "2".to_string(), value: 2, suit: "♥".to_string() });
|
||||
hand.cards.push(Card { rank: "4".to_string(), value: 4, suit: "◆".to_string() });
|
||||
hand.cards.push(Card { rank: "A".to_string(), value: 14, suit: "♣".to_string() });
|
||||
hand.cards.push(Card { rank: "5".to_string(), value: 5, suit: "◆".to_string() });
|
||||
hand.cards.push(Card { rank: "3".to_string(), value: 3, suit: "♠".to_string() });
|
||||
|
||||
assert_eq!(hand.has_straight(), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_has_flush() {
|
||||
let mut hand = Hand::new();
|
||||
|
||||
hand.cards.push(Card { rank: "2".to_string(), value: 2, suit: "♥".to_string() });
|
||||
hand.cards.push(Card { rank: "4".to_string(), value: 4, suit: "♥".to_string() });
|
||||
hand.cards.push(Card { rank: "9".to_string(), value: 9, suit: "♥".to_string() });
|
||||
hand.cards.push(Card { rank: "5".to_string(), value: 5, suit: "♥".to_string() });
|
||||
hand.cards.push(Card { rank: "8".to_string(), value: 8, suit: "♥".to_string() });
|
||||
|
||||
assert_eq!(hand.has_flush(), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_has_full_house() {
|
||||
let mut hand = Hand::new();
|
||||
|
||||
hand.cards.push(Card { rank: "2".to_string(), value: 2, suit: "♥".to_string() });
|
||||
hand.cards.push(Card { rank: "5".to_string(), value: 5, suit: "♠".to_string() });
|
||||
hand.cards.push(Card { rank: "2".to_string(), value: 2, suit: "♣".to_string() });
|
||||
hand.cards.push(Card { rank: "5".to_string(), value: 5, suit: "◆".to_string() });
|
||||
hand.cards.push(Card { rank: "2".to_string(), value: 2, suit: "◆".to_string() });
|
||||
|
||||
assert_eq!(hand.has_full_house(), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_has_straight_flush() {
|
||||
let mut hand = Hand::new();
|
||||
|
||||
hand.cards.push(Card { rank: "2".to_string(), value: 2, suit: "♥".to_string() });
|
||||
hand.cards.push(Card { rank: "3".to_string(), value: 3, suit: "♥".to_string() });
|
||||
hand.cards.push(Card { rank: "4".to_string(), value: 4, suit: "♥".to_string() });
|
||||
hand.cards.push(Card { rank: "5".to_string(), value: 5, suit: "♥".to_string() });
|
||||
hand.cards.push(Card { rank: "6".to_string(), value: 6, suit: "♥".to_string() });
|
||||
|
||||
assert_eq!(hand.has_straight_flush(), true)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_has_royal_flush() {
|
||||
let mut hand = Hand::new();
|
||||
|
||||
hand.cards.push(Card { rank: "10".to_string(), value: 10, suit: "♥".to_string() });
|
||||
hand.cards.push(Card { rank: "J".to_string(), value: 11, suit: "♥".to_string() });
|
||||
hand.cards.push(Card { rank: "Q".to_string(), value: 12, suit: "♥".to_string() });
|
||||
hand.cards.push(Card { rank: "K".to_string(), value: 13, suit: "♥".to_string() });
|
||||
hand.cards.push(Card { rank: "A".to_string(), value: 14, suit: "♥".to_string() });
|
||||
|
||||
assert_eq!(hand.has_royal_flush(), true)
|
||||
}
|
||||
}
|
2
src/tests/mod.rs
Normal file
2
src/tests/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
mod deck_test;
|
||||
mod hand_test;
|
Loading…
Add table
Add a link
Reference in a new issue