Archived
1
0
Fork 0

Move Tetris and TestTetris to one solution

This commit is contained in:
Ethanell 2022-05-18 11:28:00 +02:00
parent e4170be81e
commit c515481143
28 changed files with 480 additions and 69 deletions

2
.gitignore vendored
View file

@ -1,4 +1,4 @@
/.idea/ .idea/
bin/ bin/
obj/ obj/
/packages/ /packages/

6
TestTetris/.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
/.idea/
bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/

40
TestTetris/GameTest.cs Normal file
View file

@ -0,0 +1,40 @@
using System;
using System.Drawing;
using NUnit.Framework;
using Tetris.Models;
namespace TestTetris;
public class GameTest {
private Game g;
[SetUp]
public void SetUp() {
g = new("test", new Grid(new Color[10,20]));
Console.Out.WriteLine("===={Grid w/ Tetrominoe}====");
Console.Out.WriteLine(g.Grid.ToString(g.CurrentTetrominoe));
Console.Out.WriteLine("============================");
}
[Test]
public void HitBottom() {
for (int i = 1; i < (g.Grid.MaxGrid.Y+1)-g.CurrentTetrominoe.Shape.GetLength(1)+1; i++) {
g.CurrentTetrominoe.GoDown();
Console.Out.WriteLine(g.Grid.ToString(g.CurrentTetrominoe));
}
Assert.AreEqual(true, g.HitBottom());
}
[Test]
public void HitTop() {
Assert.False(g.HitTop());
for (int x = 0; x <= g.Grid.MaxGrid.X; x++)
g.Grid.CGrid[x,g.CurrentTetrominoe.Shape.GetLength(1)] = Color.Red;
Console.Out.WriteLine(g.Grid.ToString(g.CurrentTetrominoe));
Assert.True(g.HitTop());
}
}

169
TestTetris/GridTest.cs Normal file
View file

