fix: ensure HighCard only applies when no other combination matches
This commit is contained in:
11
README.md
11
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.
|
||||
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user