public void Format_WithThreeAndTwoSpacing_ReturnsProperlySpacedString() { var f = new WordSearchFormatter(new DummySolutionFormatter(), 3, 2); var expected = "a b c\n\n\nd e f\n\n\ng h i\n\n\nj k l"; Assert.Equal(expected, f.Format(ThreeByFourWordSearch())); }
public void FormatWithSolutions_WithSingleCharFormatterTooLittleSpacing_ThrowsProperException() { var f = new WordSearchFormatter(new ParenthesesSolutionFormatter(), 0); var location = new WordLocation(0, 0, 1, 1, 3); var e = Assert.Throws <FormatException>(() => f.Format(ThreeByFourWordSearch(), new[] { location })); Assert.Equal(WordSearchFormatter.TooLittleSpacingError, e.Message); }
public void FormatWithSolutions_WithSingleCharFormatterWithOneSolution_FormatsCorrectly() { var f = new WordSearchFormatter(new TestSolutionFormatter()); var expected = "* b c\nd * f\ng h *\nj k l"; var location = new WordLocation(0, 0, 1, 1, 3); Assert.Equal(expected, f.Format(ThreeByFourWordSearch(), new [] { location })); }
public WordSearchSolverConsole(WordSearch wordSearch, IEnumerable <string> words, bool allowOverlapping, WordSearchFormatter formatter) { WordSearch = wordSearch; Words = words; AllowOverlapping = allowOverlapping; Formatter = formatter; }
public void FormatWithSolutions_WithSingleCharFormatterWithManySolutions_FormatsCorrectly() { var f = new WordSearchFormatter(new TestSolutionFormatter(), 0); var expected = "***de*\ng*ij*l\nm*o*qr\nstuvwx\nyz***d"; var words = new[] { "abc", "bhn", "fkp" }; var locations = new IterativeSolver(SixByFiveWordSearch(), words).Solve().Values.SelectMany(l => l); Assert.Equal(expected, f.Format(SixByFiveWordSearch(), locations)); }
public void FormatWithSolutions_WithLongFormatterTooLittleSpacing_ThrowsProperException() { var f = new WordSearchFormatter(new TestSolutionFormatter { Length = 21 }, 9); var location = new WordLocation(0, 0, 1, 1, 3); var e = Assert.Throws <FormatException>(() => f.Format(ThreeByFourWordSearch(), new[] { location })); Assert.Equal(WordSearchFormatter.TooLittleSpacingError, e.Message); }
public void UsedWithFormatter_WithTooLittleSpace_ThrowsProperException() { var f = new WordSearchFormatter(new ParenthesesSolutionFormatter(), 0); var locations = new[] { new WordLocation(0, 3, 1, 1, 3), new WordLocation(1, 2, 0, 1, 4), new WordLocation(1, 1, 1, 1, 3) }; var e = Assert.Throws <FormatException>(() => f.Format(SixByFiveWordSearch(), locations)); Assert.Equal(WordSearchFormatter.TooLittleSpacingError, e.Message); }
public void FormatWithSolutions_WithLongFormatter_FormatsCorrectly() { var f = new WordSearchFormatter(new TestSolutionFormatter { Length = 3 }, 3); var location = new WordLocation(0, 0, 1, 1, 3); var expected = "*** b c\n" + "d *** f\n" + "g h ***\n" + "j k l"; Assert.Equal(expected, f.Format(ThreeByFourWordSearch(), new[] { location })); }
public void FormatWithSolutions_WithEvenFormatter_PlacesSpaceAtBeginning() { var f = new WordSearchFormatter(new TestSolutionFormatter { Length = 2 }); var location = new WordLocation(0, 0, 1, 1, 3); var expected = "**b c\n" + "d** f\n" + "g h**\n" + "j k l"; Assert.Equal(expected, f.Format(ThreeByFourWordSearch(), new [] { location })); }
public void UsedWithFormatter_WithTypicalWordSearchWithValidSpacing_FormatsCorrectly() { var f = new WordSearchFormatter(new ParenthesesSolutionFormatter(), 2); var locations = new[] { new WordLocation(0, 3, 1, 1, 3), new WordLocation(1, 2, 0, 1, 4), new WordLocation(1, 1, 1, 1, 3) }; var expected = "a b c (d) e f\n" + "g (h)(i) j (k) l\n" + "m n (o) p q (r)\n" + "s t (u)(v) w x\n" + "y z (a) b c d"; Assert.Equal(expected, f.Format(SixByFiveWordSearch(), locations)); }
private static void Launch(Options options) { var wordSearch = GetWordSearchSafe(options); if (wordSearch == null) { return; } var words = GetWordsSafe(options); if (words == null) { return; } var solutionFormatter = options.GetSolutionFormatter(); if (solutionFormatter == null) { return; } try { var f = new WordSearchFormatter(solutionFormatter, options.HSpace, options.VSpace); var w = new WordSearchSolverConsole(wordSearch, words, options.AllowOverlapping, f); if (w.Confirm()) { Console.WriteLine(); w.Launch(); } } catch (Exception e) { ErrorHandler.HandleUnknownException(e); } }