Skip to content

Commit e959e3d

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 9e304c0 + 8a7792a commit e959e3d

17 files changed

+417
-109
lines changed

HexCore.Tests/HexGraph/AStarSearch.Test.cs renamed to HexCore.Tests/AStarSearch.Test.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using HexCoreTests.Fixtures;
44
using NUnit.Framework;
55

6-
namespace HexCoreTests.HexGraph
6+
namespace HexCoreTests
77
{
88
[TestFixture]
99
public class AStarSearchTest

HexCore.Tests/DataStructures/Coordinate2D.Test.cs renamed to HexCore.Tests/Coordinate2D.Test.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
using System.Collections.Generic;
21
using HexCore;
32
using HexCoreTests.Fixtures;
43
using NUnit.Framework;
54

6-
namespace HexCoreTests.DataStructures
5+
namespace HexCoreTests
76
{
87
[TestFixture]
98
public class Coordinate2DTest
@@ -18,7 +17,7 @@ public void ConvertsOffsetCoordinatesToCubeCoordinatesCorrectly()
1817
//Down and right: Y - 1, Z + 1
1918
//Down and left: X - 1, Z + 1
2019
//Right: X + 1, Y - 1;
21-
var expectedCubeCoordinates = new []
20+
var expectedCubeCoordinates = new[]
2221
{
2322
new Coordinate3D(0, 0, 0),
2423
// Down right:
@@ -38,7 +37,7 @@ public void ConvertsOffsetCoordinatesToCubeCoordinatesCorrectly()
3837
// Down and left:
3938
new Coordinate3D(1, -3, 2)
4039
};
41-
40+
4241
Assert.That(cubeCoordinates, Is.EqualTo(expectedCubeCoordinates));
4342
}
4443

@@ -77,5 +76,13 @@ public void To3D_ShouldConvertOddRowsRight()
7776
var actualCoordinate3D = coordinate2D.To3D();
7877
Assert.That(actualCoordinate3D, Is.EqualTo(expectedCoordinate3D));
7978
}
79+
80+
[Test]
81+
public void ToString_ShouldSerializeToString()
82+
{
83+
var coordinate2D = new Coordinate2D(1, 1, OffsetTypes.OddRowsRight);
84+
85+
Assert.That(coordinate2D.ToString(), Is.EqualTo("(1, 1)"));
86+
}
8087
}
8188
}

HexCore.Tests/DataStructures/Coordinate3D.Test.cs renamed to HexCore.Tests/Coordinate3D.Test.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using HexCore;
33
using NUnit.Framework;
44

5-
namespace HexCoreTests.DataStructures
5+
namespace HexCoreTests
66
{
77
[TestFixture]
88
public class Coordinate3DTest
@@ -119,5 +119,13 @@ public void To2D_ShouldConvertTo2DOddRowsRight()
119119
var expectedCoordinate2D = new Coordinate2D(1, 1, OffsetTypes.OddRowsRight);
120120
Assert.That(actualCoordinate2D, Is.EqualTo(expectedCoordinate2D));
121121
}
122+
123+
[Test]
124+
public void ToString_ShouldSerializeToString()
125+
{
126+
var coordinate3D = new Coordinate3D(1, -2, 1);
127+
128+
Assert.That(coordinate3D.ToString(), Is.EqualTo("(1, -2, 1)"));
129+
}
122130
}
123131
}
Lines changed: 230 additions & 38 deletions
Large diffs are not rendered by default.

HexCore.Tests/HexGraph/GraphFactory.Test.cs renamed to HexCore.Tests/GraphFactory.Test.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using HexCoreTests.Fixtures;
33
using NUnit.Framework;
44

