parent
ae5f58c8c7
commit
3171da146f
3 changed files with 150 additions and 0 deletions
72
tests/RockPaperScissorsTest.php
Normal file
72
tests/RockPaperScissorsTest.php
Normal file
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
use Assert\AssertionFailedException;
|
||||
|
||||
beforeEach(function () {
|
||||
$this->game = new App\RockPaperScissorsGame();
|
||||
});
|
||||
|
||||
it('throws an exception for an empty first move', function () {
|
||||
$this->game->firstMove('');
|
||||
})->throws(AssertionFailedException::class, 'You must specify a move.');
|
||||
|
||||
it('throws an exception for an empty second move', function () {
|
||||
$this->game->secondMove('');
|
||||
})->throws(AssertionFailedException::class, 'You must specify a move.');
|
||||
|
||||
it('throws an exception if an invalid first move is entered', function () {
|
||||
$this->game->firstMove('banana');
|
||||
})->throws(AssertionFailedException::class, 'You must enter a valid move. banana given.');
|
||||
|
||||
it('throws an exception if an invalid second move is entered', function () {
|
||||
$this->game->secondMove('apple');
|
||||
})->throws(AssertionFailedException::class, 'You must enter a valid move. apple given.');
|
||||
|
||||
it('returns the result of two different valid moves', function (
|
||||
string $firstMove,
|
||||
string $secondMove,
|
||||
string $winner
|
||||
) {
|
||||
$this->game
|
||||
->firstMove($firstMove)
|
||||
->secondMove($secondMove);
|
||||
|
||||
assertSame($winner, $this->game->getWinner());
|
||||
})->with([
|
||||
[
|
||||
'firstMove' => 'rock',
|
||||
'secondMove' => 'paper',
|
||||
'winner' => 'paper',
|
||||
],
|
||||
[
|
||||
'firstMove' => 'paper',
|
||||
'secondMove' => 'rock',
|
||||
'winner' => 'paper',
|
||||
],
|
||||
[
|
||||
'firstMove' => 'rock',
|
||||
'secondMove' => 'scissors',
|
||||
'winner' => 'scissors',
|
||||
],
|
||||
[
|
||||
'firstMove' => 'scissors',
|
||||
'secondMove' => 'rock',
|
||||
'winner' => 'scissors',
|
||||
],
|
||||
[
|
||||
'firstMove' => 'scissors',
|
||||
'secondMove' => 'paper',
|
||||
'winner' => 'scissors',
|
||||
],
|
||||
[
|
||||
'firstMove' => 'paper',
|
||||
'secondMove' => 'scissors',
|
||||
'winner' => 'scissors',
|
||||
],
|
||||
]);
|
||||
|
||||
test('it returns null if there is a tie', function (string $move) {
|
||||
$this->game->firstMove($move)->secondMove($move);
|
||||
|
||||
assertNull($this->game->getWinner());
|
||||
})->with(['rock', 'paper', 'scissors']);
|
Loading…
Add table
Add a link
Reference in a new issue