Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/Domain/HiLoCounter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Domain;

final class HiLoCounter
{
private int $count = 0;

public function count(Card $card): void
{
$value = $card->numericValue();

if ($value >= 2 && $value <= 6) {
$this->count++;
} elseif ($value >= 10) {
$this->count--;
}
}

public function runningCount(): int
{
return $this->count;
}

public function reset(): void
{
$this->count = 0;
}
}
13 changes: 13 additions & 0 deletions tests/Domain/BasicStrategyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,4 +516,17 @@ public function testPairOf10sShouldNotSplit(): void

$this->assertSame(Decision::Stand, $strategy->decide($hand, $dealerCard));
}

public function testPairOf9sAgainstDealerTenShouldStand(): void
{
$strategy = new BasicStrategy();

$hand = new Hand();
$hand->addCard(new Card('9', 'Hearts'));
$hand->addCard(new Card('9', 'Spades'));

$dealerCard = new Card('10', 'Diamonds');

$this->assertSame(Decision::Stand, $strategy->decide($hand, $dealerCard));
}
}
55 changes: 55 additions & 0 deletions tests/Domain/HiLoCounterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace App\Tests\Domain;

use App\Domain\Card;
use App\Domain\HiLoCounter;
use PHPUnit\Framework\TestCase;

final class HiLoCounterTest extends TestCase
{
public function testLowCardIncrementsCount(): void
{
$counter = new HiLoCounter();
$counter->count(new Card('5', 'Hearts'));

$this->assertSame(1, $counter->runningCount());
}

public function testNeutralCardDoesNotChangeCount(): void
{
$counter = new HiLoCounter();
$counter->count(new Card('7', 'Hearts'));

$this->assertSame(0, $counter->runningCount());
}

public function testHighCardDecrementsCount(): void
{
$counter = new HiLoCounter();
$counter->count(new Card('King', 'Hearts'));

$this->assertSame(-1, $counter->runningCount());
}

public function testMultipleCardsAccumulateCount(): void
{
$counter = new HiLoCounter();
$counter->count(new Card('2', 'Hearts'));
$counter->count(new Card('King', 'Spades'));
$counter->count(new Card('5', 'Diamonds'));
$counter->count(new Card('7', 'Clubs'));

$this->assertSame(1, $counter->runningCount());
}

public function testResetCounterReturnsToZero(): void
{
$counter = new HiLoCounter();
$counter->count(new Card('2', 'Hearts'));
$counter->count(new Card('3', 'Spades'));
$counter->reset();

$this->assertSame(0, $counter->runningCount());
}
}
Loading