Skip to content

Commit 3a2131a

Browse files
committed
Initial Commit
1 parent 0ad5cb4 commit 3a2131a

File tree

61 files changed

+10118
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+10118
-0
lines changed

PostmanDelivers.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.28922.388
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TikTakToe.Engine", "TikTakToe.Engine\TikTakToe.Engine.csproj", "{B518E9EB-D9B5-460A-BB8F-07F2849F2612}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TikTakToe.Engine.Tests", "TikTakToe.Engine.Tests\TikTakToe.Engine.Tests.csproj", "{32A01C4D-654D-4A4E-A579-FDA9422069AC}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{B518E9EB-D9B5-460A-BB8F-07F2849F2612}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17+
{B518E9EB-D9B5-460A-BB8F-07F2849F2612}.Debug|Any CPU.Build.0 = Debug|Any CPU
18+
{B518E9EB-D9B5-460A-BB8F-07F2849F2612}.Release|Any CPU.ActiveCfg = Release|Any CPU
19+
{B518E9EB-D9B5-460A-BB8F-07F2849F2612}.Release|Any CPU.Build.0 = Release|Any CPU
20+
{32A01C4D-654D-4A4E-A579-FDA9422069AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{32A01C4D-654D-4A4E-A579-FDA9422069AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{32A01C4D-654D-4A4E-A579-FDA9422069AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
23+
{32A01C4D-654D-4A4E-A579-FDA9422069AC}.Release|Any CPU.Build.0 = Release|Any CPU
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {5436ACD3-0736-4435-B989-1F7E93F12F8F}
30+
EndGlobalSection
31+
EndGlobal
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace TikTakToe.Engine.Tests
7+
{
8+
[TestClass]
9+
public class DataIntegrationTests
10+
{
11+
[TestMethod]
12+
public void GenerateGame_Test()
13+
{
14+
Game g = new Game();
15+
g.GenerateNewGame("Bob", "Janel");
16+
Assert.IsTrue(g.Id > 0);
17+
}
18+
}
19+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
3+
namespace TikTakToe.Engine.Tests
4+
{
5+
[TestClass]
6+
public class GameBoardTests
7+
{
8+
[TestMethod]
9+
public void BasicBoardRenderWithAllNulls_Test()
10+
{
11+
Game g = new Game();
12+
g.Board = new GameBoard();
13+
//g.Board.Squares = new string[] { null, null, null, null, null, null, null, null };
14+
string gameboard = g.Board.RenderBoard();
15+
System.Console.WriteLine(gameboard);
16+
17+
string expected = @"[ ] [ ] [ ]
18+
19+
[ ] [ ] [ ]
20+
21+
[ ] [ ] [ ]";
22+
23+
Assert.AreEqual(expected, gameboard, "Gameboard layout did not render as expected");
24+
}
25+
26+
[TestMethod]
27+
public void RenderBoardWithSomeSquaresOccupied_Test()
28+
{
29+
Game g = new Game();
30+
g.Board = new GameBoard();
31+
32+
g.Board.Squares[0] = null;
33+
g.Board.Squares[1] = null;
34+
g.Board.Squares[2] = null;
35+
g.Board.Squares[3] = null;
36+
g.Board.Squares[4] = "x";
37+
g.Board.Squares[5] = null;
38+
g.Board.Squares[6] = null;
39+
g.Board.Squares[7] = "O";
40+
g.Board.Squares[8] = "Z";
41+
42+
string gameboard = g.Board.RenderBoard();
43+
System.Console.WriteLine(gameboard);
44+
45+
string expected = @"[ ] [ ] [ ]
46+
47+
[ ] [ X ] [ ]
48+
49+
[ ] [ O ] [ ]";
50+
51+
Assert.AreEqual(expected, gameboard, "Gameboard layout did not render as expected");
52+
}
53+
54+
[TestMethod]
55+
public void RenderBoardWithAllSquaresOccupied_Test()
56+
{
57+
Game g = new Game();
58+
g.Board = new GameBoard();
59+
60+
g.Board.Squares[0] = "X";
61+
g.Board.Squares[1] = "O";
62+
g.Board.Squares[2] = "X";
63+
g.Board.Squares[3] = "O";
64+
g.Board.Squares[4] = "x";
65+
g.Board.Squares[5] = "o";
66+
g.Board.Squares[6] = "X";
67+
g.Board.Squares[7] = "O";
68+
g.Board.Squares[8] = "X";
69+
70+
string gameboard = g.Board.RenderBoard();
71+
System.Console.WriteLine(gameboard);
72+
73+
string expected = @"[ X ] [ O ] [ X ]
74+
75+
[ O ] [ X ] [ O ]
76+
77+
[ X ] [ O ] [ X ]";
78+
79+
Assert.AreEqual(expected, gameboard, "Gameboard layout did not render as expected");
80+
}
81+
}
82+
}
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
using System;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
4+
namespace TikTakToe.Engine.Tests
5+
{
6+
[TestClass]
7+
public class GamePlayTests
8+
{
9+
[TestMethod]
10+
public void XMustGoFirst_Test()
11+
{
12+
GameBoard gameBoard = new GameBoard();
13+
string startBoard = gameBoard.RenderBoard();
14+
15+
var whosTurn = gameBoard.WhosTurnIsIt();
16+
17+
Assert.AreEqual("X", whosTurn.whosTurn, $"First turn should go to X but it was {whosTurn.whosTurn}");
18+
19+
MoveResult result = gameBoard.ExecuteTurn("O", 4);
20+
21+
Assert.IsFalse(result.IsValid, "Move should have been invalid but was computed as valid.");
22+
Assert.AreEqual(startBoard, gameBoard.RenderBoard());
23+
}
24+
25+
[TestMethod]
26+
public void XGoesAndNowItIsOsTurn_Test()
27+
{
28+
GameBoard gameBoard = new GameBoard();
29+
30+
var whosTurn = gameBoard.WhosTurnIsIt();
31+
32+
Assert.AreEqual("X", whosTurn.whosTurn, $"First turn should go to X but it was {whosTurn.whosTurn}");
33+
34+
MoveResult result = gameBoard.ExecuteTurn("X", 4);
35+
36+
Assert.IsTrue(result.IsValid, "Move should have been valid but was computed as invalid.");
37+
whosTurn = gameBoard.WhosTurnIsIt();
38+
Assert.AreEqual("O", whosTurn.whosTurn, $"Next move should go to O but it was computed as {whosTurn.whosTurn}");
39+
}
40+
41+
[TestMethod]
42+
public void XWins_Test()
43+
{
44+
GameBoard gameBoard = new GameBoard();
45+
MoveResult move = gameBoard.ExecuteTurn("X", 8);
46+
var next = gameBoard.WhosTurnIsIt();
47+
Assert.AreEqual("O", next.whosTurn, "Should be O's turn but was not computed that way.");
48+
49+
move = gameBoard.ExecuteTurn("O", 6);
50+
next = gameBoard.WhosTurnIsIt();
51+
Assert.AreEqual("X", next.whosTurn, "Should be X's turn but was not computed that way.");
52+
53+
move = gameBoard.ExecuteTurn("X", 4);
54+
next = gameBoard.WhosTurnIsIt();
55+
Assert.AreEqual("O", next.whosTurn, "Should be O's turn but was not computed that way.");
56+
57+
move = gameBoard.ExecuteTurn("O", 7);
58+
next = gameBoard.WhosTurnIsIt();
59+
Assert.AreEqual("X", next.whosTurn, "Should be X's turn but was not computed that way.");
60+
61+
move = gameBoard.ExecuteTurn("X", 0);
62+
Console.WriteLine(move.GameBoard);
63+
next = gameBoard.WhosTurnIsIt();
64+
var gameover = gameBoard.IsGameOver();
65+
Assert.IsTrue(gameover.gameIsOver, "Game should be over but was not computed as such.");
66+
Assert.AreEqual("X", gameover.winner);
67+
}
68+
69+
[TestMethod]
70+
public void OWinsTest()
71+
{
72+
GameBoard gameBoard = new GameBoard();
73+
74+
MoveResult move = gameBoard.ExecuteTurn("X", 3);
75+
move = gameBoard.ExecuteTurn("O", 0);
76+
move = gameBoard.ExecuteTurn("X", 1);
77+
move = gameBoard.ExecuteTurn("O", 4);
78+
move = gameBoard.ExecuteTurn("X", 5);
79+
move = gameBoard.ExecuteTurn("O", 8);
80+
81+
var gameover = gameBoard.IsGameOver();
82+
Assert.IsTrue(gameover.gameIsOver, "Game should be over but was not computed as such.");
83+
Assert.AreEqual("O", gameover.winner);
84+
}
85+
86+
[TestMethod]
87+
public void GameIsDraw_Test()
88+
{
89+
GameBoard gameBoard = new GameBoard();
90+
91+
MoveResult move = gameBoard.ExecuteTurn("X", 1);
92+
move = gameBoard.ExecuteTurn("O", 0);
93+
move = gameBoard.ExecuteTurn("X", 4);
94+
move = gameBoard.ExecuteTurn("O", 2);
95+
move = gameBoard.ExecuteTurn("X", 5);
96+
move = gameBoard.ExecuteTurn("O", 3);
97+
move = gameBoard.ExecuteTurn("X", 6);
98+
move = gameBoard.ExecuteTurn("O", 7);
99+
move = gameBoard.ExecuteTurn("X", 8);
100+
101+
Assert.IsTrue(move.GameIsOver, "Game should be over but was not computed as such.");
102+
Assert.AreEqual("DRAW", gameBoard.Winner);
103+
}
104+
105+
[TestMethod]
106+
public void XGoesWhenItIsOsTurn_Test()
107+
{
108+
GameBoard gameBoard = new GameBoard();
109+
110+
MoveResult move = gameBoard.ExecuteTurn("X", 1);
111+
move = gameBoard.ExecuteTurn("O", 0);
112+
move = gameBoard.ExecuteTurn("X", 4);
113+
string gameBoardStateAtLastValidTurn = gameBoard.RenderBoard();
114+
move = gameBoard.ExecuteTurn("X", 2);
115+
116+
Assert.IsFalse(move.IsValid, "X going twice should be invalid but it was not computed as such.");
117+
Assert.IsFalse(move.GameIsOver, "Game should not be over but it was computed as over.");
118+
Assert.AreEqual("It is O's turn to move. Play fair.", move.Reason);
119+
Assert.AreEqual(gameBoardStateAtLastValidTurn, gameBoard.RenderBoard(), "Gameboard state should not have changed on an invalid move but it did.");
120+
}
121+
122+
[TestMethod]
123+
public void OGoesWhenItIsXsTurn_Test()
124+
{
125+
GameBoard gameBoard = new GameBoard();
126+
127+
MoveResult move = gameBoard.ExecuteTurn("X", 1);
128+
move = gameBoard.ExecuteTurn("O", 0);
129+
move = gameBoard.ExecuteTurn("X", 4);
130+
move = gameBoard.ExecuteTurn("O", 2);
131+
string gameBoardStateAtLastValidTurn = gameBoard.RenderBoard();
132+
move = gameBoard.ExecuteTurn("O", 3);
133+
134+
Assert.IsFalse(move.IsValid, "O going twice should be invalid but it was not computed as such.");
135+
Assert.IsFalse(move.GameIsOver, "Game should not be over but it was computed as over.");
136+
Assert.AreEqual("It is X's turn to move. Play fair.", move.Reason);
137+
Assert.AreEqual(gameBoardStateAtLastValidTurn, gameBoard.RenderBoard(), "Gameboard state should not have changed on an invalid move but it did.");
138+
}
139+
140+
[TestMethod]
141+
public void GameReportsOver_Test()
142+
{
143+
GameBoard gameBoard = new GameBoard();
144+
MoveResult move = gameBoard.ExecuteTurn("X", 8);
145+
146+
move = gameBoard.ExecuteTurn("O", 6);
147+
move = gameBoard.ExecuteTurn("X", 4);
148+
move = gameBoard.ExecuteTurn("O", 7);
149+
move = gameBoard.ExecuteTurn("X", 0);
150+
151+
move = gameBoard.ExecuteTurn("O", 1);
152+
Assert.IsTrue(move.GameIsOver, "Game should be over but was not computed as such.");
153+
Assert.IsFalse(move.IsValid, "Move was not valid");
154+
Assert.AreEqual("Game is Over. Congratulations to X", move.Reason);
155+
}
156+
157+
[TestMethod]
158+
public void XMovesInSpotOccupiedByO_Test()
159+
{
160+
GameBoard gameBoard = new GameBoard();
161+
MoveResult move = gameBoard.ExecuteTurn("X", 8);
162+
163+
move = gameBoard.ExecuteTurn("O", 6);
164+
move = gameBoard.ExecuteTurn("X", 4);
165+
move = gameBoard.ExecuteTurn("O", 7);
166+
move = gameBoard.ExecuteTurn("X", 7);
167+
168+
Assert.IsFalse(move.GameIsOver, "Game should not be over but was computed as such.");
169+
Assert.IsFalse(move.IsValid, "Move should be invalid");
170+
Assert.AreEqual("The square is already occupied by O. Turn aborted, try again.", move.Reason);
171+
}
172+
173+
[TestMethod]
174+
public void XMovesInSpotOccupiedByX_Test()
175+
{
176+
GameBoard gameBoard = new GameBoard();
177+
MoveResult move = gameBoard.ExecuteTurn("X", 8);
178+
179+
move = gameBoard.ExecuteTurn("O", 6);
180+
move = gameBoard.ExecuteTurn("X", 4);
181+
move = gameBoard.ExecuteTurn("O", 7);
182+
move = gameBoard.ExecuteTurn("X", 4);
183+
184+
Assert.IsFalse(move.GameIsOver, "Game should not be over but was computed as such.");
185+
Assert.IsFalse(move.IsValid, "Move should be invalid");
186+
Assert.AreEqual("The square is already occupied by X. Turn aborted, try again.", move.Reason);
187+
}
188+
189+
[TestMethod]
190+
public void OMovesInSpotOccupiedByO_Test()
191+
{
192+
GameBoard gameBoard = new GameBoard();
193+
MoveResult move = gameBoard.ExecuteTurn("X", 8);
194+
195+
move = gameBoard.ExecuteTurn("O", 6);
196+
move = gameBoard.ExecuteTurn("X", 4);
197+
move = gameBoard.ExecuteTurn("O", 6);
198+
199+
Assert.IsFalse(move.GameIsOver, "Game should not be over but was computed as such.");
200+
Assert.IsFalse(move.IsValid, "Move should be invalid");
201+
Assert.AreEqual("The square is already occupied by O. Turn aborted, try again.", move.Reason);
202+
}
203+
204+
[TestMethod]
205+
public void OMovesInSpotOccupiedByX_Test()
206+
{
207+
GameBoard gameBoard = new GameBoard();
208+
MoveResult move = gameBoard.ExecuteTurn("X", 8);
209+
210+
move = gameBoard.ExecuteTurn("O", 6);
211+
move = gameBoard.ExecuteTurn("X", 4);
212+
move = gameBoard.ExecuteTurn("O", 4);
213+
214+
Assert.IsFalse(move.GameIsOver, "Game should not be over but was computed as such.");
215+
Assert.IsFalse(move.IsValid, "Move should be invalid");
216+
Assert.AreEqual("The square is already occupied by X. Turn aborted, try again.", move.Reason);
217+
}
218+
}
219+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.2</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
11+
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
12+
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\TikTakToe.Engine\TikTakToe.Engine.csproj" />
17+
</ItemGroup>
18+
19+
</Project>

TikTakToe.Engine.Tests/bin/Debug/netcoreapp2.2/Data/GameDB.sqlite3

Whitespace-only changes.

TikTakToe.Engine.Tests/bin/Debug/netcoreapp2.2/GameDB.sqlite3

Whitespace-only changes.

0 commit comments

Comments
 (0)