Skip to content

Commit

Permalink
#16 HanRankingServiceTest módosítása (GameState kiszedése a tesztekbő…
Browse files Browse the repository at this point in the history
…l, ez által garantálva a mobilitást)
  • Loading branch information
unknown authored and unknown committed Apr 22, 2015
1 parent 5528f9f commit dd48f8a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 41 deletions.
20 changes: 8 additions & 12 deletions src/main/java/org/leanpoker/player/checkCards/CheckResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@
public class CheckResult {

private HandRank hand;
private String highRank1;
private String highRank2;
private int myCardsOfHand;
private final Collection<Card> cards;
private RankInfo rankInfo;

public CheckResult(HandRank hand, List<Card> cards, String highRank1, String highRank2, int myCardsOfHand) {
this.hand = hand;
this.highRank1 = highRank1;
this.highRank2 = highRank2;
this.myCardsOfHand = myCardsOfHand;
rankInfo=new RankInfo(highRank1,highRank2,myCardsOfHand);
this.cards = cards;
}

Expand All @@ -34,19 +30,19 @@ public Collection<Card> getCards() {
}

public String getHighRank1() {
return highRank1;
return rankInfo.getHighRank1();
}

public String getHighRank2() {
return highRank2;
return rankInfo.getHighRank2();
}

public int getMyCardsOfHand() {
return myCardsOfHand;
return rankInfo.getMyCardsOfHand();
}

@Override
public String toString() {
return "CheckResult{" + "hand=" + hand + ", highRank1=" + highRank1 + ", highRank2=" + highRank2 + '}';
public RankInfo getRankInfo() {
return rankInfo;
}

}
39 changes: 39 additions & 0 deletions src/main/java/org/leanpoker/player/checkCards/RankInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

package org.leanpoker.player.checkCards;

/**
*
* @author poker10
*/

public class RankInfo {
private String highRank1;
private String highRank2;
private int myCardsOfHand;

public String getHighRank1() {
return highRank1;
}

public String getHighRank2() {
return highRank2;
}

public int getMyCardsOfHand() {
return myCardsOfHand;
}


public RankInfo(String highRank1, String highRank2, int myCardsOfHand) {
this.highRank1 = highRank1;
this.highRank2 = highRank2;
this.myCardsOfHand = myCardsOfHand;
}


}
44 changes: 15 additions & 29 deletions src/test/java/com/wcs/poker/hand/HandRankingServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,11 @@
public class HandRankingServiceTest {

private HandRankingService handRankingService;
private GameState gameState;
private Player player;
private HandChecker handChecker;

@Before
public void setUp() {
handRankingService = new HandRankingService();
gameState = new GameState(10, 320, 400, 241, 0, 7, 0);
player = new Player(1, "Albert", "active", "Default random player", 1590, 80);
handChecker = new HandChecker();
}

Expand All @@ -55,89 +51,79 @@ public void testNotMoreThenSevenCardsAreAccepted() {

@Test
public void testEvaulateRoyalFlushHand() throws Exception {
setCards(loadCards("royalFlushHandTestDataSet.json"));
CheckResult result = handChecker.getResult(gameState);
CheckResult result = handChecker.getResult(modifiedCards(loadCards("royalFlushHandTestDataSet.json")));

assertThat(result.getHand(), Is.is(HandRank.ROYAL_FLUSH));
assertThat(result.getCards(), Is.is((Collection) loadCards("royalFlushHand.json")));
}

@Test
public void testEvaulateStraightFlush() throws Exception {
setCards(loadCards("straightFlushHandTestDataSet.json"));
CheckResult result = handChecker.getResult(gameState);

CheckResult result = handChecker.getResult(modifiedCards(loadCards("straightFlushHandTestDataSet.json")));

assertThat(result.getHand(), Is.is(HandRank.STRAIGH_FLUSH));
assertThat(result.getCards(), Is.is((Collection) loadCards("straightFlush.json")));
}

@Test
public void testEvaulateFourOfAKind() throws Exception {
setCards(loadCards("fourOfAKindTestDataSet.json"));
CheckResult result = handChecker.getResult(gameState);
CheckResult result = handChecker.getResult(modifiedCards(loadCards("fourOfAKindTestDataSet.json")));

assertThat(result.getHand(), Is.is(HandRank.POKER));
assertThat(result.getCards(), Is.is((Collection) loadCards("fourOfAKindHand.json")));
}

@Test
public void testEvaulateFullHouse() throws Exception {
setCards(loadCards("fullHouseTestDataSet.json"));
CheckResult result = handChecker.getResult(gameState);
CheckResult result = handChecker.getResult(modifiedCards(loadCards("fullHouseTestDataSet.json")));

assertThat(result.getHand(), Is.is(HandRank.FULL));
assertThat(result.getCards(), Is.is((Collection) loadCards("fullHouseHand.json")));
}

@Test
public void testEvaulateFlush() throws Exception {
setCards(loadCards("flushTestDataSet.json"));
CheckResult result = handChecker.getResult(gameState);
CheckResult result = handChecker.getResult(modifiedCards(loadCards("flushTestDataSet.json")));

assertThat(result.getHand(), Is.is(HandRank.FLUSH));
assertThat(result.getCards(), Is.is((Collection) loadCards("flushHand.json")));
}

@Test
public void testEvaulateStraight() throws Exception {
setCards(loadCards("straightTestDataSet.json"));
CheckResult result = handChecker.getResult(gameState);
CheckResult result = handChecker.getResult(modifiedCards(loadCards("straightTestDataSet.json")));

assertThat(result.getHand(), Is.is(HandRank.STRAIGHT));
assertThat(result.getCards(), Is.is((Collection) loadCards("straightHand.json")));
}

@Test
public void testEvaulateThreeOfAKind() throws Exception {
setCards(loadCards("threeOfAKindTestDataSet.json"));
CheckResult result = handChecker.getResult(gameState);
CheckResult result = handChecker.getResult(modifiedCards(loadCards("threeOfAKindTestDataSet.json")));

assertThat(result.getHand(), Is.is(HandRank.DRILL));
assertThat(result.getCards(), Is.is((Collection) loadCards("threeOfAKindHand.json")));
}

@Test
public void testEvaulateTwoPairs() throws Exception {
setCards(loadCards("twoPairsTestDataSet.json"));
CheckResult result = handChecker.getResult(gameState);
CheckResult result = handChecker.getResult(modifiedCards(loadCards("twoPairsTestDataSet.json")));

assertThat(result.getHand(), Is.is(HandRank.TWO_PAIR));
assertThat(result.getCards(), Is.is((Collection) loadCards("twoPairsHand.json")));
}

@Test
public void testEvaulatePair() throws Exception {
setCards(loadCards("pairTestDataSet.json"));
CheckResult result = handChecker.getResult(gameState);
CheckResult result = handChecker.getResult(modifiedCards(loadCards("pairTestDataSet.json")));

assertThat(result.getHand(), Is.is(HandRank.ONE_PAIR));
assertThat(result.getCards(), Is.is((Collection) loadCards("pairHand.json")));
}

@Test
public void testEvaulateHighCard() throws Exception {
setCards(loadCards("highCardDataSet.json"));
CheckResult result = handChecker.getResult(gameState);
CheckResult result = handChecker.getResult(modifiedCards(loadCards("highCardDataSet.json")));

assertThat(result.getHand(), Is.is(HandRank.HIGH_CARD));
assertThat(result.getCards(),Is.is((Collection) loadCards("highCardHand.json")));
Expand All @@ -152,9 +138,9 @@ private List<Card> loadCards(String name) throws IOException {
return new Gson().fromJson(json, cardListType);
}

private void setCards(List<Card> cards) {
player.setHoleCards(cards.subList(0, 2));
gameState.setPlayers(Arrays.asList(player));
gameState.setCommunityCards(cards.subList(2, cards.size()));
private List<Card> modifiedCards(List<Card> cards) {
cards.get(0).setInMyHand(true);
cards.get(1).setInMyHand(true);
return cards;
}
}

0 comments on commit dd48f8a

Please sign in to comment.