-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoker_test.cpp
108 lines (93 loc) · 3.46 KB
/
poker_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//
// Created by ryanj on 7/21/2019.
//
#include "poker.h"
#include "gtest/gtest.h"
using namespace ::poker;
void Fixture_create_hand(playerHand &hand, cardSuit &suit, std::vector<int> pips_values ){
for(int pips : pips_values)
hand.takeCard(card(suit, pips ));
}
//fixture straight flush
void Fixture_straightFlush(playerHand &hand, cardSuit &suit) {
Fixture_create_hand(hand, suit, {9,10,11,12,13});
}
void Fixture_royalFlush(playerHand &hand, cardSuit suit) {
Fixture_create_hand(hand, suit, {1,10,11,12,13});
}
TEST(PlayerHand_StraightFlushTest, HandlesZeroInput) {
playerHand TestStraight;
for (int i = 1; i != 6; i++) {
TestStraight.takeCard(card(cardSuit::SPADE, pips(i)));
}
TestStraight.calculate5CardPokerScore();
PlayerHandInfo HandInfo = TestStraight.CheckHand();
EXPECT_EQ(HandInfo.hasStraight, true);
EXPECT_EQ(HandInfo.hasStraightFlush, true);
EXPECT_EQ(HandInfo.hasFlush, true);
}
TEST(PlayerHand_PairTest, HandlesZeroInput) {
playerHand TestPair;
TestPair.takeCard(card(cardSuit::SPADE, 1));
TestPair.takeCard(card(cardSuit::HEART, 1));
TestPair.takeCard(card(cardSuit::CLUB, 5));
TestPair.takeCard(card(cardSuit::DIAMOND, 9));
TestPair.takeCard(card(cardSuit::SPADE, 7));
TestPair.calculate5CardPokerScore();
PlayerHandInfo HandInfo = TestPair.CheckHand();
EXPECT_EQ(HandInfo.hasPair, true);
EXPECT_EQ(HandInfo.score, poker::CombinationBaseScore[poker::CombinationRank::Pair] + 14);
}
TEST(PlayerHand_FlushTest, HandlesZeroInput) {
playerHand testHand;
testHand.takeCard(card(cardSuit::SPADE, 0));
testHand.takeCard(card(cardSuit::SPADE, 2));
testHand.takeCard(card(cardSuit::SPADE, 4));
testHand.takeCard(card(cardSuit::SPADE, 7));
testHand.takeCard(card(cardSuit::SPADE, 10));
testHand.calculate5CardPokerScore();
PlayerHandInfo HandInfo = testHand.CheckHand();
EXPECT_EQ(HandInfo.hasFlush, true);
EXPECT_EQ(HandInfo.hasPair, false);
EXPECT_EQ(HandInfo.hasStraight, false);
}
TEST(PlayerHand_Straight_NoFlushTest, HandlesZeroInput) {
playerHand testHand;
testHand.takeCard(card(cardSuit::SPADE, 2));
testHand.takeCard(card(cardSuit::SPADE, 3));
testHand.takeCard(card(cardSuit::HEART, 4));
testHand.takeCard(card(cardSuit::SPADE, 5));
testHand.takeCard(card(cardSuit::DIAMOND, 6));
testHand.calculate5CardPokerScore();
PlayerHandInfo HandInfo = testHand.CheckHand();
EXPECT_EQ(HandInfo.hasFlush, false);
EXPECT_EQ(HandInfo.hasPair, false);
EXPECT_EQ(HandInfo.hasStraight, true);
EXPECT_EQ(HandInfo.hasRoyalFlush,false);
}
TEST(PlayerHand_RoyalFlushTest, HandlesZeroInput) {
playerHand testHand;
Fixture_royalFlush(testHand, cardSuit::CLUB);
testHand.calculate5CardPokerScore();
PlayerHandInfo HandInfo = testHand.CheckHand();
EXPECT_EQ(HandInfo.hasFlush, true);
EXPECT_EQ(HandInfo.hasPair, false);
EXPECT_EQ(HandInfo.hasStraight, true);
EXPECT_EQ(HandInfo.hasRoyalFlush,true);
//EXPECT_EQ(testHand.getPokerScore(), (63 + 13));
}
// tests for the game
TEST(Game_ScoreTest, HandlesZeroInput) {
int number_of_players{4};
int size_of_hand{5};
//int size_of_deck{5};
cardGame mygame(number_of_players, size_of_hand);
mygame.calculatePokerScore();
mygame.SortHandsByScores();
mygame.printPokerScores();
}
//EXPECT_EQ(TestGame.PrintHands(), true);}
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}