Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
antouhou committed Jul 4, 2020
2 parents 9e304c0 + 8a7792a commit e959e3d
Show file tree
Hide file tree
Showing 17 changed files with 417 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using HexCoreTests.Fixtures;
using NUnit.Framework;

namespace HexCoreTests.HexGraph
namespace HexCoreTests
{
[TestFixture]
public class AStarSearchTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System.Collections.Generic;
using HexCore;
using HexCoreTests.Fixtures;
using NUnit.Framework;

namespace HexCoreTests.DataStructures
namespace HexCoreTests
{
[TestFixture]
public class Coordinate2DTest
Expand All @@ -18,7 +17,7 @@ public void ConvertsOffsetCoordinatesToCubeCoordinatesCorrectly()
//Down and right: Y - 1, Z + 1
//Down and left: X - 1, Z + 1
//Right: X + 1, Y - 1;
var expectedCubeCoordinates = new []
var expectedCubeCoordinates = new[]
{
new Coordinate3D(0, 0, 0),
// Down right:
Expand All @@ -38,7 +37,7 @@ public void ConvertsOffsetCoordinatesToCubeCoordinatesCorrectly()
// Down and left:
new Coordinate3D(1, -3, 2)
};

Assert.That(cubeCoordinates, Is.EqualTo(expectedCubeCoordinates));
}

Expand Down Expand Up @@ -77,5 +76,13 @@ public void To3D_ShouldConvertOddRowsRight()
var actualCoordinate3D = coordinate2D.To3D();
Assert.That(actualCoordinate3D, Is.EqualTo(expectedCoordinate3D));
}

