diff --git a/src/main/scala/combinations/PokerCombination.scala b/src/main/scala/combinations/PokerCombination.scala new file mode 100644 index 0000000..90df513 --- /dev/null +++ b/src/main/scala/combinations/PokerCombination.scala @@ -0,0 +1,32 @@ +package combinations + +import cards._ +import score._ + +/** + * Represents a generic poker combination. + * Each combination must define its name, score, and a method + * to determine if a list of cards satisfies the condition of the combination. + */ +trait PokerCombination { + + /** + * The name of the poker combination (e.g., "Flush", "FullHouse"). + */ + def name: String + + /** + * The score associated with this combination. + * This includes both the number of chips and a multiplier. + */ + def score: Score + + /** + * Verifies whether a given list of cards satisfies this poker combination. + * The list can contain between 1 and 5 cards. + * + * @param cards the list of cards to evaluate + * @return true if the combination is met, false otherwise + */ + def verify(cards: List[Card]): Boolean +} diff --git a/src/test/scala/combinations/FlushTest.scala b/src/test/scala/combinations/FlushTest.scala index 496cfc0..5b3b049 100644 --- a/src/test/scala/combinations/FlushTest.scala +++ b/src/test/scala/combinations/FlushTest.scala @@ -2,24 +2,33 @@ package combinations import munit.FunSuite import cards._ -import score.Score + class FlushTest extends FunSuite { - test("Flush reconoce una mano válida") { + test("Flush recognizes a valid hand") { val hand = List( - // TODO: cinco cartas del mismo palo, sin orden + Card(Two, Hearts), + Card(Five, Hearts), + Card(Seven, Hearts), + Card(Jack, Hearts), + Card(Queen, Hearts) ) - val combinacion = new Flush() - assert(combinacion.verifica(hand)) - assertEquals(combinacion.score, Score(35, 4)) + val combination = Flush() + assert(combination.verify(hand)) + assertEquals(combination.score.chips, 35) + assertEquals(combination.score.multiplier, 4) } - test("Flush no reconoce una mano inválida") { + test("Flush does not recognize an invalid hand") { val hand = List( - // TODO: cartas que no cumplan la condición + Card(Two, Hearts), + Card(Five, Spades), + Card(Seven, Hearts), + Card(Jack, Hearts), + Card(Queen, Hearts) ) - val combinacion = new Flush() - assert(!combinacion.verifica(hand)) + val combination = Flush() + assert(!combination.verify(hand)) } } diff --git a/src/test/scala/combinations/FourOfAKindTest.scala b/src/test/scala/combinations/FourOfAKindTest.scala index f588fd8..a590746 100644 --- a/src/test/scala/combinations/FourOfAKindTest.scala +++ b/src/test/scala/combinations/FourOfAKindTest.scala @@ -2,24 +2,32 @@ package combinations import munit.FunSuite import cards._ -import score.Score class FourOfAKindTest extends FunSuite { - test("FourOfAKind reconoce una mano válida") { + test("Poker recognizes a valid hand") { val hand = List( - // TODO: cuatro cartas del mismo rango + Card(Two, Hearts), + Card(Two, Hearts), + Card(Two, Hearts), + Card(Two, Hearts), + Card(Queen, Hearts) ) - val combinacion = new FourOfAKind() - assert(combinacion.verifica(hand)) - assertEquals(combinacion.score, Score(60, 7)) + val combination = FourOfAKind() + assert(combination.verify(hand)) + assertEquals(combination.score.chips, 60) + assertEquals(combination.score.multiplier, 7) } - test("FourOfAKind no reconoce una mano inválida") { + test("Poker does not recognize an invalid hand") { val hand = List( - // TODO: cartas que no cumplan la condición + Card(Two, Hearts), + Card(Five, Spades), + Card(Seven, Hearts), + Card(Jack, Hearts), + Card(Queen, Hearts) ) - val combinacion = new FourOfAKind() - assert(!combinacion.verifica(hand)) + val combination = FourOfAKind() + assert(!combination.verify(hand)) } } diff --git a/src/test/scala/combinations/FullHouseTest.scala b/src/test/scala/combinations/FullHouseTest.scala index 6ff16dc..860ccdc 100644 --- a/src/test/scala/combinations/FullHouseTest.scala +++ b/src/test/scala/combinations/FullHouseTest.scala @@ -2,24 +2,32 @@ package combinations import munit.FunSuite import cards._ -import score.Score class FullHouseTest extends FunSuite { - test("FullHouse reconoce una mano válida") { + test("Full house recognizes a valid hand") { val hand = List( - // TODO: tres cartas de un rango y dos de otro + Card(Two, Hearts), + Card(Two, Hearts), + Card(Queen, Hearts), + Card(Queen, Hearts), + Card(Queen, Hearts) ) - val combinacion = new FullHouse() - assert(combinacion.verifica(hand)) - assertEquals(combinacion.score, Score(40, 4)) + val combination = FullHouse() + assert(combination.verify(hand)) + assertEquals(combination.score.chips, 40) + assertEquals(combination.score.multiplier, 4) } - test("FullHouse no reconoce una mano inválida") { + test("Full house does not recognize an invalid hand") { val hand = List( - // TODO: cartas que no cumplan la condición + Card(Two, Hearts), + Card(Five, Spades), + Card(Seven, Hearts), + Card(Jack, Hearts), + Card(Queen, Hearts) ) - val combinacion = new FullHouse() - assert(!combinacion.verifica(hand)) + val combination = FullHouse() + assert(!combination.verify(hand)) } } diff --git a/src/test/scala/combinations/HighCardTest.scala b/src/test/scala/combinations/HighCardTest.scala index a9866d3..4a68bb0 100644 --- a/src/test/scala/combinations/HighCardTest.scala +++ b/src/test/scala/combinations/HighCardTest.scala @@ -2,24 +2,27 @@ package combinations import munit.FunSuite import cards._ -import score.Score class HighCardTest extends FunSuite { - test("HighCard reconoce una mano válida") { + test("HighCard accepts any hand") { val hand = List( - // TODO: sin pares, sin color, sin escalera + Card(Two, Hearts), + Card(Four, Clubs), + Card(Seven, Diamonds), + Card(Jack, Spades), + Card(Ace, Hearts) ) - val combinacion = new HighCard() - assert(combinacion.verifica(hand)) - assertEquals(combinacion.score, Score(5, 1)) + + val combination = HighCard() + assert(combination.verify(hand)) + assertEquals(combination.score.chips, 5) + assertEquals(combination.score.multiplier, 1) } - test("HighCard no reconoce una mano inválida") { - val hand = List( - // TODO: cartas que no cumplan la condición - ) - val combinacion = new HighCard() - assert(!combinacion.verifica(hand)) + test("HighCard accepts even a single card") { + val hand = List(Card(King, Clubs)) + val combination = HighCard() + assert(combination.verify(hand)) } } diff --git a/src/test/scala/combinations/PairTest.scala b/src/test/scala/combinations/PairTest.scala index 9c509eb..af969d4 100644 --- a/src/test/scala/combinations/PairTest.scala +++ b/src/test/scala/combinations/PairTest.scala @@ -2,24 +2,32 @@ package combinations import munit.FunSuite import cards._ -import score.Score class PairTest extends FunSuite { - test("Pair reconoce una mano válida") { + test("Pair recognizes a valid hand") { val hand = List( - // TODO: un par + Card(Two, Hearts), + Card(Two, Hearts), + Card(Five, Hearts), + Card(Six, Hearts), + Card(Queen, Hearts) ) - val combinacion = new Pair() - assert(combinacion.verifica(hand)) - assertEquals(combinacion.score, Score(10, 2)) + val combination = Pair() + assert(combination.verify(hand)) + assertEquals(combination.score.chips, 10) + assertEquals(combination.score.multiplier, 2) } - test("Pair no reconoce una mano inválida") { + test("Pair does not recognize an invalid hand") { val hand = List( - // TODO: cartas que no cumplan la condición + Card(Two, Hearts), + Card(Five, Spades), + Card(Seven, Hearts), + Card(Jack, Hearts), + Card(Queen, Hearts) ) - val combinacion = new Pair() - assert(!combinacion.verifica(hand)) + val combination = Pair() + assert(!combination.verify(hand)) } } diff --git a/src/test/scala/combinations/StraightFlushTest.scala b/src/test/scala/combinations/StraightFlushTest.scala index 2964f6f..29b17e9 100644 --- a/src/test/scala/combinations/StraightFlushTest.scala +++ b/src/test/scala/combinations/StraightFlushTest.scala @@ -2,24 +2,33 @@ package combinations import munit.FunSuite import cards._ -import score.Score +import score._ class StraightFlushTest extends FunSuite { - test("StraightFlush reconoce una mano válida") { + test("StraightFlush recognizes a valid hand") { val hand = List( - // TODO: cinco cartas consecutivas del mismo palo + Card(Two, Hearts), + Card(Three, Hearts), + Card(Four, Hearts), + Card(Five, Hearts), + Card(Six, Hearts) ) - val combinacion = new StraightFlush() - assert(combinacion.verifica(hand)) - assertEquals(combinacion.score, Score(100, 8)) + val combination = new StraightFlush() + assert(combination.verify(hand)) + assertEquals(combination.score.chips, 100) + assertEquals(combination.score.multiplier, 8) } - test("StraightFlush no reconoce una mano inválida") { + test("StraightFlush does not recognize an invalid hand") { val hand = List( - // TODO: cartas que no cumplan la condición + Card(Two, Hearts), + Card(Three, Hearts), + Card(Four, Hearts), + Card(Five, Hearts), + Card(Six, Spades) ) - val combinacion = new StraightFlush() - assert(!combinacion.verifica(hand)) + val combination = new StraightFlush() + assert(!combination.verify(hand)) } } diff --git a/src/test/scala/combinations/StraightTest.scala b/src/test/scala/combinations/StraightTest.scala index a9f591f..0cdd8ff 100644 --- a/src/test/scala/combinations/StraightTest.scala +++ b/src/test/scala/combinations/StraightTest.scala @@ -2,24 +2,33 @@ package combinations import munit.FunSuite import cards._ -import score.Score +import score._ class StraightTest extends FunSuite { - test("Straight reconoce una mano válida") { + test("Straight recognizes a valid hand") { val hand = List( - // TODO: cinco cartas consecutivas de cualquier palo + Card(Two, Hearts), + Card(Three, Clubs), + Card(Four, Diamonds), + Card(Five, Spades), + Card(Six, Hearts) ) - val combinacion = new Straight() - assert(combinacion.verifica(hand)) - assertEquals(combinacion.score, Score(30, 4)) + val combination = new Straight() + assert(combination.verify(hand)) + assertEquals(combination.score.chips, 30) + assertEquals(combination.score.multiplier, 4) } - test("Straight no reconoce una mano inválida") { + test("Straight does not recognize an invalid hand") { val hand = List( - // TODO: cartas que no cumplan la condición + Card(Two, Hearts), + Card(Three, Clubs), + Card(Five, Diamonds), + Card(Seven, Spades), + Card(Nine, Hearts) ) - val combinacion = new Straight() - assert(!combinacion.verifica(hand)) + val combination = new Straight() + assert(!combination.verify(hand)) } } diff --git a/src/test/scala/combinations/ThreeOfAKindTest.scala b/src/test/scala/combinations/ThreeOfAKindTest.scala index 2aab59f..632785a 100644 --- a/src/test/scala/combinations/ThreeOfAKindTest.scala +++ b/src/test/scala/combinations/ThreeOfAKindTest.scala @@ -2,24 +2,33 @@ package combinations import munit.FunSuite import cards._ -import score.Score +import score._ class ThreeOfAKindTest extends FunSuite { - test("ThreeOfAKind reconoce una mano válida") { + test("ThreeOfAKind recognizes a valid hand") { val hand = List( - // TODO: tres cartas del mismo rango + Card(Five, Hearts), + Card(Five, Spades), + Card(Five, Diamonds), + Card(Seven, Hearts), + Card(Nine, Spades) ) - val combinacion = new ThreeOfAKind() - assert(combinacion.verifica(hand)) - assertEquals(combinacion.score, Score(30, 3)) + val combination = new ThreeOfAKind() + assert(combination.verify(hand)) + assertEquals(combination.score.chips, 30) + assertEquals(combination.score.multiplier, 3) } - test("ThreeOfAKind no reconoce una mano inválida") { + test("ThreeOfAKind does not recognize an invalid hand") { val hand = List( - // TODO: cartas que no cumplan la condición + Card(Five, Hearts), + Card(Five, Spades), + Card(Six, Diamonds), + Card(Seven, Hearts), + Card(Nine, Spades) ) - val combinacion = new ThreeOfAKind() - assert(!combinacion.verifica(hand)) + val combination = new ThreeOfAKind() + assert(!combination.verify(hand)) } } diff --git a/src/test/scala/combinations/TwoPairTest.scala b/src/test/scala/combinations/TwoPairTest.scala index a11ba6f..c602bdb 100644 --- a/src/test/scala/combinations/TwoPairTest.scala +++ b/src/test/scala/combinations/TwoPairTest.scala @@ -2,24 +2,33 @@ package combinations import munit.FunSuite import cards._ -import score.Score +import score._ class TwoPairTest extends FunSuite { - test("TwoPair reconoce una mano válida") { + test("TwoPair recognizes a valid hand") { val hand = List( - // TODO: dos pares de distinto rango + Card(Five, Hearts), + Card(Five, Spades), + Card(Seven, Diamonds), + Card(Seven, Clubs), + Card(Nine, Spades) ) - val combinacion = new TwoPair() - assert(combinacion.verifica(hand)) - assertEquals(combinacion.score, Score(20, 2)) + val combination = new TwoPair() + assert(combination.verify(hand)) + assertEquals(combination.score.chips, 20) + assertEquals(combination.score.multiplier, 2) } - test("TwoPair no reconoce una mano inválida") { + test("TwoPair does not recognize an invalid hand") { val hand = List( - // TODO: cartas que no cumplan la condición + Card(Five, Hearts), + Card(Five, Spades), + Card(Six, Diamonds), + Card(Seven, Hearts), + Card(Nine, Spades) ) - val combinacion = new TwoPair() - assert(!combinacion.verifica(hand)) + val combination = new TwoPair() + assert(!combination.verify(hand)) } } diff --git a/src/test/scala/hand/HandTest.scala b/src/test/scala/hand/HandTest.scala index 42e8417..2367d88 100644 --- a/src/test/scala/hand/HandTest.scala +++ b/src/test/scala/hand/HandTest.scala @@ -1,11 +1,28 @@ package hand import munit.FunSuite -import cards.{Card, Ace, Hearts} -import jokers.Joker +import cards._ +import jokers._ class HandTest extends FunSuite { + test("Hand toString returns a string with cards and jokers") { + val hand = new Hand() + hand.addCard(new Card(Five, Hearts)) + hand.addCard(new Card(King, Spades)) + + hand.addJoker(new Joker("Devious Joker")) + hand.addJoker(new Joker("Greedy Joker")) + + val result = hand.toString + + assert(result.contains("cards")) + assert(result.contains("jokers")) + assert(result.contains("Five")) + assert(result.contains("King")) + assert(result.contains("Devious Joker")) + assert(result.contains("Greedy Joker")) + } test("addCard should add a card to the hand") { val hand = new Hand val card = new Card(Ace, Hearts)