-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player_public_test.cpp
121 lines (99 loc) · 3.03 KB
/
Player_public_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
109
110
111
112
113
114
115
116
117
118
119
120
121
/* Player_public_test.cpp
*
* Unit tests for the Simple and Human Euchre players
*
* by Andrew DeOrio
* 2021-03-12
*/
#include "Player.hpp"
#include "Card.hpp"
#include "unit_test_framework.hpp"
#include <sstream>
using namespace std;
// THESE TEST CASES WILL ONLY TELL YOU IF YOUR CODE COMPILES.
// YOU NEED TO WRITE YOUR OWN COMPREHENSIVE TEST CASES IN Player_tests.cpp
TEST(test_player_insertion) {
// Create a Human player
Player * human = Player_factory("NotRobot", "Human");
// Print the player using the stream insertion operator
ostringstream oss1;
oss1 << * human;
// Verify that the output is the player's name
ASSERT_EQUAL(oss1.str(), "NotRobot");
// Create a Simple player
Player * alice = Player_factory("Alice", "Simple");
// Print the player using the stream insertion operator
ostringstream oss2;
oss2 << *alice;
ASSERT_EQUAL(oss2.str(), "Alice");
// Clean up players that were created using Player_factory()
delete human;
delete alice;
}
TEST(test_player_get_name) {
// Create a player and verify that get_name() returns the player's name
Player * alice = Player_factory("Alice", "Simple");
ASSERT_EQUAL(alice->get_name(), "Alice");
delete alice;
}
TEST(test_simple_player_make_trump) {
// Bob's hand
Player * bob = Player_factory("Bob", "Simple");
bob->add_card(Card(NINE, SPADES));
bob->add_card(Card(TEN, SPADES));
bob->add_card(Card(QUEEN, SPADES));
bob->add_card(Card(KING, SPADES));
bob->add_card(Card(ACE, SPADES));
// Bob makes tump
Card nine_spades(NINE, SPADES);
Suit trump;
bool orderup = bob->make_trump(
nine_spades, // Upcard
true, // Bob is also the dealer
1, // First round
trump // Suit ordered up (if any)
);
// Verify Bob's order up and trump suit
ASSERT_TRUE(orderup);
ASSERT_EQUAL(trump, SPADES);
delete bob;
}
TEST(test_simple_player_lead_card) {
// Bob's hand
Player * bob = Player_factory("Bob", "Simple");
bob->add_card(Card(NINE, SPADES));
bob->add_card(Card(TEN, SPADES));
bob->add_card(Card(QUEEN, SPADES));
bob->add_card(Card(KING, SPADES));
bob->add_card(Card(ACE, SPADES));
// Bob adds a card to his hand and discards one card
bob->add_and_discard(
Card(NINE, HEARTS) // upcard
);
// Bob leads
Card card_led = bob->lead_card(HEARTS);
// Verify the card Bob selected to lead
Card ace_spades(ACE, SPADES);
ASSERT_EQUAL(card_led, ace_spades); //check led card
delete bob;
}
TEST(test_simple_player_play_card) {
// Bob's hand
Player * bob = Player_factory("Bob", "Simple");
bob->add_card(Card(NINE, SPADES));
bob->add_card(Card(TEN, SPADES));
bob->add_card(Card(QUEEN, SPADES));
bob->add_card(Card(KING, SPADES));
bob->add_card(Card(ACE, SPADES));
// Bob plays a card
Card nine_diamonds(NINE, DIAMONDS);
Card card_played = bob->play_card(
nine_diamonds, // Nine of Diamonds is led
HEARTS // Trump suit
);
// Verify the card Bob played
ASSERT_EQUAL(card_played, Card(NINE, SPADES));
delete bob;
}
TEST_MAIN()