forked from overengineering/sharpasonne
-
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.
Players & Turns (overengineering#15)
* Adds Sharpasonne.Models.Tests to .vscode build tasks * Replaces public Engine constructor with Factory that returns an optional type * Adds Players class to encapsulate the concept of multiple players. * Adds Players and CurrentPlayerTurn to Engine. * Renames Players consts to use domain language and use C# stylistic convensions. * Fixes typos in EngineTests and PlayersTests
- Loading branch information
1 parent
b8d89c0
commit adea469
Showing
8 changed files
with
298 additions
and
56 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
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; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using Optional.Unsafe; | ||
using Sharpasonne.GameActions; | ||
using Sharpasonne.Models; | ||
using Sharpasonne.Rules; | ||
using Sharpasonne.Tests.Rules; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace Sharpasonne.Tests | ||
{ | ||
public class Engine_PlayerTests : UnitTest<PlaceTileGameAction> | ||
{ | ||
protected Engine CreateEngine(int players) | ||
{ | ||
var mockPlayers = new Mock<Players>(); | ||
|
||
mockPlayers.SetupGet(e => e.Count).Returns(players); | ||
|
||
var option = Engine.Create( | ||
ImmutableQueue<IGameAction>.Empty, | ||
new Dictionary<Type, IImmutableList<IRule<IGameAction>>> { | ||
[typeof(PlaceTileGameAction)] = ImmutableList<IRule<IGameAction>>.Empty | ||
}.ToImmutableDictionary(), | ||
mockPlayers.Object | ||
); | ||
|
||
return option.ValueOrFailure(); | ||
} | ||
|
||
[Fact] | ||
public void Given_2Players_When_FirstTurn_Then_NextPlayerIsFirstPlayer() | ||
{ | ||
Assert.Equal(1, CreateEngine(players: 2).CurrentPlayerTurn); | ||
} | ||
|
||
[Fact] | ||
public void Given_2Players_When_SecondTurn_Then_NextPlayerIsSecondPlayer() | ||
{ | ||
var firstTurn = CreateEngine(2); | ||
var secondTurn = firstTurn.Perform(MakePlaceTile(0, 0)).ValueOrFailure(); | ||
Assert.Equal(2, secondTurn.CurrentPlayerTurn); | ||
} | ||
|
||
[Fact] | ||
public void Given_2Players_When_ThirdTurn_Then_NextPlayerIsFirstPlayerAgain() | ||
{ | ||
var firstTurn = CreateEngine(2); | ||
var secondTurn = firstTurn.Perform(MakePlaceTile(0, 0)).ValueOrFailure(); | ||
var thirdTurn = secondTurn.Perform(MakePlaceTile(0, 1)).ValueOrFailure(); | ||
Assert.Equal(1, thirdTurn.CurrentPlayerTurn); | ||
} | ||
} | ||
} |
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,59 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using Optional.Unsafe; | ||
using Sharpasonne.GameActions; | ||
using Sharpasonne.Models; | ||
using Sharpasonne.Rules; | ||
using Sharpasonne.Tests.Rules; | ||
using Xunit; | ||
|
||
namespace Sharpasonne.Tests | ||
{ | ||
public class PlayersTests : UnitTest<PlaceTileGameAction> | ||
{ | ||
[Fact] | ||
public void Given_ZeroPlayers_When_CreatingPlayers_Then_NoneIsArgumentOutOfRangeException() | ||
{ | ||
Players.Create(0).MatchNone(exception => Assert.IsType<ArgumentOutOfRangeException>(exception)); | ||
} | ||
|
||
[Fact] | ||
public void Given_1Player_When_CreatingPlayers_Then_NoneIsArgumentOutOfRangeException() | ||
{ | ||
Players.Create(1).MatchNone(exception => Assert.IsType<ArgumentOutOfRangeException>(exception)); | ||
} | ||
|
||
[Fact] | ||
public void Given_2Players_When_CreatingPlayers_Then_SomeIsReturned() | ||
{ | ||
Assert.NotNull(Players.Create(2).ValueOrFailure()); | ||
} | ||
|
||
[Fact] | ||
public void Given_6Players_When_CreatingPlayers_Then_NoneIsArgumentOutOfRangeException() | ||
{ | ||
Players.Create(6).MatchNone(exception => Assert.IsType<ArgumentOutOfRangeException>(exception)); | ||
} | ||
|
||
[Fact] | ||
public void Given_NumberOutsideRange_When_FindingNextPlayer_Then_Is1() | ||
{ | ||
Assert.Equal(1, Players.Create(2).ValueOrFailure().NextPlayer(0)); | ||
Assert.Equal(1, Players.Create(2).ValueOrFailure().NextPlayer(3)); | ||
} | ||
|
||
[Fact] | ||
public void Given_Player1_When_FindingNextPlayer_Then_Is2() | ||
{ | ||
Assert.Equal(2, Players.Create(2).ValueOrFailure().NextPlayer(1)); | ||
} | ||
|
||
[Fact] | ||
public void Given_LastPlayerInBound_When_FindingNextPlayer_Then_Is1() | ||
{ | ||
int count = 4; | ||
Assert.Equal(1, Players.Create(count).ValueOrFailure().NextPlayer(count)); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.