@ -0,0 +1,169 @@
using System;
using System.Drawing;
using NUnit.Framework;
using Tetris.Models;
namespace TestTetris;
public class GridTest {
private Color[,] ig;
private Grid g;
private Tetrominoe t;
private static readonly Random random = new Random();
[SetUp]
public void SetUp() {
ig = new Color[10, 20];
g = new Grid(ig);
t = new Tetrominoe(g, new bool[,] {
{true, false, false},
{true, true, true}
}, new Point(5, 0), 0, Color.Aqua);
Console.Out.WriteLine("===={Grid w/ Tetrominoe}====");
Console.Out.WriteLine(g.ToString(t));
Console.Out.WriteLine("============================");
}
[Test]
public void CanGoLeft() {
int startX = t.Coordinates.X;
int startY = t.Coordinates.Y;
Console.Out.WriteLine(t.Coordinates);
for (int i = 1; i <= startX - g.MinGrid.X; i++) {
t.GoLeft();
Console.Out.WriteLine(g.ToString(t));
Assert.AreEqual(new Point(startX-i, startY), t.Coordinates);
}
// Try over the left grid limit
Assert.AreEqual(new Point(g.MinGrid.X, startY), t.Coordinates);
t.GoLeft();
Assert.AreEqual(new Point(g.MinGrid.X, startY), t.Coordinates);
}
[Test]
public void CanGoRight() {
int startX = t.Coordinates.X;
int startY = t.Coordinates.Y;
Console.Out.WriteLine(t.Coordinates);
for (int i = 1; i < (g.MaxGrid.X+1)-startX-t.Shape.GetLength(0)+1; i++) {
t.GoRight();
Console.Out.WriteLine(g.ToString(t));
Assert.AreEqual(new Point(startX+i, startY), t.Coordinates);
}
// Try over the right grid limit
Assert.AreEqual(new Point((g.MaxGrid.X+1)-t.Shape.GetLength(0), startY), t.Coordinates);
t.GoRight();
Assert.AreEqual(new Point((g.MaxGrid.X+1)-t.Shape.GetLength(0), startY), t.Coordinates);
}
[Test]
public void CanGoDown() {
int startX = t.Coordinates.X;
int startY = t.Coordinates.Y;
for (int i = 1; i < (g.MaxGrid.Y+1)-t.Shape.GetLength(1)+1; i++) {
t.GoDown();
Console.Out.WriteLine(g.ToString(t));
Assert.AreEqual(new Point(startX, startY+i), t.Coordinates);
}
// Try over the grid depth limit
Assert.AreEqual(new Point(startX, (g.MaxGrid.Y+1)-t.Shape.GetLength(1)), t.Coordinates);
t.GoDown();
Assert.AreEqual(new Point(startX, (g.MaxGrid.Y+1)-t.Shape.GetLength(1)), t.Coordinates);
}
[Test]
public void CanRotate() {
bool[,] shape = new bool[,] {
{true, false, false},
{true, true, true}
};
int longestShapeBorder;
if (shape.GetLength(0) > shape.GetLength(1))
longestShapeBorder = shape.GetLength(0);
else
longestShapeBorder = shape.GetLength(1);
g = new Grid(new Color[longestShapeBorder, longestShapeBorder]);
t = new Tetrominoe(g, shape, new Point(0, 0), 0, Color.Aqua);
Console.Out.WriteLine(g.ToString(t));
t.RotateLeft();
Console.Out.WriteLine(g.ToString(t));
Assert.AreEqual(3, t.Orientation);
t.RotateLeft();
Console.Out.WriteLine(g.ToString(t));
Assert.AreEqual(2, t.Orientation);
t.RotateLeft();
Console.Out.WriteLine(g.ToString(t));
Assert.AreEqual(1, t.Orientation);
t.RotateLeft();
Console.Out.WriteLine(g.ToString(t));
Assert.AreEqual(0, t.Orientation);
}
[Test]
public void CantGo() {
ig[4, 0] = Color.Red;
ig[4, 1] = Color.Red;
ig[4, 2] = Color.Red;
ig[4, 3] = Color.Red;
ig[5, 3] = Color.Red;
ig[6, 3] = Color.Red;
ig[7, 3] = Color.Red;
ig[7, 2] = Color.Red;
ig[7, 1] = Color.Red;
ig[7, 0] = Color.Red;
Console.Out.WriteLine(g.ToString(t));
int startX = t.Coordinates.X;
int startY = t.Coordinates.Y;
int startOrientation = t.Orientation;
t.GoDown();
Assert.AreEqual(new Point(startX, startY), t.Coordinates);
t.GoLeft();
Assert.AreEqual(new Point(startX, startY), t.Coordinates);
t.GoRight();
Assert.AreEqual(new Point(startX, startY), t.Coordinates);
t.RotateLeft();
Assert.AreEqual(startOrientation, t.Orientation);
t.RotateRight();
Assert.AreEqual(startOrientation, t.Orientation);
}
[Test]
public void LineFull() {
Console.Out.WriteLine(g.ToString());
Assert.False(g.LineFull());
for (int x = 0; x < ig.GetLength(0); x++)
ig[x, ig.GetLength(1) - 1] = Color.Aqua;
Console.Out.WriteLine("==========");
Console.Out.WriteLine(g.ToString());
Assert.True(g.LineFull());
}
[Test]
public void ClearLine() {
for (uint x = 0; x < ig.GetLength(0); x++)
for (uint y = 0; y < ig.GetLength(1); y++) {
ig[x, y] = Color.FromArgb(random.Next(256), random.Next(256), random.Next(256));
}
for (int x = 0; x < ig.GetLength(0); x++)
ig[x, ig.GetLength(1) - 1] = Color.Aqua;
Color[,] olg_grid = (Color[,])ig.Clone();
Console.Out.WriteLine(g.ToString());
g.ClearLine();
Console.Out.WriteLine("==========");
Console.Out.WriteLine(g.ToString());
for (uint x = 0; x < ig.GetLength(0); x++)
for (uint y = 1; y < ig.GetLength(1); y++) {
Assert.AreEqual(olg_grid[x, y-1], ig[x,y]);
}
for (uint x = 0; x < ig.GetLength(0); x++)
Assert.AreEqual(Color.Empty, ig[x, 0]);
}
}

