public void NotSolveInvalidMaze() { var settings = servicesProvider.GetRequiredService <MazeSettings>(); settings.MazeFile = ".\\TestFiles\\maze8x6-error-unsolvable.txt"; MazeTextLoader loader = new MazeTextLoader(settings, logger); var glogger = servicesProvider.GetRequiredService <ILoggerFactory>().CreateLogger <MazeGrid>(); IMazeGrid grid = new MazeGrid(glogger); grid.Load(loader); var solutions = new List <IEnumerable <IMazeCell> >(); grid.Solve(sut, (solvedPath) => { if (solvedPath.Count() > 0) { solutions.Add(solvedPath); } }); // Empty solution Assert.Empty(solutions); }
public void SolveValidMaze() { var settings = servicesProvider.GetRequiredService <MazeSettings>(); MazeTextLoader loader = new MazeTextLoader(settings, logger); var glogger = servicesProvider.GetRequiredService <ILoggerFactory>().CreateLogger <MazeGrid>(); IMazeGrid grid = new MazeGrid(glogger); grid.Load(loader); // Keep a list of solutions var solutions = new List <IEnumerable <IMazeCell> >(); grid.Solve(sut, (solvedPath) => { if (solvedPath.Count() > 0) { solutions.Add(solvedPath); } }); // Single solution Assert.Single(solutions); // First Item = Start Assert.True(solutions.FirstOrDefault().First().Equals(grid.Start)); // Last Item = Finish Assert.True(solutions.FirstOrDefault().Last().Equals(grid.Finish)); }
public void GenerateGraph() { var settings = servicesProvider.GetRequiredService <MazeSettings>(); MazeTextLoader loader = new MazeTextLoader(settings, logger); sut.Load(loader); Graph <IMazeCell> _graph = sut.GenerateGraph(); Assert.True(_graph.Nodes.Count() > 0); }
public void ThrowOnGetNodeByPositionIfOutOfRange() { var settings = servicesProvider.GetRequiredService <MazeSettings>(); MazeTextLoader loader = new MazeTextLoader(settings, logger); sut.Load(loader); // out of range node Assert.Throws <ArgumentException>(() => { var node = sut.GetNode(sut.Height, sut.Width); }); }
public void ReturnNodeByPosition() { var settings = servicesProvider.GetRequiredService <MazeSettings>(); MazeTextLoader loader = new MazeTextLoader(settings, logger); sut.Load(loader); // start node var node = sut.GetNode(sut.Start.Row, sut.Start.Col); Assert.True(node.Equals(sut.Start)); }
public void LoadFromGivenLoader() { var settings = servicesProvider.GetRequiredService <MazeSettings>(); MazeTextLoader loader = new MazeTextLoader(settings, logger); sut.Load(loader); Assert.InRange <int>(sut.Width, settings.MinWidth, int.MaxValue); Assert.InRange <int>(sut.Height, settings.MinHeight, int.MaxValue); Assert.True(sut.MazeMap != null); }
public void ThrowIfFileIsMissingStartOrEndPoint() { var settings = servicesProvider.GetRequiredService <MazeSettings>(); settings.MazeFile = "./maze8x6-error-no-start.txt"; MazeTextLoader sut = new MazeTextLoader(settings, logger); var glogger = servicesProvider.GetRequiredService <ILoggerFactory>().CreateLogger <MazeGrid>(); IMazeGrid grid = new MazeGrid(glogger); Assert.Throws <Exception>(() => { grid.Load(sut); }); }
public void ThrowIfFileNotFound() { var settings = servicesProvider.GetRequiredService <MazeSettings>(); settings.MazeFile = "./I-do-not-exist.txt"; MazeTextLoader sut = new MazeTextLoader(settings, logger); var glogger = servicesProvider.GetRequiredService <ILoggerFactory>().CreateLogger <MazeGrid>(); IMazeGrid grid = new MazeGrid(glogger); Assert.Throws <Exception>(() => { grid.Load(sut); }); }
public void LoadMazeGridFromFile() { var settings = servicesProvider.GetRequiredService <MazeSettings>(); MazeTextLoader sut = new MazeTextLoader(settings, logger); var glogger = servicesProvider.GetRequiredService <ILoggerFactory>().CreateLogger <MazeGrid>(); IMazeGrid grid = new MazeGrid(glogger); sut.Load(grid); Assert.InRange <int>(grid.Width, settings.MinWidth, int.MaxValue); Assert.InRange <int>(grid.Height, settings.MinHeight, int.MaxValue); Assert.True(grid.MazeMap != null); }
public void ReturnCallbackFromGivenSolver() { var settings = servicesProvider.GetRequiredService <MazeSettings>(); MazeTextLoader loader = new MazeTextLoader(settings, logger); sut.Load(loader); var slogger = servicesProvider.GetRequiredService <ILoggerFactory>().CreateLogger <BFSGraphSolver>(); BFSGraphSolver solver = new BFSGraphSolver(slogger); bool called = false; sut.Solve(solver, (c) => { called = true; }); Assert.True(called); }