108 lines
3.7 KiB
C#
108 lines
3.7 KiB
C#
|
using Godot;
|
||
|
using GoDotTest;
|
||
|
using System.Diagnostics;
|
||
|
|
||
|
public class HexCellTests : TestClass
|
||
|
{
|
||
|
public HexCellTests(Node testScene) : base(testScene)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void TestHexCellSimple()
|
||
|
{
|
||
|
HexCell cell = new HexCell();
|
||
|
Debug.Assert(cell.CubeCoords == new Vector3(0, 0, 0));
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void TestAxialCoords()
|
||
|
{
|
||
|
HexCell cell = new HexCell(1, 1, -2);
|
||
|
Debug.Assert(cell.AxialCoords == new Vector2(1, 1));
|
||
|
|
||
|
cell = new HexCell(1, -1);
|
||
|
Debug.Assert(cell.AxialCoords == new Vector2(1, -1));
|
||
|
|
||
|
cell = new HexCell(new Vector3(-1, 2, -1));
|
||
|
HexCell otherCell = cell;
|
||
|
Debug.Assert(otherCell.AxialCoords == new Vector2(-1, 2));
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void TestAxialCoordsRounded()
|
||
|
{
|
||
|
HexCell cell = new HexCell(new Vector2(-0.1f, 0.6f));
|
||
|
Debug.Assert(cell.CubeCoords == new Vector3(0, 1, -1));
|
||
|
|
||
|
cell = new HexCell(new Vector2(4.2f, -5.5f));
|
||
|
Debug.Assert(cell.CubeCoords == new Vector3(4, -5, 1));
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void TestConversion()
|
||
|
{
|
||
|
HexCell cell = new HexCell();
|
||
|
Debug.Assert(cell.AxialToCubeCoords(new Vector2(2, 1)) == new Vector3(2, 1, -3));
|
||
|
Debug.Assert(cell.AxialToCubeCoords(new Vector2(-1, -1)) == new Vector3(-1, -1, 2));
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void TestRounding()
|
||
|
{
|
||
|
HexCell cell = new HexCell();
|
||
|
Debug.Assert(cell.RoundCoords(new Vector3(0.1f, 0.5f, -0.6f)) == new Vector3(0, 1, -1));
|
||
|
Debug.Assert(cell.RoundCoords(new Vector3(-0.4f, -1.3f, 1.7f)) == new Vector3(-1, -1, 2));
|
||
|
|
||
|
Debug.Assert(cell.RoundCoords(new Vector2(-0.1f, 0.6f)) == new Vector3(0, 1, -1));
|
||
|
Debug.Assert(cell.RoundCoords(new Vector2(4.2f, -5.5f)) == new Vector3(4, -5, 1));
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void TestCoords()
|
||
|
{
|
||
|
HexCell cell = new HexCell();
|
||
|
|
||
|
// from cubic positive
|
||
|
cell.CubeCoords = new Vector3(2, 1, -3);
|
||
|
Debug.Assert(cell.CubeCoords == new Vector3(2, 1, -3));
|
||
|
Debug.Assert(cell.AxialCoords == new Vector2(2, 1));
|
||
|
Debug.Assert(cell.OffsetCoords == new Vector2(2, 2));
|
||
|
|
||
|
// from offset positive
|
||
|
cell.OffsetCoords = new Vector2(2, 2);
|
||
|
Debug.Assert(cell.CubeCoords == new Vector3(2, 1, -3));
|
||
|
Debug.Assert(cell.AxialCoords == new Vector2(2, 1));
|
||
|
Debug.Assert(cell.OffsetCoords == new Vector2(2, 2));
|
||
|
|
||
|
// from offset negative
|
||
|
cell.OffsetCoords = new Vector2(-1, -2);
|
||
|
Debug.Assert(cell.CubeCoords == new Vector3(-1, -1, 2));
|
||
|
Debug.Assert(cell.AxialCoords == new Vector2(-1, -1));
|
||
|
Debug.Assert(cell.OffsetCoords == new Vector2(-1, -2));
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void TestNearby()
|
||
|
{
|
||
|
HexCell cell = new HexCell(new Vector2(1, 2));
|
||
|
|
||
|
// adjacent
|
||
|
HexCell otherCell = cell.getAdjacent(HexCell.DIR_N);
|
||
|
Debug.Assert(otherCell.AxialCoords == new Vector2(1, 3));
|
||
|
otherCell = cell.getAdjacent(HexCell.DIR_NE);
|
||
|
Debug.Assert(otherCell.AxialCoords == new Vector2(2, 2));
|
||
|
otherCell = cell.getAdjacent(HexCell.DIR_SE);
|
||
|
Debug.Assert(otherCell.AxialCoords == new Vector2(2, 1));
|
||
|
otherCell = cell.getAdjacent(HexCell.DIR_S);
|
||
|
Debug.Assert(otherCell.AxialCoords == new Vector2(1, 1));
|
||
|
otherCell = cell.getAdjacent(HexCell.DIR_SW);
|
||
|
Debug.Assert(otherCell.AxialCoords == new Vector2(0, 2));
|
||
|
otherCell = cell.getAdjacent(HexCell.DIR_NW);
|
||
|
Debug.Assert(otherCell.AxialCoords == new Vector2(0, 3));
|
||
|
|
||
|
// not really adjacent
|
||
|
otherCell = cell.getAdjacent(new Vector3(-3, -3, 6));
|
||
|
Debug.Assert(otherCell.AxialCoords == new Vector2(-2, -1));
|
||
|
}
|
||
|
}
|