Akeem Cherry 6 년 전
부모
커밋
97b70674d1

+ 0
- 16
src/main/java/io/zipcoder/casino/Dealer.java 파일 보기

@@ -1,16 +0,0 @@
1
-package io.zipcoder.casino;
2
-
3
-public class Dealer extends Player {
4
-
5
-    public Dealer(String name, double moneyStartedWith) {
6
-        super(name, moneyStartedWith);
7
-    }
8
-
9
-    public void dealCards(Player player, Card card){
10
-
11
-    }
12
-
13
-    public void takeBet(Player player, double money){
14
-
15
-    }
16
-}

+ 41
- 0
src/main/java/io/zipcoder/casino/Hand.java 파일 보기

@@ -0,0 +1,41 @@
1
+package io.zipcoder.casino;
2
+
3
+import java.util.ArrayList;
4
+import java.util.List;
5
+
6
+public class Hand {
7
+    private  List<Card> cards = new ArrayList<Card>();
8
+
9
+    public void clear(){
10
+        cards.clear();
11
+    }
12
+
13
+    public void add(Card c){
14
+        if(cards == null)
15
+            throw new NullPointerException ("no cards in hand, add new card");
16
+            cards.add(c);
17
+    }
18
+
19
+
20
+    public Integer getValue(){
21
+       Integer sum = 0;
22
+       for(Card card: cards){
23
+        sum+= card.getValue();
24
+       }
25
+        return sum;
26
+    }
27
+
28
+
29
+    public List<Card> getCards() {
30
+        return cards;
31
+    }
32
+
33
+    public void setCards(List<Card> cards) {
34
+
35
+        this.cards = cards;
36
+    }
37
+
38
+    public boolean contains(Card card){
39
+        return this.cards.contains(card);
40
+    }
41
+}

+ 0
- 55
src/main/java/io/zipcoder/casino/Player.java 파일 보기

@@ -1,55 +0,0 @@
1
-package io.zipcoder.casino;
2
-
3
-public class Player {
4
-
5
-    private String name;
6
-
7
-    private Hand hand;
8
-
9
-    private Wallet wallet;
10
-    private double wager;
11
-
12
-    public Player(String name, double moneyStartedWith) {
13
-
14
-        this.hand = new Hand();
15
-
16
-        this.name = name;
17
-
18
-        this.wallet = new Wallet(moneyStartedWith);
19
-    }
20
-
21
-    public void addCard(Card card) {
22
-
23
-        hand.add(card);
24
-    }
25
-
26
-    public Hand getHand() {
27
-
28
-        return hand;
29
-    }
30
-
31
-    public void setHand(Hand hand) {
32
-
33
-        this.hand = hand;
34
-    }
35
-
36
-    public String getName() {
37
-
38
-        return name;
39
-    }
40
-
41
-    public void setWager(double money) {
42
-        this.wager = money;
43
-        wallet.takeMoney(money);
44
-    }
45
-
46
-    public double getWalletAmount() {
47
-        return wallet.getCurrentAmount();
48
-    }
49
-
50
-    public double getWager() {
51
-
52
-        return wager;
53
-    }
54
-
55
-}

+ 26
- 0
src/test/java/io/zipcoder/casino/BlackjackDealerTest.java 파일 보기

@@ -0,0 +1,26 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Test;
4
+
5
+public class BlackjackDealerTest {
6
+
7
+    @Test
8
+    public void testDealCard(){
9
+        //Given
10
+
11
+        //When
12
+
13
+        //Then
14
+
15
+    }
16
+
17
+    @Test
18
+    public void testTakeBet(){
19
+        //given
20
+        Player play = new Player();
21
+
22
+        //When
23
+
24
+        //Then
25
+    }
26
+}

+ 0
- 45
src/test/java/io/zipcoder/casino/BlackjackPlayerTest.java 파일 보기

@@ -1,45 +0,0 @@
1
-package io.zipcoder.casino;
2
-
3
-import io.zipcoder.casino.BlackjackPlayer;
4
-import org.junit.Assert;
5
-import org.junit.Before;
6
-import org.junit.Test;
7
-
8
-public class BlackjackPlayerTest {
9
-
10
-    BlackjackPlayer blackjackPlayer;
11
-
12
-
13
-    @Before
14
-    public void setup(){
15
-
16
-        blackjackPlayer  = new BlackjackPlayer("Xzavia", 200.00);
17
-
18
-    }
19
-
20
-    @Test
21
-    public void setWagerTest() {
22
-
23
-        //When
24
-        double actual = 100.00;
25
-
26
-        blackjackPlayer.setWager(100.00);
27
-
28
-        double expected = blackjackPlayer.getWager();
29
-
30
-        //Then
31
-        Assert.assertEquals(expected, actual, 0);
32
-    }
33
-
34
-    @Test
35
-    public void getNameTest() {
36
-
37
-        String expected = "Tommy";
38
-
39
-        String actual = blackjackPlayer.getName();
40
-
41
-        Assert.assertEquals(expected, actual);
42
-    }
43
-
44
-
45
-}