View file

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
<PackageReference Include="coverlet.collector" Version="3.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Tetris\Tetris.csproj" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,27 @@
using System;
using System.Drawing;
using NUnit.Framework;
using Tetris.Models;
namespace TestTetris;
public class TetrominoeParserTest {
[Test]
public void TestAll() {
bool[,] shape;
Tetrominoe t;
foreach (String name in TetrominoeParser.List()) {
Console.Out.WriteLine("====={"+name+"}=====");
Grid g = new Grid(new Color[10, 20]);
t = new Tetrominoe(g, name);
Console.Out.WriteLine(t);
}
}
[Test]
public void NotFound() {
Assert.Throws<Exception>(delegate {
TetrominoeParser.GetShape("azertyuiop");
});
}
}

View file

@ -0,0 +1,107 @@
using System;
using System.Drawing;
using NUnit.Framework;
using Tetris.Models;
using Point = System.Drawing.Point;
namespace TestTetris;
public class TetrominoeTest {
private Tetrominoe t;
private Grid g;
[SetUp]
public void SetUp() {
g = new Grid(new Color[10, 20]);
t = new Tetrominoe(g, new bool[,] {
{true, false, false},
{true, true, true}
}, new Point(5, 10), 0, Color.Aqua);
Console.Out.WriteLine("===={Grid w/ Tetrominoe}====");
Console.Out.WriteLine(g.ToString(t));
Console.Out.WriteLine("============================");
}
[Test]
public void ShapeRotate() {
Assert.AreEqual(new bool[,] {
{true, false, false},
{true, true, true}
}, t.Shape);
t.RotateRight();
Console.Out.WriteLine(t);
Assert.AreEqual(new bool[,] {
{true, true},
{true, false},
{true, false}
}, t.Shape);
t.RotateRight();
Console.Out.WriteLine(t);
Assert.AreEqual(new bool[,] {
{true, true, true},
{false, false, true}
}, t.Shape);
t.RotateRight();
Console.Out.WriteLine(t);
Assert.AreEqual(new bool[,] {
{false, true},
{false, true},
{true, true}
}, t.Shape);
t.RotateRight();
Console.Out.WriteLine(t);
Assert.AreEqual(new bool[,] {
{true, false, false},
{true, true, true}
}, t.Shape);
}
[Test]
public void Orientation() {
t.Orientation = 0;
Assert.AreEqual(0, t.Orientation);
t.RotateLeft();
Assert.AreEqual(3, t.Orientation);
t.RotateLeft();
Assert.AreEqual(2, t.Orientation);
t.RotateLeft();
Assert.AreEqual(1, t.Orientation);
t.RotateLeft();
Assert.AreEqual(0, t.Orientation);
t.Orientation = 3;
t.RotateRight();
Assert.AreEqual(0, t.Orientation);
t.RotateRight();
Assert.AreEqual(1, t.Orientation);
t.RotateRight();
Assert.AreEqual(2, t.Orientation);
t.RotateRight();
Assert.AreEqual(3, t.Orientation);
t.RotateRight();
Assert.AreEqual(0, t.Orientation);
}
[Test]
public void GoRight() {
int startX = t.Coordinates.X;
int startY = t.Coordinates.Y;
t.GoRight();
Assert.AreEqual(new Point(startX+1, startY), t.Coordinates);
}
[Test]
public void GoLeft() {
int startX = t.Coordinates.X;
int startY = t.Coordinates.Y;
t.GoLeft();
Assert.AreEqual(new Point(startX-1, startY), t.Coordinates);
}
[Test]
public void GoDown() {
int startX = t.Coordinates.X;
int startY = t.Coordinates.Y;
t.GoDown();
Assert.AreEqual(new Point(startX,startY+1), t.Coordinates);
}
}

View file

