Minor style cleanup.
parent
6c0bff1de1
commit
4839bfcb00
|
@ -1,15 +1,9 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Godot;
|
using Godot;
|
||||||
using Godot.Collections;
|
|
||||||
using GoDotTest;
|
using GoDotTest;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Array = System.Array;
|
|
||||||
|
|
||||||
//using GodotXUnitApi;
|
|
||||||
//using Xunit;
|
|
||||||
|
|
||||||
namespace GodotComponentTest.tests;
|
namespace GodotComponentTest.tests;
|
||||||
|
|
||||||
|
@ -18,14 +12,14 @@ public class HexGridPathFindingTests : TestClass
|
||||||
private HexGrid _hexGrid;
|
private HexGrid _hexGrid;
|
||||||
private HexCell _hexCell;
|
private HexCell _hexCell;
|
||||||
|
|
||||||
private HexCell _positionA = new HexCell(new Vector2(2, 0));
|
private HexCell _positionA = new HexCell(new Vector2(2, 0));
|
||||||
private HexCell _positionB = new HexCell(new Vector2(4, 2));
|
private HexCell _positionB = new HexCell(new Vector2(4, 2));
|
||||||
private HexCell _positionC = new HexCell(new Vector2(7, 0));
|
private HexCell _positionC = new HexCell(new Vector2(7, 0));
|
||||||
private HexCell _positionD = new HexCell(new Vector2(5, 0));
|
private HexCell _positionD = new HexCell(new Vector2(5, 0));
|
||||||
private HexCell _positionE = new HexCell(new Vector2(2, 2));
|
private HexCell _positionE = new HexCell(new Vector2(2, 2));
|
||||||
private HexCell _positionF = new HexCell(new Vector2(1, 3));
|
private HexCell _positionF = new HexCell(new Vector2(1, 3));
|
||||||
private HexCell _positionG = new HexCell(new Vector2(1, 0));
|
private HexCell _positionG = new HexCell(new Vector2(1, 0));
|
||||||
|
|
||||||
private Vector2[] _obstacles =
|
private Vector2[] _obstacles =
|
||||||
{
|
{
|
||||||
new Vector2(2, 1),
|
new Vector2(2, 1),
|
||||||
|
@ -53,7 +47,7 @@ public class HexGridPathFindingTests : TestClass
|
||||||
_hexGrid.AddObstacle(new HexCell(obstacle));
|
_hexGrid.AddObstacle(new HexCell(obstacle));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestBounds()
|
public void TestBounds()
|
||||||
{
|
{
|
||||||
|
@ -61,7 +55,7 @@ public class HexGridPathFindingTests : TestClass
|
||||||
Assert.Equal(_hexGrid.PathCostDefault, _hexGrid.GetHexCost(new Vector2(0, 4)));
|
Assert.Equal(_hexGrid.PathCostDefault, _hexGrid.GetHexCost(new Vector2(0, 4)));
|
||||||
Assert.Equal(_hexGrid.PathCostDefault, _hexGrid.GetHexCost(new Vector2(7, 0)));
|
Assert.Equal(_hexGrid.PathCostDefault, _hexGrid.GetHexCost(new Vector2(7, 0)));
|
||||||
Assert.Equal(_hexGrid.PathCostDefault, _hexGrid.GetHexCost(new Vector2(7, 4)));
|
Assert.Equal(_hexGrid.PathCostDefault, _hexGrid.GetHexCost(new Vector2(7, 4)));
|
||||||
|
|
||||||
Assert.Equal(0, _hexGrid.GetHexCost(new Vector2(8, 2)));
|
Assert.Equal(0, _hexGrid.GetHexCost(new Vector2(8, 2)));
|
||||||
Assert.Equal(0, _hexGrid.GetHexCost(new Vector2(6, 5)));
|
Assert.Equal(0, _hexGrid.GetHexCost(new Vector2(6, 5)));
|
||||||
Assert.Equal(0, _hexGrid.GetHexCost(new Vector2(-1, 2)));
|
Assert.Equal(0, _hexGrid.GetHexCost(new Vector2(-1, 2)));
|
||||||
|
@ -73,7 +67,7 @@ public class HexGridPathFindingTests : TestClass
|
||||||
{
|
{
|
||||||
HexGrid grid = new HexGrid();
|
HexGrid grid = new HexGrid();
|
||||||
grid.SetBounds(new Vector2(-5, -5), new Vector2(-2, -2));
|
grid.SetBounds(new Vector2(-5, -5), new Vector2(-2, -2));
|
||||||
|
|
||||||
Assert.Equal(grid.PathCostDefault, grid.GetHexCost(new Vector2(-2, -2)));
|
Assert.Equal(grid.PathCostDefault, grid.GetHexCost(new Vector2(-2, -2)));
|
||||||
Assert.Equal(grid.PathCostDefault, grid.GetHexCost(new Vector2(-5, -5)));
|
Assert.Equal(grid.PathCostDefault, grid.GetHexCost(new Vector2(-5, -5)));
|
||||||
Assert.Equal(0, grid.GetHexCost(new Vector2(0, 0)));
|
Assert.Equal(0, grid.GetHexCost(new Vector2(0, 0)));
|
||||||
|
@ -86,7 +80,7 @@ public class HexGridPathFindingTests : TestClass
|
||||||
{
|
{
|
||||||
HexGrid grid = new HexGrid();
|
HexGrid grid = new HexGrid();
|
||||||
grid.SetBounds(new Vector2(-3, -3), new Vector2(2, 2));
|
grid.SetBounds(new Vector2(-3, -3), new Vector2(2, 2));
|
||||||
|
|
||||||
Assert.Equal(grid.PathCostDefault, grid.GetHexCost(new Vector2(-3, -3)));
|
Assert.Equal(grid.PathCostDefault, grid.GetHexCost(new Vector2(-3, -3)));
|
||||||
Assert.Equal(grid.PathCostDefault, grid.GetHexCost(new Vector2(2, 2)));
|
Assert.Equal(grid.PathCostDefault, grid.GetHexCost(new Vector2(2, 2)));
|
||||||
Assert.Equal(grid.PathCostDefault, grid.GetHexCost(new Vector2(0, 0)));
|
Assert.Equal(grid.PathCostDefault, grid.GetHexCost(new Vector2(0, 0)));
|
||||||
|
@ -98,11 +92,11 @@ public class HexGridPathFindingTests : TestClass
|
||||||
public void TestGridObstacles()
|
public void TestGridObstacles()
|
||||||
{
|
{
|
||||||
Assert.Equal(_obstacles.Length, _hexGrid.Obstacles.Count);
|
Assert.Equal(_obstacles.Length, _hexGrid.Obstacles.Count);
|
||||||
|
|
||||||
// Adding an obstacle
|
// Adding an obstacle
|
||||||
_hexGrid.AddObstacle(new HexCell(new Vector2(0, 0)));
|
_hexGrid.AddObstacle(new HexCell(new Vector2(0, 0)));
|
||||||
Assert.Equal(0, _hexGrid.Obstacles[new Vector2(0, 0)]);
|
Assert.Equal(0, _hexGrid.Obstacles[new Vector2(0, 0)]);
|
||||||
|
|
||||||
// Replacing obstacle
|
// Replacing obstacle
|
||||||
_hexGrid.AddObstacle(new HexCell(new Vector2(0, 0)), 2);
|
_hexGrid.AddObstacle(new HexCell(new Vector2(0, 0)), 2);
|
||||||
Assert.Equal(2, _hexGrid.Obstacles[new Vector2(0, 0)]);
|
Assert.Equal(2, _hexGrid.Obstacles[new Vector2(0, 0)]);
|
||||||
|
@ -110,7 +104,7 @@ public class HexGridPathFindingTests : TestClass
|
||||||
// Removing obstacle
|
// Removing obstacle
|
||||||
_hexGrid.RemoveObstacle(new HexCell(new Vector2(0, 0)));
|
_hexGrid.RemoveObstacle(new HexCell(new Vector2(0, 0)));
|
||||||
Assert.DoesNotContain(new Vector2(0, 0), _hexGrid.Obstacles);
|
Assert.DoesNotContain(new Vector2(0, 0), _hexGrid.Obstacles);
|
||||||
|
|
||||||
// Removing invalid does not cause error
|
// Removing invalid does not cause error
|
||||||
_hexGrid.RemoveObstacle(new HexCell(new Vector2(0, 0)));
|
_hexGrid.RemoveObstacle(new HexCell(new Vector2(0, 0)));
|
||||||
}
|
}
|
||||||
|
@ -119,10 +113,10 @@ public class HexGridPathFindingTests : TestClass
|
||||||
public void TestHexCost()
|
public void TestHexCost()
|
||||||
{
|
{
|
||||||
Assert.Equal(_hexGrid.PathCostDefault, _hexGrid.GetHexCost(new Vector2(1, 1)));
|
Assert.Equal(_hexGrid.PathCostDefault, _hexGrid.GetHexCost(new Vector2(1, 1)));
|
||||||
Assert.Equal(0, _hexGrid.GetHexCost(new HexCell(new Vector3 (2, 1, -3))));
|
Assert.Equal(0, _hexGrid.GetHexCost(new HexCell(new Vector3(2, 1, -3))));
|
||||||
|
|
||||||
_hexGrid.AddObstacle(new HexCell(1, 1), 1.337f);
|
_hexGrid.AddObstacle(new HexCell(1, 1), 1.337f);
|
||||||
Assert.Equal(1.337f, _hexGrid.GetHexCost(new Vector2(1,1)));
|
Assert.Equal(1.337f, _hexGrid.GetHexCost(new Vector2(1, 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -140,7 +134,7 @@ public class HexGridPathFindingTests : TestClass
|
||||||
Assert.Single(_hexGrid.Barriers);
|
Assert.Single(_hexGrid.Barriers);
|
||||||
_hexGrid.AddBarrier(new Vector2(0, 1), HexCell.DIR_S, 8);
|
_hexGrid.AddBarrier(new Vector2(0, 1), HexCell.DIR_S, 8);
|
||||||
Assert.Equal(2, _hexGrid.Barriers.Count);
|
Assert.Equal(2, _hexGrid.Barriers.Count);
|
||||||
|
|
||||||
Assert.Equal(14, _hexGrid.GetMoveCost(new Vector2(0, 0), HexCell.DIR_N));
|
Assert.Equal(14, _hexGrid.GetMoveCost(new Vector2(0, 0), HexCell.DIR_N));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,7 +149,7 @@ public class HexGridPathFindingTests : TestClass
|
||||||
Assert.Equal(expectedCell.AxialCoords, pathCell.AxialCoords);
|
Assert.Equal(expectedCell.AxialCoords, pathCell.AxialCoords);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestStraightLine()
|
public void TestStraightLine()
|
||||||
{
|
{
|
||||||
|
@ -204,7 +198,7 @@ public class HexGridPathFindingTests : TestClass
|
||||||
|
|
||||||
ComparePath(expectedPath, _hexGrid.FindPath(expectedPath.First(), expectedPath.Last()));
|
ComparePath(expectedPath, _hexGrid.FindPath(expectedPath.First(), expectedPath.Last()));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestWalls()
|
public void TestWalls()
|
||||||
{
|
{
|
||||||
|
@ -222,7 +216,7 @@ public class HexGridPathFindingTests : TestClass
|
||||||
{
|
{
|
||||||
_hexGrid.AddBarrier(_positionG, wall);
|
_hexGrid.AddBarrier(_positionG, wall);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<HexCell> expectedPath = new List<HexCell>()
|
List<HexCell> expectedPath = new List<HexCell>()
|
||||||
{
|
{
|
||||||
_positionA,
|
_positionA,
|
||||||
|
@ -240,7 +234,7 @@ public class HexGridPathFindingTests : TestClass
|
||||||
{
|
{
|
||||||
_hexGrid.AddBarrier(_positionG, HexCell.DIR_NE, 3);
|
_hexGrid.AddBarrier(_positionG, HexCell.DIR_NE, 3);
|
||||||
_hexGrid.AddBarrier(_positionG, HexCell.DIR_N, _hexGrid.PathCostDefault - 0.1f);
|
_hexGrid.AddBarrier(_positionG, HexCell.DIR_N, _hexGrid.PathCostDefault - 0.1f);
|
||||||
|
|
||||||
List<HexCell> expectedPath = new List<HexCell>()
|
List<HexCell> expectedPath = new List<HexCell>()
|
||||||
{
|
{
|
||||||
_positionA,
|
_positionA,
|
||||||
|
@ -263,7 +257,7 @@ public class HexGridPathFindingTests : TestClass
|
||||||
new HexCell(new Vector2(5, 1)),
|
new HexCell(new Vector2(5, 1)),
|
||||||
_positionB,
|
_positionB,
|
||||||
};
|
};
|
||||||
|
|
||||||
List<HexCell> longPath = new List<HexCell>()
|
List<HexCell> longPath = new List<HexCell>()
|
||||||
{
|
{
|
||||||
_positionA,
|
_positionA,
|
||||||
|
@ -279,7 +273,7 @@ public class HexGridPathFindingTests : TestClass
|
||||||
|
|
||||||
_hexGrid.PathCostDefault = 1f;
|
_hexGrid.PathCostDefault = 1f;
|
||||||
ComparePath(shortPath, _hexGrid.FindPath(shortPath.First(), shortPath.Last()));
|
ComparePath(shortPath, _hexGrid.FindPath(shortPath.First(), shortPath.Last()));
|
||||||
|
|
||||||
_hexGrid.PathCostDefault = 2f;
|
_hexGrid.PathCostDefault = 2f;
|
||||||
ComparePath(shortPath, _hexGrid.FindPath(shortPath.First(), shortPath.Last()));
|
ComparePath(shortPath, _hexGrid.FindPath(shortPath.First(), shortPath.Last()));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue