From 588d798f9379dd542801eb8cd46ba8ffa73d40e9 Mon Sep 17 00:00:00 2001 From: Erik Schierboom Date: Wed, 5 Feb 2025 15:57:15 +0100 Subject: [PATCH] word-search: add generator --- .../practice/word-search/.meta/Generator.tpl | 32 ++ .../practice/word-search/WordSearchTests.cs | 372 ++++++------------ 2 files changed, 154 insertions(+), 250 deletions(-) create mode 100644 exercises/practice/word-search/.meta/Generator.tpl diff --git a/exercises/practice/word-search/.meta/Generator.tpl b/exercises/practice/word-search/.meta/Generator.tpl new file mode 100644 index 0000000000..db3e18069e --- /dev/null +++ b/exercises/practice/word-search/.meta/Generator.tpl @@ -0,0 +1,32 @@ +{{ func tuple + ret $"({$0.column}, {$0.row})" +end }} +using Xunit; + +public class {{ testClass }} +{ + {{- for test in tests }} + [Fact{{ if !for.first }}(Skip = "Remove this Skip property to run this test"){{ end }}] + public void {{ test.testMethod }}() + { + string[] wordsToSearchFor = {{ test.input.wordsToSearchFor }}; + var grid = + {{- for line in test.input.grid }} + {{ if for.last -}} + {{ line | string.literal -}}; + {{- else -}} + {{ line | string.append "\n" | string.literal }} + + {{- end -}} + {{- end }} + var sut = new {{ testedClass }}(grid); + var actual = sut.Search(wordsToSearchFor); + {{- for key in test.expected | object.keys }} + {{- if test.expected[key] }} + Assert.Equal(({{ test.expected[key].start | tuple }}, {{ test.expected[key].end | tuple }}), actual[{{ key | string.literal }}]); + {{- else }} + Assert.Null(actual[{{ key | string.literal }}]); + {{ end -}} + {{ end -}} + } + {{ end -}} +} diff --git a/exercises/practice/word-search/WordSearchTests.cs b/exercises/practice/word-search/WordSearchTests.cs index 5acd188360..f1064b5e2d 100644 --- a/exercises/practice/word-search/WordSearchTests.cs +++ b/exercises/practice/word-search/WordSearchTests.cs @@ -1,5 +1,3 @@ -using System; -using System.Collections.Generic; using Xunit; public class WordSearchTests @@ -7,111 +5,88 @@ public class WordSearchTests [Fact] public void Should_accept_an_initial_game_grid_and_a_target_search_word() { - var wordsToSearchFor = new[] { "clojure" }; - var grid = "jefblpepre"; + string[] wordsToSearchFor = ["clojure"]; + var grid = + "jefblpepre"; var sut = new WordSearch(grid); var actual = sut.Search(wordsToSearchFor); - var expected = new Dictionary - { - ["clojure"] = null - }; - Assert.Equal(expected["clojure"], actual["clojure"]); + Assert.Null(actual["clojure"]); } [Fact(Skip = "Remove this Skip property to run this test")] public void Should_locate_one_word_written_left_to_right() { - var wordsToSearchFor = new[] { "clojure" }; - var grid = "clojurermt"; + string[] wordsToSearchFor = ["clojure"]; + var grid = + "clojurermt"; var sut = new WordSearch(grid); var actual = sut.Search(wordsToSearchFor); - var expected = new Dictionary - { - ["clojure"] = ((1, 1), (7, 1)) - }; - Assert.Equal(expected["clojure"], actual["clojure"]); + Assert.Equal(((1, 1), (7, 1)), actual["clojure"]); } [Fact(Skip = "Remove this Skip property to run this test")] public void Should_locate_the_same_word_written_left_to_right_in_a_different_position() { - var wordsToSearchFor = new[] { "clojure" }; - var grid = "mtclojurer"; + string[] wordsToSearchFor = ["clojure"]; + var grid = + "mtclojurer"; var sut = new WordSearch(grid); var actual = sut.Search(wordsToSearchFor); - var expected = new Dictionary - { - ["clojure"] = ((3, 1), (9, 1)) - }; - Assert.Equal(expected["clojure"], actual["clojure"]); + Assert.Equal(((3, 1), (9, 1)), actual["clojure"]); } [Fact(Skip = "Remove this Skip property to run this test")] public void Should_locate_a_different_left_to_right_word() { - var wordsToSearchFor = new[] { "coffee" }; - var grid = "coffeelplx"; + string[] wordsToSearchFor = ["coffee"]; + var grid = + "coffeelplx"; var sut = new WordSearch(grid); var actual = sut.Search(wordsToSearchFor); - var expected = new Dictionary - { - ["coffee"] = ((1, 1), (6, 1)) - }; - Assert.Equal(expected["coffee"], actual["coffee"]); + Assert.Equal(((1, 1), (6, 1)), actual["coffee"]); } [Fact(Skip = "Remove this Skip property to run this test")] public void Should_locate_that_different_left_to_right_word_in_a_different_position() { - var wordsToSearchFor = new[] { "coffee" }; - var grid = "xcoffeezlp"; + string[] wordsToSearchFor = ["coffee"]; + var grid = + "xcoffeezlp"; var sut = new WordSearch(grid); var actual = sut.Search(wordsToSearchFor); - var expected = new Dictionary - { - ["coffee"] = ((2, 1), (7, 1)) - }; - Assert.Equal(expected["coffee"], actual["coffee"]); + Assert.Equal(((2, 1), (7, 1)), actual["coffee"]); } [Fact(Skip = "Remove this Skip property to run this test")] public void Should_locate_a_left_to_right_word_in_two_line_grid() { - var wordsToSearchFor = new[] { "clojure" }; - var grid = + string[] wordsToSearchFor = ["clojure"]; + var grid = "jefblpepre\n" + "tclojurerm"; var sut = new WordSearch(grid); var actual = sut.Search(wordsToSearchFor); - var expected = new Dictionary - { - ["clojure"] = ((2, 2), (8, 2)) - }; - Assert.Equal(expected["clojure"], actual["clojure"]); + Assert.Equal(((2, 2), (8, 2)), actual["clojure"]); } [Fact(Skip = "Remove this Skip property to run this test")] public void Should_locate_a_left_to_right_word_in_three_line_grid() { - var wordsToSearchFor = new[] { "clojure" }; - var grid = + string[] wordsToSearchFor = ["clojure"]; + var grid = "camdcimgtc\n" + "jefblpepre\n" + "clojurermt"; var sut = new WordSearch(grid); var actual = sut.Search(wordsToSearchFor); - var expected = new Dictionary - { - ["clojure"] = ((1, 3), (7, 3)) - }; - Assert.Equal(expected["clojure"], actual["clojure"]); + Assert.Equal(((1, 3), (7, 3)), actual["clojure"]); } [Fact(Skip = "Remove this Skip property to run this test")] public void Should_locate_a_left_to_right_word_in_ten_line_grid() { - var wordsToSearchFor = new[] { "clojure" }; - var grid = + string[] wordsToSearchFor = ["clojure"]; + var grid = "jefblpepre\n" + "camdcimgtc\n" + "oivokprjsm\n" + @@ -124,18 +99,14 @@ public void Should_locate_a_left_to_right_word_in_ten_line_grid() "clojurermt"; var sut = new WordSearch(grid); var actual = sut.Search(wordsToSearchFor); - var expected = new Dictionary - { - ["clojure"] = ((1, 10), (7, 10)) - }; - Assert.Equal(expected["clojure"], actual["clojure"]); + Assert.Equal(((1, 10), (7, 10)), actual["clojure"]); } [Fact(Skip = "Remove this Skip property to run this test")] public void Should_locate_that_left_to_right_word_in_a_different_position_in_a_ten_line_grid() { - var wordsToSearchFor = new[] { "clojure" }; - var grid = + string[] wordsToSearchFor = ["clojure"]; + var grid = "jefblpepre\n" + "camdcimgtc\n" + "oivokprjsm\n" + @@ -148,18 +119,14 @@ public void Should_locate_that_left_to_right_word_in_a_different_position_in_a_t "jalaycalmp"; var sut = new WordSearch(grid); var actual = sut.Search(wordsToSearchFor); - var expected = new Dictionary - { - ["clojure"] = ((1, 9), (7, 9)) - }; - Assert.Equal(expected["clojure"], actual["clojure"]); + Assert.Equal(((1, 9), (7, 9)), actual["clojure"]); } [Fact(Skip = "Remove this Skip property to run this test")] public void Should_locate_a_different_left_to_right_word_in_a_ten_line_grid() { - var wordsToSearchFor = new[] { "fortran" }; - var grid = + string[] wordsToSearchFor = ["fortran"]; + var grid = "jefblpepre\n" + "camdcimgtc\n" + "oivokprjsm\n" + @@ -172,18 +139,14 @@ public void Should_locate_a_different_left_to_right_word_in_a_ten_line_grid() "jalaycalmp"; var sut = new WordSearch(grid); var actual = sut.Search(wordsToSearchFor); - var expected = new Dictionary - { - ["fortran"] = ((1, 7), (7, 7)) - }; - Assert.Equal(expected["fortran"], actual["fortran"]); + Assert.Equal(((1, 7), (7, 7)), actual["fortran"]); } [Fact(Skip = "Remove this Skip property to run this test")] public void Should_locate_multiple_words() { - var wordsToSearchFor = new[] { "fortran", "clojure" }; - var grid = + string[] wordsToSearchFor = ["fortran", "clojure"]; + var grid = "jefblpepre\n" + "camdcimgtc\n" + "oivokprjsm\n" + @@ -196,34 +159,26 @@ public void Should_locate_multiple_words() "clojurermt"; var sut = new WordSearch(grid); var actual = sut.Search(wordsToSearchFor); - var expected = new Dictionary - { - ["clojure"] = ((1, 10), (7, 10)), - ["fortran"] = ((1, 7), (7, 7)) - }; - Assert.Equal(expected["clojure"], actual["clojure"]); - Assert.Equal(expected["fortran"], actual["fortran"]); + Assert.Equal(((1, 10), (7, 10)), actual["clojure"]); + Assert.Equal(((1, 7), (7, 7)), actual["fortran"]); } [Fact(Skip = "Remove this Skip property to run this test")] public void Should_locate_a_single_word_written_right_to_left() { - var wordsToSearchFor = new[] { "elixir" }; - var grid = "rixilelhrs"; + string[] wordsToSearchFor = ["elixir"]; + var grid = + "rixilelhrs"; var sut = new WordSearch(grid); var actual = sut.Search(wordsToSearchFor); - var expected = new Dictionary - { - ["elixir"] = ((6, 1), (1, 1)) - }; - Assert.Equal(expected["elixir"], actual["elixir"]); + Assert.Equal(((6, 1), (1, 1)), actual["elixir"]); } [Fact(Skip = "Remove this Skip property to run this test")] public void Should_locate_multiple_words_written_in_different_horizontal_directions() { - var wordsToSearchFor = new[] { "elixir", "clojure" }; - var grid = + string[] wordsToSearchFor = ["elixir", "clojure"]; + var grid = "jefblpepre\n" + "camdcimgtc\n" + "oivokprjsm\n" + @@ -236,20 +191,15 @@ public void Should_locate_multiple_words_written_in_different_horizontal_directi "clojurermt"; var sut = new WordSearch(grid); var actual = sut.Search(wordsToSearchFor); - var expected = new Dictionary - { - ["clojure"] = ((1, 10), (7, 10)), - ["elixir"] = ((6, 5), (1, 5)) - }; - Assert.Equal(expected["clojure"], actual["clojure"]); - Assert.Equal(expected["elixir"], actual["elixir"]); + Assert.Equal(((1, 10), (7, 10)), actual["clojure"]); + Assert.Equal(((6, 5), (1, 5)), actual["elixir"]); } [Fact(Skip = "Remove this Skip property to run this test")] public void Should_locate_words_written_top_to_bottom() { - var wordsToSearchFor = new[] { "clojure", "elixir", "ecmascript" }; - var grid = + string[] wordsToSearchFor = ["clojure", "elixir", "ecmascript"]; + var grid = "jefblpepre\n" + "camdcimgtc\n" + "oivokprjsm\n" + @@ -262,22 +212,16 @@ public void Should_locate_words_written_top_to_bottom() "clojurermt"; var sut = new WordSearch(grid); var actual = sut.Search(wordsToSearchFor); - var expected = new Dictionary - { - ["clojure"] = ((1, 10), (7, 10)), - ["elixir"] = ((6, 5), (1, 5)), - ["ecmascript"] = ((10, 1), (10, 10)) - }; - Assert.Equal(expected["clojure"], actual["clojure"]); - Assert.Equal(expected["elixir"], actual["elixir"]); - Assert.Equal(expected["ecmascript"], actual["ecmascript"]); + Assert.Equal(((1, 10), (7, 10)), actual["clojure"]); + Assert.Equal(((6, 5), (1, 5)), actual["elixir"]); + Assert.Equal(((10, 1), (10, 10)), actual["ecmascript"]); } [Fact(Skip = "Remove this Skip property to run this test")] public void Should_locate_words_written_bottom_to_top() { - var wordsToSearchFor = new[] { "clojure", "elixir", "ecmascript", "rust" }; - var grid = + string[] wordsToSearchFor = ["clojure", "elixir", "ecmascript", "rust"]; + var grid = "jefblpepre\n" + "camdcimgtc\n" + "oivokprjsm\n" + @@ -290,24 +234,17 @@ public void Should_locate_words_written_bottom_to_top() "clojurermt"; var sut = new WordSearch(grid); var actual = sut.Search(wordsToSearchFor); - var expected = new Dictionary - { - ["clojure"] = ((1, 10), (7, 10)), - ["elixir"] = ((6, 5), (1, 5)), - ["ecmascript"] = ((10, 1), (10, 10)), - ["rust"] = ((9, 5), (9, 2)) - }; - Assert.Equal(expected["clojure"], actual["clojure"]); - Assert.Equal(expected["elixir"], actual["elixir"]); - Assert.Equal(expected["ecmascript"], actual["ecmascript"]); - Assert.Equal(expected["rust"], actual["rust"]); + Assert.Equal(((1, 10), (7, 10)), actual["clojure"]); + Assert.Equal(((6, 5), (1, 5)), actual["elixir"]); + Assert.Equal(((10, 1), (10, 10)), actual["ecmascript"]); + Assert.Equal(((9, 5), (9, 2)), actual["rust"]); } [Fact(Skip = "Remove this Skip property to run this test")] public void Should_locate_words_written_top_left_to_bottom_right() { - var wordsToSearchFor = new[] { "clojure", "elixir", "ecmascript", "rust", "java" }; - var grid = + string[] wordsToSearchFor = ["clojure", "elixir", "ecmascript", "rust", "java"]; + var grid = "jefblpepre\n" + "camdcimgtc\n" + "oivokprjsm\n" + @@ -320,26 +257,18 @@ public void Should_locate_words_written_top_left_to_bottom_right() "clojurermt"; var sut = new WordSearch(grid); var actual = sut.Search(wordsToSearchFor); - var expected = new Dictionary - { - ["clojure"] = ((1, 10), (7, 10)), - ["elixir"] = ((6, 5), (1, 5)), - ["ecmascript"] = ((10, 1), (10, 10)), - ["rust"] = ((9, 5), (9, 2)), - ["java"] = ((1, 1), (4, 4)) - }; - Assert.Equal(expected["clojure"], actual["clojure"]); - Assert.Equal(expected["elixir"], actual["elixir"]); - Assert.Equal(expected["ecmascript"], actual["ecmascript"]); - Assert.Equal(expected["rust"], actual["rust"]); - Assert.Equal(expected["java"], actual["java"]); + Assert.Equal(((1, 10), (7, 10)), actual["clojure"]); + Assert.Equal(((6, 5), (1, 5)), actual["elixir"]); + Assert.Equal(((10, 1), (10, 10)), actual["ecmascript"]); + Assert.Equal(((9, 5), (9, 2)), actual["rust"]); + Assert.Equal(((1, 1), (4, 4)), actual["java"]); } [Fact(Skip = "Remove this Skip property to run this test")] public void Should_locate_words_written_bottom_right_to_top_left() { - var wordsToSearchFor = new[] { "clojure", "elixir", "ecmascript", "rust", "java", "lua" }; - var grid = + string[] wordsToSearchFor = ["clojure", "elixir", "ecmascript", "rust", "java", "lua"]; + var grid = "jefblpepre\n" + "camdcimgtc\n" + "oivokprjsm\n" + @@ -352,28 +281,19 @@ public void Should_locate_words_written_bottom_right_to_top_left() "clojurermt"; var sut = new WordSearch(grid); var actual = sut.Search(wordsToSearchFor); - var expected = new Dictionary - { - ["clojure"] = ((1, 10), (7, 10)), - ["elixir"] = ((6, 5), (1, 5)), - ["ecmascript"] = ((10, 1), (10, 10)), - ["rust"] = ((9, 5), (9, 2)), - ["java"] = ((1, 1), (4, 4)), - ["lua"] = ((8, 9), (6, 7)) - }; - Assert.Equal(expected["clojure"], actual["clojure"]); - Assert.Equal(expected["elixir"], actual["elixir"]); - Assert.Equal(expected["ecmascript"], actual["ecmascript"]); - Assert.Equal(expected["rust"], actual["rust"]); - Assert.Equal(expected["java"], actual["java"]); - Assert.Equal(expected["lua"], actual["lua"]); + Assert.Equal(((1, 10), (7, 10)), actual["clojure"]); + Assert.Equal(((6, 5), (1, 5)), actual["elixir"]); + Assert.Equal(((10, 1), (10, 10)), actual["ecmascript"]); + Assert.Equal(((9, 5), (9, 2)), actual["rust"]); + Assert.Equal(((1, 1), (4, 4)), actual["java"]); + Assert.Equal(((8, 9), (6, 7)), actual["lua"]); } [Fact(Skip = "Remove this Skip property to run this test")] public void Should_locate_words_written_bottom_left_to_top_right() { - var wordsToSearchFor = new[] { "clojure", "elixir", "ecmascript", "rust", "java", "lua", "lisp" }; - var grid = + string[] wordsToSearchFor = ["clojure", "elixir", "ecmascript", "rust", "java", "lua", "lisp"]; + var grid = "jefblpepre\n" + "camdcimgtc\n" + "oivokprjsm\n" + @@ -386,30 +306,20 @@ public void Should_locate_words_written_bottom_left_to_top_right() "clojurermt"; var sut = new WordSearch(grid); var actual = sut.Search(wordsToSearchFor); - var expected = new Dictionary - { - ["clojure"] = ((1, 10), (7, 10)), - ["elixir"] = ((6, 5), (1, 5)), - ["ecmascript"] = ((10, 1), (10, 10)), - ["rust"] = ((9, 5), (9, 2)), - ["java"] = ((1, 1), (4, 4)), - ["lua"] = ((8, 9), (6, 7)), - ["lisp"] = ((3, 6), (6, 3)) - }; - Assert.Equal(expected["clojure"], actual["clojure"]); - Assert.Equal(expected["elixir"], actual["elixir"]); - Assert.Equal(expected["ecmascript"], actual["ecmascript"]); - Assert.Equal(expected["rust"], actual["rust"]); - Assert.Equal(expected["java"], actual["java"]); - Assert.Equal(expected["lua"], actual["lua"]); - Assert.Equal(expected["lisp"], actual["lisp"]); + Assert.Equal(((1, 10), (7, 10)), actual["clojure"]); + Assert.Equal(((6, 5), (1, 5)), actual["elixir"]); + Assert.Equal(((10, 1), (10, 10)), actual["ecmascript"]); + Assert.Equal(((9, 5), (9, 2)), actual["rust"]); + Assert.Equal(((1, 1), (4, 4)), actual["java"]); + Assert.Equal(((8, 9), (6, 7)), actual["lua"]); + Assert.Equal(((3, 6), (6, 3)), actual["lisp"]); } [Fact(Skip = "Remove this Skip property to run this test")] public void Should_locate_words_written_top_right_to_bottom_left() { - var wordsToSearchFor = new[] { "clojure", "elixir", "ecmascript", "rust", "java", "lua", "lisp", "ruby" }; - var grid = + string[] wordsToSearchFor = ["clojure", "elixir", "ecmascript", "rust", "java", "lua", "lisp", "ruby"]; + var grid = "jefblpepre\n" + "camdcimgtc\n" + "oivokprjsm\n" + @@ -422,32 +332,21 @@ public void Should_locate_words_written_top_right_to_bottom_left() "clojurermt"; var sut = new WordSearch(grid); var actual = sut.Search(wordsToSearchFor); - var expected = new Dictionary - { - ["clojure"] = ((1, 10), (7, 10)), - ["elixir"] = ((6, 5), (1, 5)), - ["ecmascript"] = ((10, 1), (10, 10)), - ["rust"] = ((9, 5), (9, 2)), - ["java"] = ((1, 1), (4, 4)), - ["lua"] = ((8, 9), (6, 7)), - ["lisp"] = ((3, 6), (6, 3)), - ["ruby"] = ((8, 6), (5, 9)) - }; - Assert.Equal(expected["clojure"], actual["clojure"]); - Assert.Equal(expected["elixir"], actual["elixir"]); - Assert.Equal(expected["ecmascript"], actual["ecmascript"]); - Assert.Equal(expected["rust"], actual["rust"]); - Assert.Equal(expected["java"], actual["java"]); - Assert.Equal(expected["lua"], actual["lua"]); - Assert.Equal(expected["lisp"], actual["lisp"]); - Assert.Equal(expected["ruby"], actual["ruby"]); + Assert.Equal(((1, 10), (7, 10)), actual["clojure"]); + Assert.Equal(((6, 5), (1, 5)), actual["elixir"]); + Assert.Equal(((10, 1), (10, 10)), actual["ecmascript"]); + Assert.Equal(((9, 5), (9, 2)), actual["rust"]); + Assert.Equal(((1, 1), (4, 4)), actual["java"]); + Assert.Equal(((8, 9), (6, 7)), actual["lua"]); + Assert.Equal(((3, 6), (6, 3)), actual["lisp"]); + Assert.Equal(((8, 6), (5, 9)), actual["ruby"]); } [Fact(Skip = "Remove this Skip property to run this test")] public void Should_fail_to_locate_a_word_that_is_not_in_the_puzzle() { - var wordsToSearchFor = new[] { "clojure", "elixir", "ecmascript", "rust", "java", "lua", "lisp", "ruby", "haskell" }; - var grid = + string[] wordsToSearchFor = ["clojure", "elixir", "ecmascript", "rust", "java", "lua", "lisp", "ruby", "haskell"]; + var grid = "jefblpepre\n" + "camdcimgtc\n" + "oivokprjsm\n" + @@ -460,86 +359,63 @@ public void Should_fail_to_locate_a_word_that_is_not_in_the_puzzle() "clojurermt"; var sut = new WordSearch(grid); var actual = sut.Search(wordsToSearchFor); - var expected = new Dictionary - { - ["clojure"] = ((1, 10), (7, 10)), - ["elixir"] = ((6, 5), (1, 5)), - ["ecmascript"] = ((10, 1), (10, 10)), - ["rust"] = ((9, 5), (9, 2)), - ["java"] = ((1, 1), (4, 4)), - ["lua"] = ((8, 9), (6, 7)), - ["lisp"] = ((3, 6), (6, 3)), - ["ruby"] = ((8, 6), (5, 9)), - ["haskell"] = null - }; - Assert.Equal(expected["clojure"], actual["clojure"]); - Assert.Equal(expected["elixir"], actual["elixir"]); - Assert.Equal(expected["ecmascript"], actual["ecmascript"]); - Assert.Equal(expected["rust"], actual["rust"]); - Assert.Equal(expected["java"], actual["java"]); - Assert.Equal(expected["lua"], actual["lua"]); - Assert.Equal(expected["lisp"], actual["lisp"]); - Assert.Equal(expected["ruby"], actual["ruby"]); - Assert.Equal(expected["haskell"], actual["haskell"]); + Assert.Equal(((1, 10), (7, 10)), actual["clojure"]); + Assert.Equal(((6, 5), (1, 5)), actual["elixir"]); + Assert.Equal(((10, 1), (10, 10)), actual["ecmascript"]); + Assert.Equal(((9, 5), (9, 2)), actual["rust"]); + Assert.Equal(((1, 1), (4, 4)), actual["java"]); + Assert.Equal(((8, 9), (6, 7)), actual["lua"]); + Assert.Equal(((3, 6), (6, 3)), actual["lisp"]); + Assert.Equal(((8, 6), (5, 9)), actual["ruby"]); + Assert.Null(actual["haskell"]); } [Fact(Skip = "Remove this Skip property to run this test")] public void Should_fail_to_locate_words_that_are_not_on_horizontal_vertical_or_diagonal_lines() { - var wordsToSearchFor = new[] { "aef", "ced", "abf", "cbd" }; - var grid = + string[] wordsToSearchFor = ["aef", "ced", "abf", "cbd"]; + var grid = "abc\n" + "def"; var sut = new WordSearch(grid); var actual = sut.Search(wordsToSearchFor); - var expected = new Dictionary - { - ["aef"] = null, - ["ced"] = null, - ["abf"] = null, - ["cbd"] = null - }; - Assert.Equal(expected["aef"], actual["aef"]); - Assert.Equal(expected["ced"], actual["ced"]); - Assert.Equal(expected["abf"], actual["abf"]); - Assert.Equal(expected["cbd"], actual["cbd"]); + Assert.Null(actual["aef"]); + + Assert.Null(actual["ced"]); + + Assert.Null(actual["abf"]); + + Assert.Null(actual["cbd"]); } [Fact(Skip = "Remove this Skip property to run this test")] public void Should_not_concatenate_different_lines_to_find_a_horizontal_word() { - var wordsToSearchFor = new[] { "elixir" }; - var grid = + string[] wordsToSearchFor = ["elixir"]; + var grid = "abceli\n" + "xirdfg"; var sut = new WordSearch(grid); var actual = sut.Search(wordsToSearchFor); - var expected = new Dictionary - { - ["elixir"] = null - }; - Assert.Equal(expected["elixir"], actual["elixir"]); + Assert.Null(actual["elixir"]); } [Fact(Skip = "Remove this Skip property to run this test")] public void Should_not_wrap_around_horizontally_to_find_a_word() { - var wordsToSearchFor = new[] { "lisp" }; - var grid = "silabcdefp"; + string[] wordsToSearchFor = ["lisp"]; + var grid = + "silabcdefp"; var sut = new WordSearch(grid); var actual = sut.Search(wordsToSearchFor); - var expected = new Dictionary - { - ["lisp"] = null - }; - Assert.Equal(expected["lisp"], actual["lisp"]); + Assert.Null(actual["lisp"]); } [Fact(Skip = "Remove this Skip property to run this test")] public void Should_not_wrap_around_vertically_to_find_a_word() { - var wordsToSearchFor = new[] { "rust" }; - var grid = + string[] wordsToSearchFor = ["rust"]; + var grid = "s\n" + "u\n" + "r\n" + @@ -549,10 +425,6 @@ public void Should_not_wrap_around_vertically_to_find_a_word() "t"; var sut = new WordSearch(grid); var actual = sut.Search(wordsToSearchFor); - var expected = new Dictionary - { - ["rust"] = null - }; - Assert.Equal(expected["rust"], actual["rust"]); + Assert.Null(actual["rust"]); } }