@ -1,8 +1,8 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tetris", "Tetris.csproj", "{1F3B4D12-6E23-49A6-BC9C-5E274CA63B57}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tetris", "Tetris\Tetris.csproj", "{F884CDE3-B3CD-46C4-9396-052B16729A66}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestTetris", "..\TestTetris\TestTetris.csproj", "{2924F978-4A50-4B23-BCEC-6AB822F236AE}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestTetris", "TestTetris\TestTetris.csproj", "{D006D92B-5B5E-4CE0-A40E-C47669CC9E5F}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -10,13 +10,13 @@ Global
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1F3B4D12-6E23-49A6-BC9C-5E274CA63B57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {F884CDE3-B3CD-46C4-9396-052B16729A66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1F3B4D12-6E23-49A6-BC9C-5E274CA63B57}.Debug|Any CPU.Build.0 = Debug|Any CPU {F884CDE3-B3CD-46C4-9396-052B16729A66}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F3B4D12-6E23-49A6-BC9C-5E274CA63B57}.Release|Any CPU.ActiveCfg = Release|Any CPU {F884CDE3-B3CD-46C4-9396-052B16729A66}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F3B4D12-6E23-49A6-BC9C-5E274CA63B57}.Release|Any CPU.Build.0 = Release|Any CPU {F884CDE3-B3CD-46C4-9396-052B16729A66}.Release|Any CPU.Build.0 = Release|Any CPU
{2924F978-4A50-4B23-BCEC-6AB822F236AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D006D92B-5B5E-4CE0-A40E-C47669CC9E5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2924F978-4A50-4B23-BCEC-6AB822F236AE}.Debug|Any CPU.Build.0 = Debug|Any CPU {D006D92B-5B5E-4CE0-A40E-C47669CC9E5F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2924F978-4A50-4B23-BCEC-6AB822F236AE}.Release|Any CPU.ActiveCfg = Release|Any CPU {D006D92B-5B5E-4CE0-A40E-C47669CC9E5F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2924F978-4A50-4B23-BCEC-6AB822F236AE}.Release|Any CPU.Build.0 = Release|Any CPU {D006D92B-5B5E-4CE0-A40E-C47669CC9E5F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

6
Tetris/.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
/.idea/
bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/

View file

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View file

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 48 KiB

22
Tetris/Tetris.sln Normal file
View file

@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tetris", "Tetris.csproj", "{1F3B4D12-6E23-49A6-BC9C-5E274CA63B57}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestTetris", "..\TestTetris\TestTetris.csproj", "{2924F978-4A50-4B23-BCEC-6AB822F236AE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1F3B4D12-6E23-49A6-BC9C-5E274CA63B57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1F3B4D12-6E23-49A6-BC9C-5E274CA63B57}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1F3B4D12-6E23-49A6-BC9C-5E274CA63B57}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1F3B4D12-6E23-49A6-BC9C-5E274CA63B57}.Release|Any CPU.Build.0 = Release|Any CPU
{2924F978-4A50-4B23-BCEC-6AB822F236AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2924F978-4A50-4B23-BCEC-6AB822F236AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2924F978-4A50-4B23-BCEC-6AB822F236AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2924F978-4A50-4B23-BCEC-6AB822F236AE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View file

@ -0,0 +1,13 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=c98faea6_002Df30d_002D4512_002D8272_002D3f49f99a10c7/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="GridTest" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
&lt;TestAncestor&gt;&#xD;
&lt;TestId&gt;NUnit3x::2924F978-4A50-4B23-BCEC-6AB822F236AE::net6.0-windows7.0::TestTetris.GridTest&lt;/TestId&gt;&#xD;
&lt;TestId&gt;NUnit3x::2924F978-4A50-4B23-BCEC-6AB822F236AE::net6.0-windows7.0::TestTetris.TetrominoeTest&lt;/TestId&gt;&#xD;
&lt;TestId&gt;NUnit3x::2924F978-4A50-4B23-BCEC-6AB822F236AE::net6.0-windows7.0::TestTetris.TetrominoeParserTest.test&lt;/TestId&gt;&#xD;
&lt;TestId&gt;NUnit3x::2924F978-4A50-4B23-BCEC-6AB822F236AE::net6.0-windows7.0::TestTetris.TetrominoeParserTest&lt;/TestId&gt;&#xD;
&lt;TestId&gt;NUnit3x::2924F978-4A50-4B23-BCEC-6AB822F236AE::net6.0-windows7.0::TestTetris.GameTest.HitBottom&lt;/TestId&gt;&#xD;
&lt;TestId&gt;NUnit3x::2924F978-4A50-4B23-BCEC-6AB822F236AE::net6.0-windows7.0::TestTetris.GameTest.HitTop&lt;/TestId&gt;&#xD;
&lt;/TestAncestor&gt;&#xD;
&lt;/SessionState&gt;</s:String>
</wpf:ResourceDictionary>