Browse Source

Merge branch 'Working' of tkhong102/ZCW-OOP-Casino into Working

nedredmond 6 years ago
parent
commit
36e337154d

+ 6
- 1
src/main/java/io/zipcoder/casino/cardgames/BlackJack.java View File

88
         return false;
88
         return false;
89
     }
89
     }
90
 
90
 
91
+    public Deck getDeck() {
92
+        //for testing
93
+        return deck;
94
+    }
95
+
91
     public void dealerCollectAll() {
96
     public void dealerCollectAll() {
92
         for (BlackJackPlayer p : this.blackJackPlayers) { // collects bet from all players
97
         for (BlackJackPlayer p : this.blackJackPlayers) { // collects bet from all players
93
             evaluateBet(p.getP(), -p.getBet());
98
             evaluateBet(p.getP(), -p.getBet());
243
 
248
 
244
 
249
 
245
     public Card drawCard() {
250
     public Card drawCard() {
246
-        // draws card from deck and adds it to "upcard" total
251
+
247
         Card card = deck.removeFirst();
252
         Card card = deck.removeFirst();
248
         return card;
253
         return card;
249
     }
254
     }

+ 77
- 0
src/test/java/io/zipcoder/casino/BlackJackTest.java View File

1
 package io.zipcoder.casino;
1
 package io.zipcoder.casino;
2
 
2
 
3
+import io.zipcoder.casino.cardgames.BlackJack;
4
+import io.zipcoder.casino.player.BlackJackPlayer;
5
+import io.zipcoder.casino.utilities.Card;
6
+import io.zipcoder.casino.utilities.containers.CardHand;
7
+import io.zipcoder.casino.utilities.containers.Deck;
8
+import io.zipcoder.casino.utilities.enums.CardValue;
9
+import org.junit.Assert;
3
 import org.junit.Test;
10
 import org.junit.Test;
4
 
11
 
12
+import java.util.ArrayList;
13
+
14
+import static io.zipcoder.casino.utilities.enums.CardSuit.HEARTS;
15
+
5
 public class BlackJackTest {
16
 public class BlackJackTest {
17
+  Deck deck = new Deck();
18
+  BlackJack blackJack = new BlackJack();
19
+  ArrayList<BlackJackPlayer> blackJackPlayers = new ArrayList<>();
20
+  CardHand dealerHand = new CardHand();
21
+  CardHand playerHand = new CardHand();
22
+  BlackJackPlayer player = new BlackJackPlayer();
23
+  Card card10 = new Card(CardValue.TEN,HEARTS);
24
+  Card card7 = new Card(CardValue.SEVEN,HEARTS);
25
+  Card cardAce = new Card(CardValue.ACE,HEARTS);
26
+
27
+
28
+    @Test
29
+    public void testPayoutAll(){
30
+        player.setBet(100);
31
+        blackJack.payoutAll();
32
+        long expected = 100;
33
+        long actual = player.getBet();
34
+        Assert.assertEquals(expected, actual);
35
+    }
36
+
37
+    @Test
38
+    public void testDealerDraw(){
39
+    blackJack.dealerDraw();
40
+    int expected = 2;
41
+    int actual = dealerHand.size();
42
+    Assert.assertEquals(expected,actual);
43
+    }
44
+
45
+    @Test
46
+    public void testDealCards(){
47
+        blackJack.dealCards(2);
48
+        int expected = 50;
49
+        int actual = blackJack.getDeck().size();
50
+        Assert.assertEquals(expected, actual);
51
+    }
52
+
53
+
54
+    @Test
55
+    public void testDrawCard(){
56
+        blackJack.drawCard();
57
+
58
+      int expected = 51;
59
+      int actual = blackJack.getDeck().size();
60
+      Assert.assertEquals(expected, actual);
61
+    }
62
+
63
+    @Test
64
+    public void testRevealCard(){
65
+        dealerHand.add(card10);
66
+        blackJack.revealCard();
67
+        int expected = 1;
68
+        int actual = dealerHand.size();
69
+
70
+    Assert.assertEquals(expected, actual);
71
+    }
72
+
73
+    @Test
74
+    public void testGetSum(){
75
+
76
+        playerHand.add(card7);
77
+        playerHand.add(card10);
78
+
79
+        int expected = 17;
80
+        int actual = blackJack.getSum(playerHand);
6
 
81
 
82
+        Assert.assertEquals(expected, actual);
7
 
83
 
84
+    }
8
 }
85
 }