public void PassableTest() { _graph.Add(new Point(0, 1)); _graph.AddConnection(new Point(0, 1), new Point(1, 2)); _graph.AddConnection(new Point(2, 3), new Point(3, 4)); _graph.AddConnection(new Point(3, 4), new Point(1, 2)); _graph.AddConnection(new Point(3, 4), new Point(10, 20)); _graph.AddConnection(new Point(10, 20), new Point(20, 80)); // separate net _graph.AddConnection(new Point(800, 100), new Point(900, 100)); _graph.AddConnection(new Point(900, 100), new Point(850, 1000)); _graph.AddConnection(new Point(800, 100), new Point(850, 1000)); _graph.AddConnection(new Point(850, 1000), new Point(950, 800)); _graph.AddConnection(new Point(950, 800), new Point(20, 80)); var hingePoint = new Point(10, 20); _graph.TogglePassable(hingePoint); Assert.False(_graph.NodeIsPassable(hingePoint)); Assert.Catch <InvalidOperationException>(() => _graph.AStarSolve(new Point(10, 20), new Point(800, 100))); Assert.Catch <InvalidOperationException>(() => _graph.AStarSolve(new Point(800, 100), new Point(10, 20))); _graph.MakePassable(hingePoint); Assert.True(_graph.NodeIsPassable(hingePoint)); _graph.TogglePassable(hingePoint); Assert.False(_graph.NodeIsPassable(hingePoint)); _graph.TogglePassable(hingePoint); Assert.True(_graph.NodeIsPassable(hingePoint)); }
public void Test() { var logLevel = Logger.LoggingLevel; Logger.LoggingLevel = Logger.LogLevel.Verbose; var nodes = _g.Nodes.ToArray(); var start = nodes[_random.Next(0, nodes.Length)]; var end = nodes[_random.Next(0, nodes.Length)]; var stopwatch = new Stopwatch(); stopwatch.Start(); var path = _g.AStarSolve(start, end); stopwatch.Stop(); var elapsed = stopwatch.ElapsedMilliseconds; Logger.Log($"A* took {stopwatch.ElapsedTicks.ToString()} ticks"); Logger.Log($"A* took {elapsed.ToString()}ms"); Assert.LessOrEqual(elapsed, 250L, "Test took to long"); Assert.IsNotEmpty(path); PrintPath(path); Logger.LoggingLevel = logLevel; Console.WriteLine(_g.ToString()); }
public void Test() { var start = new Point(_random.Next(100), _random.Next(100)); var end = new Point(_random.Next(100), _random.Next(100)); var path = _g.AStarSolve(start, end); Assert.IsNotEmpty(path); Console.WriteLine($"Path from {start} to {end}"); PrintPath(path); }
public void InvalidNodeAsArgumentTest() { Assert.Catch <Graph <Point> .NodeNotFoundException>(() => _testGraph.AStarSolve(new Point(-100, -100), new Point(-299, -299)), "NodeNotFoundException wasn't thrown, even though both of the provided values couldn't be found"); Assert.Catch <Graph <Point> .NodeNotFoundException>(() => _testGraph.AStarSolve(new Point(-100, -100), new Point(950, 800)), "NodeNotFoundException wasn't thrown, even though one of the provided values couldn't be found"); Assert.Catch <Graph <Point> .NodeNotFoundException>(() => _testGraph.AStarSolve(new Point(950, 800), new Point(-100, -100)), "NodeNotFoundException wasn't thrown, even though one of the provided values couldn't be found"); Assert.Catch(() => _testGraph.AStarSolve(null, new Point(-100, -100)), "No Exception was thrown, even though one of the provided values was null"); Assert.Catch(() => _testGraph.AStarSolve(new Point(950, 800), null), "No Exception was thrown, even though one of the provided values was null"); }