[Test]
public void ToString_ShouldSerializeToString()
{
var coordinate2D = new Coordinate2D(1, 1, OffsetTypes.OddRowsRight);

Assert.That(coordinate2D.ToString(), Is.EqualTo("(1, 1)"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using HexCore;
using NUnit.Framework;

namespace HexCoreTests.DataStructures
namespace HexCoreTests
{
[TestFixture]
public class Coordinate3DTest
Expand Down Expand Up @@ -119,5 +119,13 @@ public void To2D_ShouldConvertTo2DOddRowsRight()
var expectedCoordinate2D = new Coordinate2D(1, 1, OffsetTypes.OddRowsRight);
Assert.That(actualCoordinate2D, Is.EqualTo(expectedCoordinate2D));
}

[Test]
public void ToString_ShouldSerializeToString()
{
var coordinate3D = new Coordinate3D(1, -2, 1);

Assert.That(coordinate3D.ToString(), Is.EqualTo("(1, -2, 1)"));
}
}
}
268 changes: 230 additions & 38 deletions HexCore.Tests/HexGraph/Graph.Test.cs → HexCore.Tests/Graph.Test.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using HexCoreTests.Fixtures;
using NUnit.Framework;

namespace HexCoreTests.HexGraph
namespace HexCoreTests
{
[TestFixture]
public class GraphFactoryTest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using HexCoreTests.Fixtures;
using NUnit.Framework;

namespace HexCoreTests.HexGraph
namespace HexCoreTests
{
[TestFixture]
public class GraphUtilsTest
Expand Down
1 change: 1 addition & 0 deletions HexCore.Tests/HexCore.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="2.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.1" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
Expand Down
30 changes: 30 additions & 0 deletions HexCore.Tests/MovementType.Test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using HexCore;
using NUnit.Framework;

namespace HexCoreTests
{
[TestFixture]
public class MovementTypeTest
{
[Test]
public void Equals_ShouldReturnFalse_WhenMovementTypesAreNotEqual()
{
var type1 = new MovementType(1, "Type");
var type2 = new MovementType(2, "Type");
var type3 = new MovementType(1, "Some other type");

Assert.That(type1.Equals(type2), Is.False);
Assert.That(type1.Equals(type3), Is.False);
Assert.That(type1.Equals(null), Is.False);
}

[Test]
public void Equals_ShouldReturnTrue_WhenMovementTypesAreEqual()
{
var type1 = new MovementType(1, "Type");
var type2 = new MovementType(1, "Type");

Assert.That(type1.Equals(type2), Is.True);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System.Collections.Generic;
using HexCore;
using HexCoreTests.Fixtures;
using NUnit.Framework;

namespace HexCoreTests.HexGraph
namespace HexCoreTests
{
[TestFixture]
public class MovementTypesTest
Expand Down Expand Up @@ -253,6 +254,30 @@ public void GetMovementCost_ShouldReturnCostFromAToB()
Assert.That(movementTypes.GetMovementCost(flyingType, ground), Is.EqualTo(1));
}

[Test]
public void GetMovementCost_ShouldThrow_WhenUnknownMovementTypeIsPassed()
{
var unknownMovementType = new MovementType(1, "Some movement type");

var movementTypes = MovementTypesFixture.GetMovementTypes();

Assert.That(() => { movementTypes.GetMovementCost(unknownMovementType, MovementTypesFixture.Ground); },
Throws.ArgumentException.With.Message.EqualTo(
"Unknown movement type: 'Some movement type'"));
}

[Test]
public void GetMovementCost_ShouldThrow_WhenUnknownTerrainTypeIsPassed()
{
var unknownTerrainType = new TerrainType(1, "Some terrain type");

var movementTypes = MovementTypesFixture.GetMovementTypes();

Assert.That(() => { movementTypes.GetMovementCost(MovementTypesFixture.Walking, unknownTerrainType); },
Throws.ArgumentException.With.Message.EqualTo(
"Unknown terrain type: 'Some terrain type'"));
}

[Test]
public void GetType_ShouldReturnTypeByTheId()
{
Expand Down
21 changes: 11 additions & 10 deletions HexCore.Tests/QuickStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static void Demo()
var swimmingType = new MovementType(2, "Swimming");

var movementTypes = new MovementTypes(
new ITerrainType[] { ground, water },
new ITerrainType[] {ground, water},
new Dictionary<IMovementType, Dictionary<ITerrainType, int>>
{
[walkingType] = new Dictionary<ITerrainType, int>
Expand All @@ -30,15 +30,16 @@ public static void Demo()
}
);

var graph = new Graph(new CellState[] {
new CellState(false, new Coordinate2D(0,0, OffsetTypes.OddRowsRight), ground),
new CellState(false, new Coordinate2D(0,1, OffsetTypes.OddRowsRight), ground),
new CellState(true, new Coordinate2D(1,0, OffsetTypes.OddRowsRight), water),
new CellState(false, new Coordinate2D(1,1, OffsetTypes.OddRowsRight), water),
new CellState(false, new Coordinate2D(1,2, OffsetTypes.OddRowsRight), ground)
var graph = new Graph(new[]
{
new CellState(false, new Coordinate2D(0, 0, OffsetTypes.OddRowsRight), ground),
new CellState(false, new Coordinate2D(0, 1, OffsetTypes.OddRowsRight), ground),
new CellState(true, new Coordinate2D(1, 0, OffsetTypes.OddRowsRight), water),
new CellState(false, new Coordinate2D(1, 1, OffsetTypes.OddRowsRight), water),
new CellState(false, new Coordinate2D(1, 2, OffsetTypes.OddRowsRight), ground)
}, movementTypes);

var pawnPosition = new Coordinate2D(0,0, OffsetTypes.OddRowsRight).To3D();
var pawnPosition = new Coordinate2D(0, 0, OffsetTypes.OddRowsRight).To3D();
// Mark pawn's position as occupied
graph.BlockCells(pawnPosition);

Expand All @@ -49,9 +50,9 @@ public static void Demo()
);

var pawnGoal = new Coordinate2D(1, 2, OffsetTypes.OddRowsRight).To3D();

var theShortestPath = graph.GetShortestPath(
pawnPosition,
pawnPosition,
pawnGoal,
walkingType
);
Expand Down
29 changes: 15 additions & 14 deletions HexCore.Tests/Quickstart.Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void QuickstartExample_ShouldWork()
var swimmingType = new MovementType(2, "Swimming");

var movementTypes = new MovementTypes(
new ITerrainType[] { ground, water },
new ITerrainType[] {ground, water},
new Dictionary<IMovementType, Dictionary<ITerrainType, int>>
{
[walkingType] = new Dictionary<ITerrainType, int>
Expand All @@ -33,15 +33,16 @@ public void QuickstartExample_ShouldWork()
}
);

var graph = new Graph(new CellState[] {
new CellState(false, new Coordinate2D(0,0, OffsetTypes.OddRowsRight), ground),
new CellState(false, new Coordinate2D(0,1, OffsetTypes.OddRowsRight), ground),
new CellState(true, new Coordinate2D(1,0, OffsetTypes.OddRowsRight), water),
new CellState(false, new Coordinate2D(1,1, OffsetTypes.OddRowsRight), water),
new CellState(false, new Coordinate2D(1,2, OffsetTypes.OddRowsRight), ground)
var graph = new Graph(new[]
{
new CellState(false, new Coordinate2D(0, 0, OffsetTypes.OddRowsRight), ground),
new CellState(false, new Coordinate2D(0, 1, OffsetTypes.OddRowsRight), ground),
new CellState(true, new Coordinate2D(1, 0, OffsetTypes.OddRowsRight), water),
new CellState(false, new Coordinate2D(1, 1, OffsetTypes.OddRowsRight), water),
new CellState(false, new Coordinate2D(1, 2, OffsetTypes.OddRowsRight), ground)
}, movementTypes);

var pawnPosition = new Coordinate2D(0,0, OffsetTypes.OddRowsRight).To3D();
var pawnPosition = new Coordinate2D(0, 0, OffsetTypes.OddRowsRight).To3D();
// Mark pawn's position as occupied
graph.BlockCells(pawnPosition);

Expand All @@ -52,9 +53,9 @@ public void QuickstartExample_ShouldWork()
);

var pawnGoal = new Coordinate2D(1, 2, OffsetTypes.OddRowsRight).To3D();

var theShortestPath = graph.GetShortestPath(
pawnPosition,
pawnPosition,
pawnGoal,
walkingType
);
Expand All @@ -64,17 +65,17 @@ public void QuickstartExample_ShouldWork()
graph.BlockCells(pawnGoal);

Assert.That(graph.IsCellBlocked(pawnPosition), Is.True);
Assert.That(theShortestPath, Is.EquivalentTo(new []
Assert.That(theShortestPath, Is.EquivalentTo(new[]
{
new Coordinate2D(0, 1, OffsetTypes.OddRowsRight).To3D(),
pawnGoal
}));

var expectedMovementRange = new[]
{
new Coordinate2D(0,1, OffsetTypes.OddRowsRight).To3D(),
new Coordinate2D(1,1, OffsetTypes.OddRowsRight).To3D(),
new Coordinate2D(1,2, OffsetTypes.OddRowsRight).To3D(),
new Coordinate2D(0, 1, OffsetTypes.OddRowsRight).To3D(),
new Coordinate2D(1, 1, OffsetTypes.OddRowsRight).To3D(),
new Coordinate2D(1, 2, OffsetTypes.OddRowsRight).To3D()
};
Assert.That(pawnMovementRange, Is.EquivalentTo(expectedMovementRange));
}
Expand Down
30 changes: 30 additions & 0 deletions HexCore.Tests/TerrainType.Test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using HexCore;
using NUnit.Framework;

namespace HexCoreTests
{
[TestFixture]
public class TerrainTypeTest
{
[Test]
public void Equals_ShouldReturnFalse_WhenMovementTypesAreNotEqual()
{
var type1 = new TerrainType(1, "Type");
var type2 = new TerrainType(2, "Type");
var type3 = new TerrainType(1, "Some other type");

Assert.That(type1.Equals(type2), Is.False);
Assert.That(type1.Equals(type3), Is.False);
Assert.That(type1.Equals(null), Is.False);
}

[Test]
public void Equals_ShouldReturnTrue_WhenMovementTypesAreEqual()
{
var type1 = new TerrainType(1, "Type");
var type2 = new TerrainType(1, "Type");

Assert.That(type1.Equals(type2), Is.True);
}
}
}
7 changes: 5 additions & 2 deletions HexCore/Coordinate2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ public Coordinate2D(int x, int y, OffsetTypes offsetType)
Y = y;
OffsetType = offsetType;
}

public override string ToString() => $"({X}, {Y})";

public override string ToString()
{
return $"({X}, {Y})";
}
}
}
7 changes: 5 additions & 2 deletions HexCore/Coordinate3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ public Coordinate3D(int x, int y, int z)
{
return new Coordinate3D(a.X * scalar, a.Y * scalar, a.Z * scalar);
}

public override string ToString() => $"({X}, {Y}, {Z})";

public override string ToString()
{
return $"({X}, {Y}, {Z})";
}
}
}
Loading

0 comments on commit e959e3d

Please sign in to comment.