From b911b1e648882958a635ed5ac72385e0dd434b5a Mon Sep 17 00:00:00 2001 From: Giarf Date: Mon, 21 Apr 2025 22:08:11 -0400 Subject: [PATCH] fix: ensure HighCard only applies when no other combination matches --- README.md | 11 ++++++++--- src/test/scala/combinations/HighCardTest.scala | 17 +++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 3e9018f..a241a97 100644 --- a/README.md +++ b/README.md @@ -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 - `score/` → Score with chips and multiplier -## Testing -All tests are written using [MUnit](https://scalameta.org/munit/) and located under `src/test/scala`. -The project achieves **90%+ test coverage** using `sbt-scoverage`. +## Task 1 - Partial Delivery 2 + +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. + --- diff --git a/src/test/scala/combinations/HighCardTest.scala b/src/test/scala/combinations/HighCardTest.scala index 4a68bb0..afebdea 100644 --- a/src/test/scala/combinations/HighCardTest.scala +++ b/src/test/scala/combinations/HighCardTest.scala @@ -5,7 +5,7 @@ import cards._ class HighCardTest extends FunSuite { - test("HighCard accepts any hand") { + test("HighCard returns true only when no other combination applies") { val hand = List( Card(Two, Hearts), Card(Four, Clubs), @@ -13,16 +13,21 @@ class HighCardTest extends FunSuite { Card(Jack, Spades), Card(Ace, Hearts) ) - val combination = HighCard() - assert(combination.verify(hand)) + assert(combination.verify(hand)) // No other combination applies assertEquals(combination.score.chips, 5) assertEquals(combination.score.multiplier, 1) } - test("HighCard accepts even a single card") { - val hand = List(Card(King, Clubs)) + test("HighCard returns false when hand has a pair") { + val hand = List( + Card(Two, Hearts), + Card(Two, Spades), // pair + Card(Four, Clubs), + Card(Six, Diamonds), + Card(Nine, Hearts) + ) val combination = HighCard() - assert(combination.verify(hand)) + assert(!combination.verify(hand)) // Because it's a pair } }