public void Should_ReturnCorrectList_When_FindPathCalled() { var result1 = _arrayService.FindPath(new int[] { 1, 2, 0, 3, 0, 2, 0 }); var result2 = _arrayService.FindPath(new int[] { 1, 2, 0, 1, 0, 2, 0 }); var result3 = _arrayService.FindPath(new int[] { 1, 2, 0, -1, 0, 2, 0 }); var result4 = _arrayService.FindPath(new int[] { 1, 2, 1, -1, 0, 2, 0 }); var result5 = _arrayService.FindPath(new int[] { 3, 9, 1, 1, 1, 1, 1 }); var expected1 = new List <int> { 6, 3, 1, 0 }; var expected2 = new List <int>(); var expected3 = new List <int>(); var expected4 = new List <int>(); var expected5 = new List <int>() { 6, 1, 0 }; Assert.AreEqual(expected1, result1); Assert.AreEqual(expected2, result2); Assert.AreEqual(expected3, result3); Assert.AreEqual(expected4, result4); Assert.AreEqual(expected5, result5); }
static void Main() { var arrayService = new ArrayService(); var fileService = new FileService(); var cacheService = new CacheService(); var outputService = new OutputService(cacheService); try { var listOfArrays = fileService.ReadArray(); var path = new List <int>(); foreach (var array in listOfArrays) { var pathFromCache = cacheService.GetCacheByArray(array); if (pathFromCache == null) { path = arrayService.FindPath(array); if (!arrayService.Failure) // don't save to cache if it's unreachable { cacheService.AddCacheToRepository(array, path); } } else { path = pathFromCache; } Console.Write(outputService.PrepareOutput(array, path, arrayService.Failure)); arrayService.Failure = false; } Console.WriteLine("Would you like to see all of the cached arrays? Y/N"); ConsoleKey response; do { //Console.Write("Are you sure you want to choose this as your login key? [y/n] "); response = Console.ReadKey(false).Key; // true is intercept key (dont show), false is show if (response != ConsoleKey.Enter) { Console.WriteLine(Environment.NewLine); } } while (response != ConsoleKey.Y && response != ConsoleKey.N); if (response == ConsoleKey.Y) { Console.WriteLine(outputService.PrepareCacheOutput()); } } catch { Console.WriteLine("Error"); } }