public void WriteContent_Success() { var input = new Stack <ICollection <string> >(); var inputResult = new List <string>(); inputResult.Add("spin"); inputResult.Add("spit"); inputResult.Add("spot"); input.Push(inputResult); var shortestPaths = ShortestPathsDTO.CreateFrom(input); _fileNavigationService.WriteContent(@"Resources\result.txt", shortestPaths); Assert.IsTrue(File.Exists(@"Resources\result.txt")); }
public void ToString_Success() { var input = new Stack <ICollection <string> >(); var inputResult1 = new List <string>(); inputResult1.Add("spin"); inputResult1.Add("spit"); inputResult1.Add("spot"); var inputResult2 = new List <string>(); inputResult2.Add("spot"); inputResult2.Add("spit"); inputResult2.Add("spin"); input.Push(inputResult1); input.Push(inputResult2); var shortestPaths = ShortestPathsDTO.CreateFrom(input).ToString(); var expectedResult = "[ spin -> spit -> spot ],\r\n[ spot -> spit -> spin ]\r\n"; Assert.IsTrue(shortestPaths != null); }
/// <summary> /// Executes the application /// </summary> /// <param name="options">The <see cref="Options"/> to be used in the execution</param> /// <param name="cancellationToken">The token to monitor for cancellation requests. The default value is <see cref="CancellationToken.None"/></param> /// <returns>A task that represents the execution of the application.</returns> private async Task ExecuteApplication(Options options, CancellationToken cancellationToken = default) { _log.LogInformation("Word Navigator v{version}", string.Format("{0}.{1}", Assembly.GetEntryAssembly().GetName().Version.Major, Assembly.GetEntryAssembly().GetName().Version.Minor)); var stopWatch = new Stopwatch(); stopWatch.Start(); var wordLength = _config.GetSection("WordLength"); if (wordLength.Value != null && !options.Start.Length.Equals(int.Parse(wordLength.Value))) { throw new LengthNotPermittedException(string.Format("Length of word {0} is different than the allowed value of {1}", options.Start, wordLength.Value)); } string sourcePath; if (options.Dictionary != null && !string.IsNullOrEmpty(options.Dictionary)) { sourcePath = options.Dictionary; } else { sourcePath = @"Resources\words-english.txt"; _log.LogInformation("No dictionary path were selected, using default: {sourcePath}", sourcePath); } IAsyncEnumerable <string> content = _fileNavigationService.ReadContentAsync(sourcePath, cancellationToken); //_log.LogDebug("Seeking for {target}", options.Target); Stack <ICollection <string> > shortestPaths = await _wordNavigationService.Seek(options.Start, options.Target, content, cancellationToken); var shortestPathsDto = ShortestPathsDTO.CreateFrom(shortestPaths); string outputPath; if (options.Output != null && !string.IsNullOrEmpty(options.Output)) { outputPath = options.Output; } else { outputPath = @"results.txt"; _log.LogInformation("No output file path was selected, using default: {outputPath}", outputPath); } _log.LogDebug("Writing result paths to {outputPath}", outputPath); await _fileNavigationService.WriteContentAsync(outputPath, shortestPathsDto, cancellationToken); stopWatch.Stop(); if (shortestPaths.Count == 0) { _log.LogInformation("There are no paths for this word combination."); } else { _log.LogInformation("All shortest paths:\r\n{shortestPathsDto}", shortestPathsDto.ToString()); } _log.LogInformation("The operation took {seconds} seconds", Math.Round(stopWatch.Elapsed.TotalSeconds, 3)); }