+ 76
- 0
src/test/java/io/zipcoder/casino/HandTest.java 파일 보기

@@ -0,0 +1,76 @@
1
+package io.zipcoder.casino;
2
+
3
+import org.junit.Assert;
4
+import org.junit.Test;
5
+
6
+import java.util.ArrayList;
7
+import java.util.List;
8
+
9
+public class HandTest {
10
+
11
+    @Test
12
+    public void testAdd(){
13
+
14
+        //Given
15
+        Card expected = new Card(Suit.Diamond, Rank.Ace);
16
+        Hand hand = new Hand();
17
+
18
+        //When
19
+        hand.add(expected);
20
+        //Then
21
+        Assert.assertTrue(hand.contains(expected));
22
+    }
23
+
24
+    @Test
25
+    public void testGetValue(){
26
+
27
+        //Given
28
+        Card card1 = new Card(Suit.Diamond, Rank.Ace);
29
+        Card card2 = new Card(Suit.Spade, Rank.King);
30
+        Hand hand = new Hand();
31
+        hand.add(card1);
32
+        hand.add(card2);
33
+        Integer expectedValue = 11;
34
+
35
+        //when
36
+        Integer actual = hand.getValue();
37
+        //then
38
+        Assert.assertEquals(expectedValue, actual);
39
+    }
40
+
41
+    @Test
42
+    public void testGetCards(){
43
+    //Given
44
+        Hand hand= new Hand();
45
+        Card card1 = new Card(Suit.Diamond, Rank.Ace);
46
+        Card card2 = new Card(Suit.Spade, Rank.King);
47
+        hand.add(card1);
48
+        hand.add(card2);
49
+
50
+        //When
51
+        List<Card> s = hand.getCards();
52
+
53
+        Assert.assertNotNull(s);
54
+        Assert.assertTrue(s.size() == 2);
55
+
56
+
57
+
58
+
59
+    }
60
+
61
+    @Test
62
+    public void testContains(){
63
+        //Given
64
+        Hand hand = new Hand();
65
+        Card card1 = new Card(Suit.Diamond, Rank.Ace);
66
+        hand.add(card1);
67
+
68
+        //When
69
+        Boolean b = hand.contains(card1);
70
+
71
+        //Then
72
+        Assert.assertTrue(b);
73
+    }
74
+
75
+
76
+}

+ 0
- 83
src/test/java/io/zipcoder/casino/PlayerTest.java 파일 보기

@@ -1,83 +0,0 @@
1
-package io.zipcoder.casino;
2
-
3
-import io.zipcoder.casino.*;
4
-import org.junit.Assert;
5
-import org.junit.Before;
6
-import org.junit.Test;
7
-
8
-import java.util.List;
9
-
10
-public class PlayerTest {
11
-
12
-    Player xzavia;
13
-
14
-    @Before
15
-    public void setup(){
16
-
17
-        xzavia = new Player("Xzavia", 10_000.00);
18
-    }
19
-
20
-    @Test
21
-    public void addCardTest() {
22
-
23
-        //Given
24
-
25
-        Card expected = new Card(Suit.SPADE, Rank.Jack);
26
-
27
-        //When
28
-        xzavia.addCard(expected);
29
-        Card actual = xzavia.getHand().getCards().get(0);
30
-
31
-        //Then
32
-        Assert.assertEquals(expected, actual);
33
-    }
34
-
35
-    @Test
36
-
37
-    public void getHandTest() {
38
-
39
-        //Given
40
-        Card expected = new Card(Suit.SPADE, Rank.Jack);
41
-        Hand hand = new Hand();
42
-
43
-        //When
44
-        hand.add(expected);
45
-        List<Card> cards = hand.getCards();
46
-
47
-        //Then
48
-        Assert.assertTrue(cards.contains(expected));
49
-
50
-    }
51
-
52
-    @Test
53
-
54
-    public void setHandTest() {
55
-
56
-        //Given
57
-        Card expected = new Card(Suit.SPADE, Rank.Jack);
58
-
59
-        Hand hand = new Hand();
60
-
61
-        //When
62
-
63
-
64
-        //Then
65
-
66
-    }
67
-
68
-    @Test
69
-    public void getWalletAmountAfterWager(){
70
-
71
-        //When
72
-        xzavia.setWager(1000.00);
73
-
74
-        double expected = 9000.00;
75
-
76
-        double actual = xzavia.getWalletAmount();
77
-
78
-        //Then
79
-        Assert.assertEquals(expected,actual,0);
80
-
81
-
82
-    }
83
-}