5-
namespace HexCoreTests.HexGraph
5+
namespace HexCoreTests
66
{
77
[TestFixture]
88
public class GraphFactoryTest
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using HexCoreTests.Fixtures;
33
using NUnit.Framework;
44

5-
namespace HexCoreTests.HexGraph
5+
namespace HexCoreTests
66
{
77
[TestFixture]
88
public class GraphUtilsTest

HexCore.Tests/HexCore.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10+
<PackageReference Include="coverlet.msbuild" Version="2.9.0" />
1011
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.1" />
1112
<PackageReference Include="NUnit" Version="3.12.0" />
1213
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />

HexCore.Tests/MovementType.Test.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using HexCore;
2+
using NUnit.Framework;
3+
4+
namespace HexCoreTests
5+
{
6+
[TestFixture]
7+
public class MovementTypeTest
8+
{
9+
[Test]
10+
public void Equals_ShouldReturnFalse_WhenMovementTypesAreNotEqual()
11+
{
12+
var type1 = new MovementType(1, "Type");
13+
var type2 = new MovementType(2, "Type");
14+
var type3 = new MovementType(1, "Some other type");
15+
16+
Assert.That(type1.Equals(type2), Is.False);
17+
Assert.That(type1.Equals(type3), Is.False);
18+
Assert.That(type1.Equals(null), Is.False);
19+
}
20+
21+
[Test]
22+
public void Equals_ShouldReturnTrue_WhenMovementTypesAreEqual()
23+
{
24+
var type1 = new MovementType(1, "Type");
25+
var type2 = new MovementType(1, "Type");
26+
27+
Assert.That(type1.Equals(type2), Is.True);
28+
}
29+
}
30+
}

HexCore.Tests/HexGraph/MovementTypes.Test.cs renamed to HexCore.Tests/MovementTypes.Test.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using System.Collections.Generic;
22
using HexCore;
3+
using HexCoreTests.Fixtures;
34
using NUnit.Framework;
45

5-
namespace HexCoreTests.HexGraph
6+
namespace HexCoreTests
67
{
78
[TestFixture]
89
public class MovementTypesTest
@@ -253,6 +254,30 @@ public void GetMovementCost_ShouldReturnCostFromAToB()
253254
Assert.That(movementTypes.GetMovementCost(flyingType, ground), Is.EqualTo(1));
254255
}
255256

257+
[Test]
258+
public void GetMovementCost_ShouldThrow_WhenUnknownMovementTypeIsPassed()
259+
{
260+
var unknownMovementType = new MovementType(1, "Some movement type");
261+
262+
var movementTypes = MovementTypesFixture.GetMovementTypes();
263+
264+
Assert.That(() => { movementTypes.GetMovementCost(unknownMovementType, MovementTypesFixture.Ground); },
265+
Throws.ArgumentException.With.Message.EqualTo(
266+
"Unknown movement type: 'Some movement type'"));
267+
}
268+
269+
[Test]
270+
public void GetMovementCost_ShouldThrow_WhenUnknownTerrainTypeIsPassed()
271+
{
272+
var unknownTerrainType = new TerrainType(1, "Some terrain type");
273+
274+
var movementTypes = MovementTypesFixture.GetMovementTypes();
275+
276+
Assert.That(() => { movementTypes.GetMovementCost(MovementTypesFixture.Walking, unknownTerrainType); },
277+
Throws.ArgumentException.With.Message.EqualTo(
278+
"Unknown terrain type: 'Some terrain type'"));
279+
}
280+
256281
[Test]
257282
public void GetType_ShouldReturnTypeByTheId()
258283
{

HexCore.Tests/QuickStart.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static void Demo()
1414
var swimmingType = new MovementType(2, "Swimming");
1515

1616
var movementTypes = new MovementTypes(
17-
new ITerrainType[] { ground, water },
17+
new ITerrainType[] {ground, water},
1818
new Dictionary<IMovementType, Dictionary<ITerrainType, int>>
1919
{
2020
[walkingType] = new Dictionary<ITerrainType, int>
@@ -30,15 +30,16 @@ public static void Demo()
3030
}
3131
);
3232

33-
var graph = new Graph(new CellState[] {
34-
new CellState(false, new Coordinate2D(0,0, OffsetTypes.OddRowsRight), ground),
35-
new CellState(false, new Coordinate2D(0,1, OffsetTypes.OddRowsRight), ground),
36-
new CellState(true, new Coordinate2D(1,0, OffsetTypes.OddRowsRight), water),
37-
new CellState(false, new Coordinate2D(1,1, OffsetTypes.OddRowsRight), water),
38-
new CellState(false, new Coordinate2D(1,2, OffsetTypes.OddRowsRight), ground)
33+
var graph = new Graph(new[]
34+
{
35+
new CellState(false, new Coordinate2D(0, 0, OffsetTypes.OddRowsRight), ground),
36+
new CellState(false, new Coordinate2D(0, 1, OffsetTypes.OddRowsRight), ground),
37+
new CellState(true, new Coordinate2D(1, 0, OffsetTypes.OddRowsRight), water),
38+
new CellState(false, new Coordinate2D(1, 1, OffsetTypes.OddRowsRight), water),
39+
new CellState(false, new Coordinate2D(1, 2, OffsetTypes.OddRowsRight), ground)
3940
}, movementTypes);
4041

41-
var pawnPosition = new Coordinate2D(0,0, OffsetTypes.OddRowsRight).To3D();
42+
var pawnPosition = new Coordinate2D(0, 0, OffsetTypes.OddRowsRight).To3D();
4243
// Mark pawn's position as occupied
4344
graph.BlockCells(pawnPosition);
4445

@@ -49,9 +50,9 @@ public static void Demo()
4950
);
5051

5152
var pawnGoal = new Coordinate2D(1, 2, OffsetTypes.OddRowsRight).To3D();
52-
53+
5354
var theShortestPath = graph.GetShortestPath(
54-
pawnPosition,
55+
pawnPosition,
5556
pawnGoal,
5657
walkingType
5758
);

0 commit comments

Comments
 (0)