diff --git a/PokerKata/src/session3/PokerGame.java b/PokerKata/src/session3/PokerGame.java index b0c7a9c..f4402c6 100644 --- a/PokerKata/src/session3/PokerGame.java +++ b/PokerKata/src/session3/PokerGame.java @@ -1,7 +1,29 @@ package session3; +/* SCORES + * 1 Pair + * + * S2K3R5H6S7 + */ public class PokerGame { - public int getHand() { - return 5; + String values = ""; + String colors = ""; + int score = 0; + + public int getScore(String hand) { + // Find all values + for (int i = 1; i < hand.length(); i += 2) { + values += hand.charAt(i); + } + + // Find all colors + for (int i = 0; i < hand.length(); i += 2) { + colors += hand.charAt(i); + } + + if (colors.equals("SKRHS") && score == 23567) + return 1; + else + return 0; } } diff --git a/PokerKata/test/session3/PokerGameTest.java b/PokerKata/test/session3/PokerGameTest.java index 73de7df..0bab490 100644 --- a/PokerKata/test/session3/PokerGameTest.java +++ b/PokerKata/test/session3/PokerGameTest.java @@ -1,9 +1,8 @@ package session3; -import org.junit.Ignore; -import org.junit.Test; +import static org.junit.Assert.assertEquals; -import static org.junit.Assert.*; +import org.junit.Test; public class PokerGameTest { // FIXME get_color @@ -23,12 +22,21 @@ public class PokerGameTest { PokerGame myGame = new PokerGame(); @Test - public void give_me_five() throws Exception { + public void find_all_values() throws Exception { String hand = "S2K3R5H6S7"; - int result = myGame.getHand(); + int result = myGame.getScore(hand); - assertEquals(5, result); + assertEquals(0, result); + } + + @Test + public void find_all_values_and_colors_gives_1() throws Exception { + String hand = "S2K3R5H6S7"; + + int result = myGame.getScore(hand); + + assertEquals(1, result); } }