Skip to content

Commit

Permalink
Othello不正なアクション判定Green #55
Browse files Browse the repository at this point in the history
  • Loading branch information
ebinase committed May 22, 2022
1 parent ec51e94 commit eb42896
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/Models/Othello/Othello/Turn.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function advance(Position $position): Turn
// これ以上進めない場合
if (!$this->isAdvanceable()) throw new DomainException();
// スキップするしかない場合はコマを置けない
if ($this->mustSkip()) throw new DomainException('コマを置くことができるマスがある場合、スキップはできません');
if ($this->mustSkip()) throw new DomainException('このターンはスキップ以外できません');

return new Turn(
$this->turnNumber + 1,
Expand Down
24 changes: 14 additions & 10 deletions tests/Feature/Models/Othello/Othello/OthelloTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Packages\Models\Othello\Board\Position\Position;
use Packages\Models\Othello\Othello\Othello;
use Packages\Models\Othello\Othello\Turn;
use Tests\Mock\Models\Othello\Action\FirstTurnActionMock;
use Tests\Mock\Models\Othello\Board\SkipBoardMock;
use Tests\TestCase;

Expand Down Expand Up @@ -37,42 +38,45 @@ public function 通常更新()
$turn = Turn::init(),
0,
); // 1ターン目
$position = Position::make([4, 6]);// 先行プレイヤーが1ターン目に指す場所
$action = Action::make(ActionType::SET_STONE, $position);
$action = FirstTurnActionMock::setStone();

// when:
$othello->apply($action); // プレーを進める

// then:
self::assertSame($id->toString(), $othello->id);
self::assertTrue($turn->advance($position) == $othello->getTurn());
self::assertTrue($turn->advance($action->getData()) == $othello->getTurn());
self::assertSame(0, $othello->getSkipCount());

}

/** @test */
public function 不正なアクションを指定された時は例外を出す()
public function スキップせざるを得ないのにコマを置こうとした時は例外を出す()
{
// given:
$turn = Turn::init(); // 1ターン目
$othello = Othello::make(
\Str::uuid(),
Turn::make(1, Color::white(), SkipBoardMock::get()),
0
); // 1ターン目
// when:

$move = Position::make(ActionType::SET_STONE); // おけない場所
$action = FirstTurnActionMock::setStone(); // おけない場所
// then:
$this->expectException(\Exception::class);
$turn->advance($move); // ターンを進める
$othello->apply($action);
}

/** @test */
public function 置ける場所があるのにスキップしようとした場合は例外を出す()
{
// given:
$othello = Othello::init(); // 1ターン目
// when:
$turn = Turn::init(); // 1ターン目
$skipAction = FirstTurnActionMock::skip();
// then:
$this->expectException(\Exception::class);
// 置ける場所があるのに場所指定なしで更新した場合
$turn->advance();
$othello->apply($skipAction);
}

// ---------------------------------------
Expand Down
21 changes: 21 additions & 0 deletions tests/Mock/Models/Othello/Action/FirstTurnActionMock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Tests\Mock\Models\Othello\Action;

use Packages\Models\Othello\Action\Action;
use Packages\Models\Othello\Action\ActionType;
use Packages\Models\Othello\Board\Position\Position;

class FirstTurnActionMock
{
public static function setStone(): Action
{
$position = Position::make([4, 6]);// 先行プレイヤーが1ターン目に指す場所
return Action::make(ActionType::SET_STONE, $position);
}

public static function skip(): Action
{
return Action::make(ActionType::CONFIRM_SKIP);
}
}

0 comments on commit eb42896

Please sign in to comment.