feat: implement poker combinations and tests with custom logic
This commit is contained in:
32
src/main/scala/combinations/PokerCombination.scala
Normal file
32
src/main/scala/combinations/PokerCombination.scala
Normal file
@@ -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
|
||||||
|
}
|
||||||
@@ -2,24 +2,33 @@ package combinations
|
|||||||
|
|
||||||
import munit.FunSuite
|
import munit.FunSuite
|
||||||
import cards._
|
import cards._
|
||||||
import score.Score
|
|
||||||
|
|
||||||
class FlushTest extends FunSuite {
|
class FlushTest extends FunSuite {
|
||||||
|
|
||||||
test("Flush reconoce una mano válida") {
|
test("Flush recognizes a valid hand") {
|
||||||
val hand = List(
|
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()
|
val combination = Flush()
|
||||||
assert(combinacion.verifica(hand))
|
assert(combination.verify(hand))
|
||||||
assertEquals(combinacion.score, Score(35, 4))
|
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(
|
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()
|
val combination = Flush()
|
||||||
assert(!combinacion.verifica(hand))
|
assert(!combination.verify(hand))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,24 +2,32 @@ package combinations
|
|||||||
|
|
||||||
import munit.FunSuite
|
import munit.FunSuite
|
||||||
import cards._
|
import cards._
|
||||||
import score.Score
|
|
||||||
|
|
||||||
class FourOfAKindTest extends FunSuite {
|
class FourOfAKindTest extends FunSuite {
|
||||||
|
|
||||||
test("FourOfAKind reconoce una mano válida") {
|
test("Poker recognizes a valid hand") {
|
||||||
val hand = List(
|
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()
|
val combination = FourOfAKind()
|
||||||
assert(combinacion.verifica(hand))
|
assert(combination.verify(hand))
|
||||||
assertEquals(combinacion.score, Score(60, 7))
|
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(
|
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()
|
val combination = FourOfAKind()
|
||||||
assert(!combinacion.verifica(hand))
|
assert(!combination.verify(hand))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,24 +2,32 @@ package combinations
|
|||||||
|
|
||||||
import munit.FunSuite
|
import munit.FunSuite
|
||||||
import cards._
|
import cards._
|
||||||
import score.Score
|
|
||||||
|
|
||||||
class FullHouseTest extends FunSuite {
|
class FullHouseTest extends FunSuite {
|
||||||
|
|
||||||
test("FullHouse reconoce una mano válida") {
|
test("Full house recognizes a valid hand") {
|
||||||
val hand = List(
|
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()
|
val combination = FullHouse()
|
||||||
assert(combinacion.verifica(hand))
|
assert(combination.verify(hand))
|
||||||
assertEquals(combinacion.score, Score(40, 4))
|
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(
|
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()
|
val combination = FullHouse()
|
||||||
assert(!combinacion.verifica(hand))
|
assert(!combination.verify(hand))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,24 +2,27 @@ package combinations
|
|||||||
|
|
||||||
import munit.FunSuite
|
import munit.FunSuite
|
||||||
import cards._
|
import cards._
|
||||||
import score.Score
|
|
||||||
|
|
||||||
class HighCardTest extends FunSuite {
|
class HighCardTest extends FunSuite {
|
||||||
|
|
||||||
test("HighCard reconoce una mano válida") {
|
test("HighCard accepts any hand") {
|
||||||
val hand = List(
|
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))
|
val combination = HighCard()
|
||||||
assertEquals(combinacion.score, Score(5, 1))
|
assert(combination.verify(hand))
|
||||||
|
assertEquals(combination.score.chips, 5)
|
||||||
|
assertEquals(combination.score.multiplier, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
test("HighCard no reconoce una mano inválida") {
|
test("HighCard accepts even a single card") {
|
||||||
val hand = List(
|
val hand = List(Card(King, Clubs))
|
||||||
// TODO: cartas que no cumplan la condición
|
val combination = HighCard()
|
||||||
)
|
assert(combination.verify(hand))
|
||||||
val combinacion = new HighCard()
|
|
||||||
assert(!combinacion.verifica(hand))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,24 +2,32 @@ package combinations
|
|||||||
|
|
||||||
import munit.FunSuite
|
import munit.FunSuite
|
||||||
import cards._
|
import cards._
|
||||||
import score.Score
|
|
||||||
|
|
||||||
class PairTest extends FunSuite {
|
class PairTest extends FunSuite {
|
||||||
|
|
||||||
test("Pair reconoce una mano válida") {
|
test("Pair recognizes a valid hand") {
|
||||||
val hand = List(
|
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()
|
val combination = Pair()
|
||||||
assert(combinacion.verifica(hand))
|
assert(combination.verify(hand))
|
||||||
assertEquals(combinacion.score, Score(10, 2))
|
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(
|
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()
|
val combination = Pair()
|
||||||
assert(!combinacion.verifica(hand))
|
assert(!combination.verify(hand))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,24 +2,33 @@ package combinations
|
|||||||
|
|
||||||
import munit.FunSuite
|
import munit.FunSuite
|
||||||
import cards._
|
import cards._
|
||||||
import score.Score
|
import score._
|
||||||
|
|
||||||
class StraightFlushTest extends FunSuite {
|
class StraightFlushTest extends FunSuite {
|
||||||
|
|
||||||
test("StraightFlush reconoce una mano válida") {
|
test("StraightFlush recognizes a valid hand") {
|
||||||
val hand = List(
|
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()
|
val combination = new StraightFlush()
|
||||||
assert(combinacion.verifica(hand))
|
assert(combination.verify(hand))
|
||||||
assertEquals(combinacion.score, Score(100, 8))
|
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(
|
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()
|
val combination = new StraightFlush()
|
||||||
assert(!combinacion.verifica(hand))
|
assert(!combination.verify(hand))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,24 +2,33 @@ package combinations
|
|||||||
|
|
||||||
import munit.FunSuite
|
import munit.FunSuite
|
||||||
import cards._
|
import cards._
|
||||||
import score.Score
|
import score._
|
||||||
|
|
||||||
class StraightTest extends FunSuite {
|
class StraightTest extends FunSuite {
|
||||||
|
|
||||||
test("Straight reconoce una mano válida") {
|
test("Straight recognizes a valid hand") {
|
||||||
val hand = List(
|
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()
|
val combination = new Straight()
|
||||||
assert(combinacion.verifica(hand))
|
assert(combination.verify(hand))
|
||||||
assertEquals(combinacion.score, Score(30, 4))
|
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(
|
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()
|
val combination = new Straight()
|
||||||
assert(!combinacion.verifica(hand))
|
assert(!combination.verify(hand))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,24 +2,33 @@ package combinations
|
|||||||
|
|
||||||
import munit.FunSuite
|
import munit.FunSuite
|
||||||
import cards._
|
import cards._
|
||||||
import score.Score
|
import score._
|
||||||
|
|
||||||
class ThreeOfAKindTest extends FunSuite {
|
class ThreeOfAKindTest extends FunSuite {
|
||||||
|
|
||||||
test("ThreeOfAKind reconoce una mano válida") {
|
test("ThreeOfAKind recognizes a valid hand") {
|
||||||
val hand = List(
|
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()
|
val combination = new ThreeOfAKind()
|
||||||
assert(combinacion.verifica(hand))
|
assert(combination.verify(hand))
|
||||||
assertEquals(combinacion.score, Score(30, 3))
|
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(
|
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()
|
val combination = new ThreeOfAKind()
|
||||||
assert(!combinacion.verifica(hand))
|
assert(!combination.verify(hand))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,24 +2,33 @@ package combinations
|
|||||||
|
|
||||||
import munit.FunSuite
|
import munit.FunSuite
|
||||||
import cards._
|
import cards._
|
||||||
import score.Score
|
import score._
|
||||||
|
|
||||||
class TwoPairTest extends FunSuite {
|
class TwoPairTest extends FunSuite {
|
||||||
|
|
||||||
test("TwoPair reconoce una mano válida") {
|
test("TwoPair recognizes a valid hand") {
|
||||||
val hand = List(
|
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()
|
val combination = new TwoPair()
|
||||||
assert(combinacion.verifica(hand))
|
assert(combination.verify(hand))
|
||||||
assertEquals(combinacion.score, Score(20, 2))
|
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(
|
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()
|
val combination = new TwoPair()
|
||||||
assert(!combinacion.verifica(hand))
|
assert(!combination.verify(hand))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,28 @@
|
|||||||
package hand
|
package hand
|
||||||
|
|
||||||
import munit.FunSuite
|
import munit.FunSuite
|
||||||
import cards.{Card, Ace, Hearts}
|
import cards._
|
||||||
import jokers.Joker
|
import jokers._
|
||||||
|
|
||||||
class HandTest extends FunSuite {
|
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") {
|
test("addCard should add a card to the hand") {
|
||||||
val hand = new Hand
|
val hand = new Hand
|
||||||
val card = new Card(Ace, Hearts)
|
val card = new Card(Ace, Hearts)
|
||||||
|
|||||||
Reference in New Issue
Block a user