-
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.
feat: add test of CanStartGame and CannotStartGame
Co-authored-by: Rick Su <[email protected]> Co-authored-by: miku3920 <[email protected]>
- Loading branch information
1 parent
946f8f7
commit 41ba3e5
Showing
6 changed files
with
117 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Remove="Class1.cs" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,28 @@ | ||
namespace ChineseCheckers.Domain; | ||
|
||
public class Game | ||
{ | ||
public bool IsStarted { get; private set; } | ||
private readonly List<Player> _players = []; | ||
|
||
public Game() | ||
{ | ||
} | ||
|
||
public void AddPlayer(Player player) | ||
{ | ||
_players.Add(player); | ||
} | ||
|
||
public void Start() | ||
{ | ||
// 在這裡實作遊戲開始的邏輯 | ||
// 例如,初始化遊戲板、發放棋子等等 | ||
IsStarted = _players.Count is 2 or 3 or 4 or 6; | ||
|
||
if (IsStarted == false) | ||
{ | ||
// TODO: throw domain exception | ||
} | ||
} | ||
} |
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,6 @@ | ||
namespace ChineseCheckers.Domain; | ||
|
||
public class Player(string name) | ||
{ | ||
public string Name { get; private set; } = name; | ||
} |
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,59 @@ | ||
using ChineseCheckers.Domain; | ||
|
||
namespace ChineseCheckers.Tests; | ||
|
||
[TestClass] | ||
public class StartGameTest | ||
{ | ||
[Description(""" | ||
Given: 2 players | ||
When: Start game | ||
Then: Game is started | ||
""")] | ||
[TestMethod] | ||
[DataRow(2)] | ||
[DataRow(3)] | ||
[DataRow(4)] | ||
[DataRow(6)] | ||
public void CanStartGame(int playerCount) | ||
{ | ||
// Arrange | ||
var game = new Game(); | ||
for (var i = 0; i < playerCount; i++) | ||
{ | ||
game.AddPlayer(new Player($"Player {i}")); | ||
} | ||
|
||
// Act | ||
game.Start(); | ||
|
||
// Assert | ||
Assert.IsTrue(game.IsStarted); | ||
} | ||
|
||
|
||
[Description(""" | ||
Given: 1 player | ||
When: Start game | ||
Then: Game is not started | ||
""")] | ||
[TestMethod] | ||
[DataRow(1)] | ||
[DataRow(5)] | ||
[DataRow(7)] | ||
public void CannotStartGame(int playerCount) | ||
{ | ||
// Arrange | ||
var game = new Game(); | ||
for (var i = 0; i < playerCount; i++) | ||
{ | ||
game.AddPlayer(new Player($"Player {i}")); | ||
} | ||
|
||
// Act | ||
game.Start(); | ||
|
||
// Assert | ||
Assert.IsFalse(game.IsStarted); | ||
} | ||
} |