public void PerformTest(string inputData, IEnumerable <int> expectedCosts) { var state = StatesLoader.LoadStateFromInputData(inputData); var costs = state.Chests.Zip(expectedCosts, Tuple.Create) .ToDictionary(tuple => tuple.Item1, tuple => tuple.Item2); const int energy = int.MaxValue; var start = state.Position; var paths = pathFinder.GetPathsByDijkstra(state, state.Position, state.Chests); var previousCost = 0; foreach (var path in paths) { state.Energy = energy; state.Position = start; var controller = TestsHelper.MoveThroughPath(true, state, path.Path.Skip(1).ToList()); var position = controller.State.Position; Assert.True(costs.ContainsKey(position)); Assert.AreEqual(costs[position], path.Cost); Assert.AreEqual(costs[position], energy - controller.State.Energy); CollectionAssert.Contains(state.Chests, position); Assert.True(previousCost <= path.Cost); previousCost = path.Cost; costs.Remove(position); } CollectionAssert.IsEmpty(costs, "Have no path to chests: " + string.Join(";", costs.Keys)); }
public void Find_Empty_Path_When_No_Path(string map) { var state = StatesLoader.LoadStateFromInputData(map); var paths = pathFinder.GetPathsByDijkstra(state, state.Position, state.Chests).ToList(); CollectionAssert.AreEqual(new List <PathWithCost>(), paths); }
public void ReturnEmptyPath_WhenCantWinGame(string stateName) { var state = StatesLoader.LoadStateFromInputData(Resources.ResourceManager.GetString(stateName, CultureInfo.InvariantCulture)); var path = new GreedyPathFinder().FindPathToCompleteGoal(state); Assert.IsEmpty(path); }
public static StateController LoadStateFromInputData_And_MoveThroughPath(string stateInputData, IPathFinder pathFinder, string stateName = "") { var isGreedyPathFinder = pathFinder is My_GreedyPathFinder; var path = FindPath(pathFinder, StatesLoader.LoadStateFromInputData(stateInputData, stateName), isGreedyPathFinder); return(MoveThroughPath(isGreedyPathFinder, StatesLoader.LoadStateFromInputData(stateInputData, stateName), path)); }
private ToolStripItem[] BuildDropDownItemsWithStates() { return(StatesLoader .LoadAllStateNames(Folders.StatesForStudents) .Select(stateName => (ToolStripItem) new ToolStripButton(stateName, null, ChangeStateOnStateNameClick) { Name = stateName }) .ToArray()); }
private void RestartCurrentStateWithCurrentPathFinder() { CheckButton(stateBtns, stateBtns[currentStateInd].Name); statusBar.Text = ""; scaledViewPanelPainter.ScaledViewPanel.FitToWindow = true; timer.Dispose(); currentState = StatesLoader.LoadStateFromFolder(Folders.StatesForStudents, stateBtns[currentStateInd].Name); var mutableStateForStudent = new State(currentState); var path = currentPathFinder.FindPathToCompleteGoal(mutableStateForStudent); scaledViewPanelPainter.Controller = new StateController(currentState, path); InvalidateViews(); StartNewTimer(scaledViewPanelPainter.Controller); }
public void Dijkstra_Path_Finder_Is_Lazy() { var inputData = Resources.ResourceManager.GetString("maze_time_limit", CultureInfo.InvariantCulture); var state = StatesLoader.LoadStateFromInputData(inputData); state.Chests.Add(new Point(1, 1)); var start = new Point(0, 1); Assume.That(!state.IsWallAt(start)); BasePerformanceTests.RunWithTimeout(() => { for (int i = 0; i < 100000; ++i) { state.Position = start; var paths = pathFinder .GetPathsByDijkstra(state, start, state.Chests).FirstOrDefault(); Assert.IsNotNull(paths); } return(0); }, 2000, "Метод должен быть ленивым!"); }