-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Broke out the bool logic check to determine if it is the computers first turn into its own spec. Grouping logic blocks with functions for better readability.
- Loading branch information
Joe Shipley
committed
May 4, 2012
1 parent
611ffd6
commit 7239029
Showing
7 changed files
with
141 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
Source/Domain.GameLogic/Specifications/ComputerFirstTurnSpecification.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Linq; | ||
using TTT.Domain.Entities; | ||
|
||
namespace TTT.Domain.GameLogic.Specifications | ||
{ | ||
public class ComputerFirstTurnSpecification : IComputerFirstTurnSpecification | ||
{ | ||
public bool IsFirstTurnForComputer(Game game) | ||
{ | ||
return game.Moves.All(m => m.Owner != Enums.PlayerType.Computer); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Source/Domain.GameLogic/Specifications/IComputerFirstTurnSpecification.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using TTT.Domain.Entities; | ||
|
||
namespace TTT.Domain.GameLogic.Specifications | ||
{ | ||
public interface IComputerFirstTurnSpecification | ||
{ | ||
bool IsFirstTurnForComputer(Game game); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
Source/Tests/Unit/Domain/Specifications/ComputerFirstTurnSpecificationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System.Collections.Generic; | ||
using Machine.Specifications; | ||
using TTT.Domain; | ||
using TTT.Domain.Entities; | ||
using TTT.Domain.GameLogic.Specifications; | ||
using TTT.Tests.Helpers.Builders; | ||
using TTT.Tests.Infrastructure; | ||
|
||
namespace TTT.Tests.Unit.Domain.Specifications.ComputerFirstTurnSpecificationTests | ||
{ | ||
[Subject("Domain, Specifications, ComputerFirstTurnSpecification, IsFirstTurnForComputer")] | ||
public class When_asking_if_its_the_computers_first_turn_and_it_is | ||
: BaseIsolationTest<ComputerFirstTurnSpecification> | ||
{ | ||
private static bool _result; | ||
private static Game _game; | ||
|
||
Establish context = () => | ||
{ | ||
_game = new GameBuilder().WithMoves(new List<GameMove> | ||
{ | ||
new GameMove { Owner = Enums.PlayerType.Human, Position = BoardPosition.CreateFrom("B", 2) } | ||
}) | ||
.Build(); | ||
}; | ||
|
||
Because of = () => _result = ClassUnderTest.IsFirstTurnForComputer(_game); | ||
|
||
It should_let_us_know_that_it_is_the_computers_first_turn = () => | ||
_result.ShouldBeTrue(); | ||
} | ||
|
||
[Subject("Domain, Specifications, ComputerFirstTurnSpecification, IsFirstTurnForComputer")] | ||
public class When_determining_if_an_invalid_move_is_legitimate_or_not | ||
: BaseIsolationTest<ComputerFirstTurnSpecification> | ||
{ | ||
private static bool _result; | ||
private static Game _game; | ||
|
||
Establish context = () => | ||
{ | ||
_game = new GameBuilder().WithMoves(new List<GameMove> | ||
{ | ||
new GameMove { Owner = Enums.PlayerType.Human, Position = BoardPosition.CreateFrom("B", 1) }, | ||
new GameMove { Owner = Enums.PlayerType.Computer, Position = BoardPosition.CreateFrom("B", 2) }, | ||
new GameMove { Owner = Enums.PlayerType.Human, Position = BoardPosition.CreateFrom("B", 3) }, | ||
}) | ||
.Build(); | ||
}; | ||
|
||
Because of = () => _result = ClassUnderTest.IsFirstTurnForComputer(_game); | ||
|
||
It should_let_us_know_that_it_is_not_the_computers_first_turn = () => | ||
_result.ShouldBeFalse(); | ||
} | ||
} |