fix: ensure HighCard only applies when no other combination matches

This commit is contained in:
2025-04-21 22:08:11 -04:00
parent e66488d814
commit b911b1e648
2 changed files with 19 additions and 9 deletions

View File

@@ -26,10 +26,15 @@ It includes classes for `Card`, `Rank`, `Suit`, `Joker`, `Hand`, and `Score`, ea
- `hand/` → A hand containing a set of cards and jokers - `hand/` → A hand containing a set of cards and jokers
- `score/` → Score with chips and multiplier - `score/` → Score with chips and multiplier
## Testing
All tests are written using [MUnit](https://scalameta.org/munit/) and located under `src/test/scala`. ## Task 1 - Partial Delivery 2
The project achieves **90%+ test coverage** using `sbt-scoverage`.
This delivery defines the 9 poker combinations as classes implementing the `PokerCombination` trait.
Each class includes its name, a `Score`, and a `verify(cards: List[Card])` method to check if a hand matches the combination.
All combinations are tested with valid and invalid cases using MUnit.
The logic uses explicit loops and avoids higher-order functions, as required.
--- ---

View File

@@ -5,7 +5,7 @@ import cards._
class HighCardTest extends FunSuite { class HighCardTest extends FunSuite {
test("HighCard accepts any hand") { test("HighCard returns true only when no other combination applies") {
val hand = List( val hand = List(
Card(Two, Hearts), Card(Two, Hearts),
Card(Four, Clubs), Card(Four, Clubs),
@@ -13,16 +13,21 @@ class HighCardTest extends FunSuite {
Card(Jack, Spades), Card(Jack, Spades),
Card(Ace, Hearts) Card(Ace, Hearts)
) )
val combination = HighCard() val combination = HighCard()
assert(combination.verify(hand)) assert(combination.verify(hand)) // No other combination applies
assertEquals(combination.score.chips, 5) assertEquals(combination.score.chips, 5)
assertEquals(combination.score.multiplier, 1) assertEquals(combination.score.multiplier, 1)
} }
test("HighCard accepts even a single card") { test("HighCard returns false when hand has a pair") {
val hand = List(Card(King, Clubs)) val hand = List(
Card(Two, Hearts),
Card(Two, Spades), // pair
Card(Four, Clubs),
Card(Six, Diamonds),
Card(Nine, Hearts)
)
val combination = HighCard() val combination = HighCard()
assert(combination.verify(hand)) assert(!combination.verify(hand)) // Because it's a pair
} }
} }