Skip to content

Commit

Permalink
feat(randomizer): frozen randomizer can send a series of integer
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesRezo committed Oct 30, 2024
1 parent c8fa624 commit 9f09c1b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Frozen/Randomizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,24 @@

class Randomizer implements RandomizerInterface
{
public function __construct(protected int $rand)
/** @var int[] */
private array $numbers;

/** @var int[] */
private array $reset;

public function __construct(int ...$numbers)
{
$this->numbers = $numbers;
$this->reset = $this->numbers;
}

public function random(): int
{
return $this->rand;
if (empty($this->numbers)) {
$this->numbers = $this->reset;
}

return (int) \array_shift($this->numbers);
}
}
12 changes: 12 additions & 0 deletions tests/Frozen/RandomizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,16 @@ public function testRandom()
// Then
$this->assertEquals(1, $actual); // :-D
}

public function testMultipleRandom()
{
// Given
$randomizer = new Randomizer(1, 2);

// When
$actual = [$randomizer->random(), $randomizer->random(), $randomizer->random()];

// Then
$this->assertEquals([1, 2, 1], $actual);
}
}

0 comments on commit 9f09c1b

Please sign in to comment.