Skip to content

Commit

Permalink
add tests for examples in docs and updated docs (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
antouhou authored Dec 26, 2020
1 parent 6f33078 commit 9cf979c
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ var walkingType = new MovementType(1, "Walking");
var swimmingType = new MovementType(2, "Swimming");

var movementTypes = new MovementTypes(
new ITerrainType[] { ground, water },
new Dictionary<IMovementType, Dictionary<ITerrainType, int>>
new TerrainType[] { ground, water },
new Dictionary<MovementType, Dictionary<TerrainType, int>>
{
[walkingType] = new Dictionary<ITerrainType, int>
[walkingType] = new Dictionary<TerrainType, int>
{
[ground] = 1,
[water] = 2
},
[swimmingType] = new Dictionary<ITerrainType, int>
[swimmingType] = new Dictionary<TerrainType, int>
{
[ground] = 2,
[water] = 1
Expand Down Expand Up @@ -137,7 +137,7 @@ Cell state consists of two properties: if the cell can be used to move to/throug

#### Changing the cell's terrain type

Cell's terrain type can be changed using `graph.SetCellsTerrainType()`. Just as with blocking/unblocking cells, there are two variants: `SetCellsTerrainType(IEnumerable<Coordinate3D> coordinates, ITerrainType terrainType)` and `SetCellsTerrainType(Coordinate3D coordinates, ITerrainType terrainType)`.
Cell's terrain type can be changed using `graph.SetCellsTerrainType()`. Just as with blocking/unblocking cells, there are two variants: `SetCellsTerrainType(IEnumerable<Coordinate3D> coordinates, TerrainType terrainType)` and `SetCellsTerrainType(Coordinate3D coordinates, TerrainType terrainType)`.

## Utility methods

Expand Down
72 changes: 72 additions & 0 deletions HexCore.Tests/Documentation.Test.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System.Collections.Generic;
using HexCore;
using NUnit.Framework;

namespace HexCoreTests
{
[TestFixture]
public class Documentation
{
[Test]
public void TerrainMovementTypeExample_ShouldWork()
{
var ground = new TerrainType(1, "Ground");
var water = new TerrainType(2, "Water");

var walkingType = new MovementType(1, "Walking");
var swimmingType = new MovementType(2, "Swimming");

var movementTypes = new MovementTypes(
new TerrainType[] { ground, water },
new Dictionary<MovementType, Dictionary<TerrainType, int>>
{
[walkingType] = new Dictionary<TerrainType, int>
{
[ground] = 1,
[water] = 2
},
[swimmingType] = new Dictionary<TerrainType, int>
{
[ground] = 2,
[water] = 1
}
}
);
}

[Test]
public void CellStateExample_ShouldWork()
{
var ground = new TerrainType(1, "Ground");
var water = new TerrainType(2, "Water");

var walkingType = new MovementType(1, "Walking");
var swimmingType = new MovementType(2, "Swimming");

var movementTypes = new MovementTypes(
new TerrainType[] { ground, water },
new Dictionary<MovementType, Dictionary<TerrainType, int>>
{
[walkingType] = new Dictionary<TerrainType, int>
{
[ground] = 1,
[water] = 2
},
[swimmingType] = new Dictionary<TerrainType, int>
{
[ground] = 2,
[water] = 1
}
}
);

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)
}, movementTypes);
}
}
}
2 changes: 2 additions & 0 deletions HexCore.Tests/Quickstart.Test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public void QuickstartExample_ShouldWork()
new Coordinate2D(1, 2, OffsetTypes.OddRowsRight).To3D()
};
Assert.That(pawnMovementRange, Is.EquivalentTo(expectedMovementRange));

QuickStart.Demo();
}
}
}

0 comments on commit 9cf979c

Please sign in to comment.