|
@@ -1,18 +1,226 @@
|
1
|
1
|
package io.zipcoder.casino;
|
2
|
2
|
|
|
3
|
+import org.junit.Assert;
|
|
4
|
+import org.junit.Before;
|
3
|
5
|
import org.junit.Test;
|
4
|
6
|
|
|
7
|
+import java.util.ArrayList;
|
|
8
|
+
|
5
|
9
|
public class StudTest {
|
6
|
|
- public static void main(String[] args){
|
7
|
|
- Casino casino = new Casino();
|
8
|
|
- //get a player
|
9
|
|
- casino.setPlayer(casino.getConsole().createAccount());
|
10
|
|
- //player picks game
|
11
|
|
- casino.chooseGame();
|
|
10
|
+
|
|
11
|
+ Stud stud = new Stud(10);
|
|
12
|
+ ArrayList<CardPlayer> players = new ArrayList<>();
|
|
13
|
+ CardPlayer cardPlayer1;
|
|
14
|
+ CardPlayer cardPlayer2;
|
|
15
|
+
|
|
16
|
+ @Before
|
|
17
|
+ public void setup(){
|
|
18
|
+ ArrayList<Card> cardsTest1 = new ArrayList<>();
|
|
19
|
+ Player player1 = new Player("Player1", 10);
|
|
20
|
+ this.cardPlayer1 = new CardPlayer(player1);
|
|
21
|
+ Card cardSix = new Card(Card.CardValue.SIX, Card.Suit.HEARTS); //SIX - 600
|
|
22
|
+ Card cardFive = new Card(Card.CardValue.FIVE, Card.Suit.HEARTS); //FIVE - 50
|
|
23
|
+ Card cardFour = new Card(Card.CardValue.FOUR, Card.Suit.HEARTS); //FOUR - 4
|
|
24
|
+ cardsTest1.add(cardSix); cardsTest1.add(cardFive); cardsTest1.add(cardFour);
|
|
25
|
+ this.cardPlayer1.setHand(cardsTest1);
|
|
26
|
+
|
|
27
|
+ ArrayList<Card> cardsTest2 = new ArrayList<>();
|
|
28
|
+ Player player2 = new Player("Player2", 10);
|
|
29
|
+ this.cardPlayer2 = new CardPlayer(player2);
|
|
30
|
+ Card cardSeven = new Card(Card.CardValue.SEVEN, Card.Suit.HEARTS);
|
|
31
|
+ Card cardEight = new Card(Card.CardValue.EIGHT, Card.Suit.HEARTS);
|
|
32
|
+ Card cardNine = new Card(Card.CardValue.NINE, Card.Suit.HEARTS);
|
|
33
|
+ cardsTest2.add(cardSeven); cardsTest2.add(cardEight); cardsTest2.add(cardNine);
|
|
34
|
+ this.cardPlayer2.setHand(cardsTest2);
|
|
35
|
+
|
|
36
|
+ players.add(this.cardPlayer1);
|
|
37
|
+ players.add(this.cardPlayer2);
|
|
38
|
+
|
|
39
|
+ }
|
|
40
|
+
|
|
41
|
+ @Test
|
|
42
|
+ public void highCardHandValueTest(){
|
|
43
|
+ //WHEN
|
|
44
|
+ int card1 = 14; //ACE - 1400
|
|
45
|
+ int card2 = 13; //KING - 130
|
|
46
|
+ int card3 = 12; //QUEEN - 12
|
|
47
|
+ //THEN
|
|
48
|
+ int expected = 1542;
|
|
49
|
+ int actual = stud.highCardHandValue(card1, card2, card3);
|
|
50
|
+
|
|
51
|
+ Assert.assertEquals(expected, actual);
|
|
52
|
+ }
|
|
53
|
+
|
|
54
|
+ @Test
|
|
55
|
+ public void highCardHandValueTest2(){
|
|
56
|
+ //WHEN
|
|
57
|
+ int card2 = 11; //JACK - 110
|
|
58
|
+ int card1 = 9; //NINE - 09
|
|
59
|
+ int card3 = 12; //QUEEN - 1200
|
|
60
|
+ //THEN
|
|
61
|
+ int expected = 1319;
|
|
62
|
+ int actual = stud.highCardHandValue(card1, card2, card3);
|
|
63
|
+
|
|
64
|
+ Assert.assertEquals(expected, actual);
|
|
65
|
+ }
|
|
66
|
+
|
|
67
|
+ @Test
|
|
68
|
+ public void highCardHandValueTest3(){
|
|
69
|
+ //WHEN
|
|
70
|
+ int card1 = 11; //JACK - 110
|
|
71
|
+ int card2 = 9; //NINE - 09
|
|
72
|
+ int card3 = 12; //QUEEN - 1200
|
|
73
|
+ //THEN
|
|
74
|
+ int expected = 1319;
|
|
75
|
+ int actual = stud.highCardHandValue(card2, card3, card1);
|
|
76
|
+
|
|
77
|
+ Assert.assertEquals(expected, actual);
|
|
78
|
+ }
|
|
79
|
+
|
|
80
|
+ @Test
|
|
81
|
+ public void onePairHandValueTest(){ // card1 == card2
|
|
82
|
+ //WHEN
|
|
83
|
+ int card1 = 10; //TEN - 100000
|
|
84
|
+ int card2 = 10; //TEN - 0
|
|
85
|
+ int card3 = 02; //TWO - 2
|
|
86
|
+ //THEN
|
|
87
|
+ int expected = 100002;
|
|
88
|
+ int actual = stud.onePairHandValue(card1, card2, card3);
|
|
89
|
+
|
|
90
|
+ Assert.assertEquals(expected, actual);
|
|
91
|
+ }
|
|
92
|
+
|
|
93
|
+ @Test
|
|
94
|
+ public void onePairHandValueTest2() { // card1 == card3
|
|
95
|
+ //WHEN
|
|
96
|
+ int card1 = 10; //TEN - 100000
|
|
97
|
+ int card2 = 02; //TWO - 2
|
|
98
|
+ int card3 = 10; //TEN - 0
|
|
99
|
+ //THEN
|
|
100
|
+ int expected = 100002;
|
|
101
|
+ int actual = stud.onePairHandValue(card1, card2, card3);
|
|
102
|
+
|
|
103
|
+ Assert.assertEquals(expected, actual);
|
|
104
|
+ }
|
|
105
|
+
|
|
106
|
+ @Test
|
|
107
|
+ public void onePairHandValueTest3() { // card2 == card3
|
|
108
|
+ //WHEN
|
|
109
|
+ int card1 = 02; //TWO - 2
|
|
110
|
+ int card2 = 10; //TEN - 100000
|
|
111
|
+ int card3 = 10; //TEN - 0
|
|
112
|
+ //THEN
|
|
113
|
+ int expected = 100002;
|
|
114
|
+ int actual = stud.onePairHandValue(card1, card2, card3);
|
|
115
|
+
|
|
116
|
+ Assert.assertEquals(expected, actual);
|
|
117
|
+ }
|
|
118
|
+
|
|
119
|
+ @Test
|
|
120
|
+ public void threeOfAKindHandValueTest(){
|
|
121
|
+ //WHEN
|
|
122
|
+ int card1 = 3; //THREE - 3000000
|
|
123
|
+ //THEN
|
|
124
|
+ int expected = 3000000;
|
|
125
|
+ int actual = stud.threeOfAKindHandValue(card1);
|
|
126
|
+
|
|
127
|
+ Assert.assertEquals(expected, actual);
|
12
|
128
|
}
|
13
|
129
|
|
14
|
130
|
@Test
|
15
|
|
- public void thismethod(){
|
|
131
|
+ public void handValueTest(){
|
|
132
|
+ //WHEN
|
|
133
|
+ //SIX - 600
|
|
134
|
+ //FIVE - 50
|
|
135
|
+ //FOUR - 4
|
16
|
136
|
|
|
137
|
+ //THEN
|
|
138
|
+ int expected = 654;
|
|
139
|
+ int actual = stud.handValue(cardPlayer1);
|
|
140
|
+
|
|
141
|
+ Assert.assertEquals(expected, actual);
|
|
142
|
+ }
|
|
143
|
+
|
|
144
|
+ @Test
|
|
145
|
+ public void handValueTest2(){
|
|
146
|
+ //WHEN
|
|
147
|
+ ArrayList<Card> cardsTest = new ArrayList<>();
|
|
148
|
+ Player player1 = new Player("Test", 10);
|
|
149
|
+ this.cardPlayer1 = new CardPlayer(player1);
|
|
150
|
+ Card cardSix = new Card(Card.CardValue.SIX, Card.Suit.HEARTS);
|
|
151
|
+ Card cardFive = new Card(Card.CardValue.SIX, Card.Suit.HEARTS);
|
|
152
|
+ Card cardFour = new Card(Card.CardValue.SIX, Card.Suit.HEARTS);
|
|
153
|
+ cardsTest.add(cardSix); cardsTest.add(cardFive); cardsTest.add(cardFour);
|
|
154
|
+ this.cardPlayer1.setHand(cardsTest);
|
|
155
|
+ //THEN
|
|
156
|
+ int expected = 6000000;
|
|
157
|
+ int actual = stud.handValue(this.cardPlayer1);
|
|
158
|
+
|
|
159
|
+ Assert.assertEquals(expected, actual);
|
|
160
|
+ }
|
|
161
|
+
|
|
162
|
+ @Test
|
|
163
|
+ public void handValueTest3(){
|
|
164
|
+ //WHEN
|
|
165
|
+ ArrayList<Card> cardsTest = new ArrayList<>();
|
|
166
|
+ Player player1 = new Player("Test", 10);
|
|
167
|
+ this.cardPlayer1 = new CardPlayer(player1);
|
|
168
|
+ Card cardSix = new Card(Card.CardValue.SIX, Card.Suit.HEARTS);
|
|
169
|
+ Card cardFive = new Card(Card.CardValue.SIX, Card.Suit.HEARTS);
|
|
170
|
+ Card cardFour = new Card(Card.CardValue.SEVEN, Card.Suit.HEARTS);
|
|
171
|
+ cardsTest.add(cardSix); cardsTest.add(cardFive); cardsTest.add(cardFour);
|
|
172
|
+ this.cardPlayer1.setHand(cardsTest);
|
|
173
|
+ //THEN
|
|
174
|
+ int expected = 60007;
|
|
175
|
+ int actual = stud.handValue(this.cardPlayer1);
|
|
176
|
+
|
|
177
|
+ Assert.assertEquals(expected, actual);
|
|
178
|
+ }
|
|
179
|
+
|
|
180
|
+ @Test
|
|
181
|
+ public void determineWinnerTEST(){
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+ String expected = "Player2";
|
|
185
|
+ String actual = stud.determineWinner(players).getPlayer().getName();
|
|
186
|
+
|
|
187
|
+ Assert.assertEquals(expected, actual);
|
17
|
188
|
}
|
18
|
189
|
}
|
|
190
|
+/*
|
|
191
|
+ public CardPlayer determineWinner(ArrayList<CardPlayer> players){
|
|
192
|
+ int max = 0;
|
|
193
|
+ CardPlayer winner = null;
|
|
194
|
+
|
|
195
|
+ for(int i = 0; i < players.size(); i ++){
|
|
196
|
+ CardPlayer player = players.get(i);
|
|
197
|
+ int playerHandValue = handValue(player); // 'handValue' method sets 'max' value of this hand
|
|
198
|
+ if(playerHandValue > max){
|
|
199
|
+ max = playerHandValue;
|
|
200
|
+ winner = player;
|
|
201
|
+ }
|
|
202
|
+ }
|
|
203
|
+ System.out.println("The winner is " + winner.getPlayer().getName());
|
|
204
|
+ System.out.println(winner.getPlayer().getName() + "\'s hand was: " + winner.getHand().get(0).getName() +
|
|
205
|
+ " - " + winner.getHand().get(1).getName() + " - " + winner.getHand().get(2).getName() + "\n\n" );
|
|
206
|
+ return winner;
|
|
207
|
+ }
|
|
208
|
+
|
|
209
|
+ public CardPlayer determineWinner(){
|
|
210
|
+ int max = 0;
|
|
211
|
+ CardPlayer winner = null;
|
|
212
|
+
|
|
213
|
+ for(int i = 0; i < getPlayers().size(); i ++){
|
|
214
|
+ CardPlayer player = getPlayers().get(i);
|
|
215
|
+ int playerHandValue = handValue(player); // 'handValue' method sets 'max' value of this hand
|
|
216
|
+ if(playerHandValue > max){
|
|
217
|
+ max = playerHandValue;
|
|
218
|
+ winner = player;
|
|
219
|
+ }
|
|
220
|
+ }
|
|
221
|
+ System.out.println("The winner is " + winner.getPlayer().getName());
|
|
222
|
+ System.out.println(winner.getPlayer().getName() + "\'s hand was: " + winner.getHand().get(0).getName() +
|
|
223
|
+ " - " + winner.getHand().get(1).getName() + " - " + winner.getHand().get(2).getName() + "\n\n" );
|
|
224
|
+ return winner;
|
|
225
|
+ }
|
|
226
|
+ */
|