public void TestBlockPaths() { var result = Rectify.MakeRectangles(TestData.KeyholeTest(), DataLayout.CodeInitializedArray); Assert.AreEqual(5, result.Count, "Did not get 5 initial rectangles as expected"); var pathfinder = new RectifyPathfinder(result, StandardParams); pathfinder.ReplaceCellAt(new Position(2, 2), 2); Assert.AreEqual(5, pathfinder.NodeCount, "Did not get the 5 total rectangles expected"); var resultPath = pathfinder.CalculatePath(new Position(2, 3), new Position(2, 1)); Assert.AreEqual(0, resultPath.Count, "found a path when none expected"); resultPath = pathfinder.CalculatePath(new Position(2, 2), new Position(2, 3)); Assert.AreEqual(0, resultPath.Count, "found a path when none expected"); resultPath = pathfinder.CalculatePath(new Position(1, 2), new Position(3, 2)); Assert.AreEqual(3, resultPath.Count, "Did not find a path where expected"); resultPath = pathfinder.CalculatePath(new Position(2, 2), new Position(1, 2)); Assert.AreEqual(2, resultPath.Count, "Did not find a path where expected"); }
public void TestSingleCellObstruction() { var result = Rectify.MakeRectangles(GridLatticeTestData.EmptyGridLattice(10)); var pathfinder = new RectifyPathfinder(result, StandardLatticeParams); pathfinder.ReplaceCellAt(new Position(2, 4), 7); var resultPath = pathfinder.CalculatePath(new Position(3, 4), new Position(1, 3)); Assert.AreEqual(4, resultPath.Count, "path was not length 4 as expected"); resultPath = pathfinder.CalculatePath(new Position(3, 4), new Position(1, 4)); Assert.AreEqual(5, resultPath.Count, "path was not length 5 as expected"); }
public void TestAddToRectangles() { var result = Rectify.MakeRectangles(TestData.UniformRectangle(), DataLayout.CodeInitializedArray); Assert.AreEqual(1, result.Count, "Did not get single rectangle as expected"); var pathfinder = new RectifyPathfinder(result, StandardParams); pathfinder.ReplaceCellAt(new Position(2, 2), 4); Assert.AreEqual(5, pathfinder.NodeCount, "Did not get 5 total rectangles as expected"); var resultPath = pathfinder.CalculatePath(new Position(0, 0), new Position(2, 2)); Assert.AreEqual(0, resultPath.Count, "found a path when none expected"); }
public void TestCacheInvalidated() { var result = Rectify.MakeRectangles(TestData.BigKeyholeTest(), DataLayout.CodeInitializedArray); var pathfinder = new RectifyPathfinder(result, StandardParams); var resultPath = pathfinder.CalculatePath(new Position(0, 0), new Position(0, 5)); Assert.AreEqual(8, resultPath.Count, "Did not find a path where expected"); pathfinder.ReplaceCellAt(new Position(2, 4), 2); //either the caching algorithm isn't really working in the first place, or the checks we're already doing //wind up failling with the new rectangles. //This test is moot. resultPath = pathfinder.CalculatePath(new Position(0, 0), new Position(0, 5)); Assert.AreEqual(0, resultPath.Count, "Found previous path, cache not invalidated"); }
public void TestAddToTorus() { var result = Rectify.MakeRectangles(TestData.BigTorusTest(), DataLayout.CodeInitializedArray); Assert.AreEqual(9, result.Count, "Did not get 9 rectangles as expected"); var pathfinder = new RectifyPathfinder(result, StandardParams); pathfinder.ReplaceCellAt(new Position(3, 3), 4); Assert.AreEqual(11, pathfinder.NodeCount, "Did not get the 11 total rectangles as expected"); //These succeed because a wall already exists between the two regions. var resultPath = pathfinder.CalculatePath(new Position(3, 3), new Position(2, 2)); Assert.AreEqual(0, resultPath.Count, "found a path when none expected"); resultPath = pathfinder.CalculatePath(new Position(2, 2), new Position(3, 3)); Assert.AreEqual(0, resultPath.Count, "found a path when none expected"); }