public void ThrowsWhenTryingToRunCompletedSolver() { var testGraph = new TestGraph(); var solver = new Greedy <TestNode>(testGraph.GetNode(0, 0), testGraph.GetNode(9, 9)); solver.Run(); Assert.Throws <InvalidOperationException>(() => solver.Run()); }
public void GreedyPath() { var solver = new Greedy <TestNode>(_start, _end); solver.Run(); Assert.Multiple(() => { CollectionAssert.AreEqual( new List <TestNode> { _testGraph.GetNode(1, 1), _testGraph.GetNode(2, 2), _testGraph.GetNode(3, 3), _testGraph.GetNode(4, 3), _testGraph.GetNode(5, 3), _testGraph.GetNode(6, 4), _testGraph.GetNode(6, 5), _testGraph.GetNode(7, 6), _testGraph.GetNode(8, 7), _testGraph.GetNode(9, 8), _testGraph.GetNode(9, 9) }, solver.Path ); CollectionAssert.AreEqual( new List <TestNode> { _testGraph.GetNode(8, 9), _testGraph.GetNode(0, 0), _testGraph.GetNode(8, 6), _testGraph.GetNode(1, 0), _testGraph.GetNode(8, 8), _testGraph.GetNode(2, 0), _testGraph.GetNode(7, 3), _testGraph.GetNode(0, 1), _testGraph.GetNode(6, 7), _testGraph.GetNode(1, 2), _testGraph.GetNode(7, 8), _testGraph.GetNode(0, 2), _testGraph.GetNode(9, 7), _testGraph.GetNode(2, 3), _testGraph.GetNode(1, 3), _testGraph.GetNode(2, 1), _testGraph.GetNode(6, 3), _testGraph.GetNode(6, 2), _testGraph.GetNode(7, 4), _testGraph.GetNode(3, 1), _testGraph.GetNode(6, 6), _testGraph.GetNode(5, 6), _testGraph.GetNode(5, 2), _testGraph.GetNode(3, 2), _testGraph.GetNode(7, 7), _testGraph.GetNode(9, 6), _testGraph.GetNode(4, 2) }, solver.Open ); CollectionAssert.AreEqual( new List <TestNode> { _testGraph.GetNode(1, 1), _testGraph.GetNode(2, 2), _testGraph.GetNode(3, 3), _testGraph.GetNode(4, 3), _testGraph.GetNode(5, 3), _testGraph.GetNode(6, 4), _testGraph.GetNode(6, 5), _testGraph.GetNode(7, 6), _testGraph.GetNode(8, 7), _testGraph.GetNode(9, 8), _testGraph.GetNode(9, 9) }, solver.Closed ); Assert.AreEqual(29.0d, Math.Round(solver.PathCost)); }); }
public void TestRunTicks() { var graph = new TestGraph(); var solver = new Greedy <TestNode>(graph.GetNode(0, 0), graph.GetNode(9, 9)); solver.Run(1); Assert.AreEqual(SolverState.Incomplete, solver.State); }
public void TestNoPath() { var graph = new TestGraph(); var solver = new Greedy <TestNode>(graph.GetNode(0, 0), graph.GetNode(9, 0)); solver.Run(); Assert.AreEqual(SolverState.Failure, solver.State); }