|
@@ -3,6 +3,11 @@ package io.zipcoder.casino;
|
3
|
3
|
import org.junit.Assert;
|
4
|
4
|
import org.junit.Test;
|
5
|
5
|
|
|
6
|
+import java.io.ByteArrayInputStream;
|
|
7
|
+import java.util.ArrayList;
|
|
8
|
+import java.util.NoSuchElementException;
|
|
9
|
+import java.util.Scanner;
|
|
10
|
+
|
6
|
11
|
public class WarTest {
|
7
|
12
|
|
8
|
13
|
@Test
|
|
@@ -40,4 +45,116 @@ public class WarTest {
|
40
|
45
|
Assert.assertEquals(war.getLoser(), player);
|
41
|
46
|
}
|
42
|
47
|
|
|
48
|
+ @Test
|
|
49
|
+ public void warDealTest(){
|
|
50
|
+ War war = new War(10);
|
|
51
|
+ war.addPlayers(new Player("Jon", 100));
|
|
52
|
+ war.chooseStatingPlayer();
|
|
53
|
+ war.deal();
|
|
54
|
+
|
|
55
|
+ Assert.assertTrue(war.getPlayers().get(0).getHand().size() == 52);
|
|
56
|
+ }
|
|
57
|
+
|
|
58
|
+ @Test
|
|
59
|
+ public void warEachPlayerPlayCardTest(){
|
|
60
|
+ War war = new War(10);
|
|
61
|
+ war.addPlayers(new Player("Jon", 100), new Player("Jose", 200));
|
|
62
|
+
|
|
63
|
+ war.chooseStatingPlayer();
|
|
64
|
+ war.deal();
|
|
65
|
+ war.eachPlayerPlayCard();
|
|
66
|
+
|
|
67
|
+ int toalHand = 0;
|
|
68
|
+
|
|
69
|
+ for(CardPlayer player : war.getPlayers()){
|
|
70
|
+ toalHand += player.getHand().size();
|
|
71
|
+ }
|
|
72
|
+ Assert.assertTrue(toalHand == 50);
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+ @Test
|
|
76
|
+ public void testWarStartGame(){
|
|
77
|
+ War war = new War(10);
|
|
78
|
+ Player player1 = new Player("Jose", 100);
|
|
79
|
+ Player player2 = new Player("Lauren", 200);
|
|
80
|
+ war.addPlayers(player1, player2);
|
|
81
|
+ war.chooseStatingPlayer();
|
|
82
|
+ war.deal();
|
|
83
|
+
|
|
84
|
+ String input = "flip \n";
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+ war.setScanner(new Scanner(new ByteArrayInputStream(input.getBytes())));
|
|
88
|
+ try {
|
|
89
|
+ war.startGame();
|
|
90
|
+ } catch (NoSuchElementException e) {
|
|
91
|
+
|
|
92
|
+ }
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+ Assert.assertTrue(war.getPlayersTurn() instanceof CardPlayer);
|
|
96
|
+ }
|
|
97
|
+
|
|
98
|
+ @Test
|
|
99
|
+ public void testWarQuit(){
|
|
100
|
+ War war = new War(10);
|
|
101
|
+ Player player1 = new Player("Jose", 100);
|
|
102
|
+ Player player2 = new Player("Lauren", 200);
|
|
103
|
+ war.addPlayers(player1, player2);
|
|
104
|
+ war.chooseStatingPlayer();
|
|
105
|
+ CardPlayer startPlayer = war.getPlayersTurn();
|
|
106
|
+ war.deal();
|
|
107
|
+
|
|
108
|
+ String input = "quit \n";
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+ war.setScanner(new Scanner(new ByteArrayInputStream(input.getBytes())));
|
|
112
|
+ try {
|
|
113
|
+ war.startGame();
|
|
114
|
+ } catch (NoSuchElementException e) {
|
|
115
|
+
|
|
116
|
+ }
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+ Assert.assertTrue(war.getPlayersTurn() == startPlayer);
|
|
120
|
+ }
|
|
121
|
+
|
|
122
|
+ @Test
|
|
123
|
+ public void testWarMethod(){
|
|
124
|
+ War war = new War(10);
|
|
125
|
+ Player player1 = new Player("Jose", 100);
|
|
126
|
+ Player player2 = new Player("Lauren", 200);
|
|
127
|
+ war.addPlayers(player1, player2);
|
|
128
|
+ war.chooseStatingPlayer();
|
|
129
|
+ CardPlayer startPlayer = war.getPlayersTurn();
|
|
130
|
+
|
|
131
|
+ ArrayList<Card> hand1 = new ArrayList<>();
|
|
132
|
+ hand1.add(new Card(Card.CardValue.FOUR, Card.Suit.HEARTS));
|
|
133
|
+ hand1.add(new Card(Card.CardValue.FOUR, Card.Suit.HEARTS));
|
|
134
|
+ hand1.add(new Card(Card.CardValue.THREE, Card.Suit.HEARTS));
|
|
135
|
+ hand1.add(new Card(Card.CardValue.TWO, Card.Suit.HEARTS));
|
|
136
|
+ hand1.add(new Card(Card.CardValue.ACE, Card.Suit.HEARTS));
|
|
137
|
+
|
|
138
|
+ ArrayList<Card> hand2 = new ArrayList<>();
|
|
139
|
+ hand2.add(new Card(Card.CardValue.FOUR, Card.Suit.HEARTS));
|
|
140
|
+ hand2.add(new Card(Card.CardValue.KING, Card.Suit.HEARTS));
|
|
141
|
+ hand2.add(new Card(Card.CardValue.JACK, Card.Suit.HEARTS));
|
|
142
|
+ hand2.add(new Card(Card.CardValue.QUEEN, Card.Suit.HEARTS));
|
|
143
|
+ hand2.add(new Card(Card.CardValue.KING, Card.Suit.HEARTS));
|
|
144
|
+
|
|
145
|
+ String input = "flip \n";
|
|
146
|
+
|
|
147
|
+ war.getPlayers().get(0).setHand(hand1);
|
|
148
|
+ war.getPlayers().get(1).setHand(hand2);
|
|
149
|
+
|
|
150
|
+ war.setScanner(new Scanner(new ByteArrayInputStream(input.getBytes())));
|
|
151
|
+ try {
|
|
152
|
+ war.startRound();
|
|
153
|
+ } catch (NoSuchElementException e) {
|
|
154
|
+
|
|
155
|
+ }
|
|
156
|
+
|
|
157
|
+ Assert.assertTrue(war.getPlayers().get(0).getHand().size() == 1);
|
|
158
|
+ }
|
|
159
|
+
|
43
|
160
|
}
|