|
| 1 | +package wordsearch |
| 2 | + |
| 3 | +// Source: exercism/problem-specifications |
| 4 | +// Commit: c741e35 Add tests to support TDD workflow (#899) |
| 5 | +// Problem Specifications Version: 1.1.0 |
| 6 | + |
| 7 | +var testCases = []struct { |
| 8 | + description string |
| 9 | + puzzle []string // puzzle strings |
| 10 | + words []string // words to search for |
| 11 | + expected map[string][2][2]int // expected coordinates |
| 12 | + expectError bool |
| 13 | +}{ |
| 14 | + { |
| 15 | + "Should accept an initial game grid and a target search word", |
| 16 | + []string{"jefblpepre"}, |
| 17 | + []string{"clojure"}, |
| 18 | + map[string][2][2]int{}, |
| 19 | + true, |
| 20 | + }, |
| 21 | + { |
| 22 | + "Should locate one word written left to right", |
| 23 | + []string{"clojurermt"}, |
| 24 | + []string{"clojure"}, |
| 25 | + map[string][2][2]int{"clojure": {{0, 0}, {6, 0}}}, |
| 26 | + false, |
| 27 | + }, |
| 28 | + { |
| 29 | + "Should locate the same word written left to right in a different position", |
| 30 | + []string{"mtclojurer"}, |
| 31 | + []string{"clojure"}, |
| 32 | + map[string][2][2]int{"clojure": {{2, 0}, {8, 0}}}, |
| 33 | + false, |
| 34 | + }, |
| 35 | + { |
| 36 | + "Should locate a different left to right word", |
| 37 | + []string{"coffeelplx"}, |
| 38 | + []string{"coffee"}, |
| 39 | + map[string][2][2]int{"coffee": {{0, 0}, {5, 0}}}, |
| 40 | + false, |
| 41 | + }, |
| 42 | + { |
| 43 | + "Should locate that different left to right word in a different position", |
| 44 | + []string{"xcoffeezlp"}, |
| 45 | + []string{"coffee"}, |
| 46 | + map[string][2][2]int{"coffee": {{1, 0}, {6, 0}}}, |
| 47 | + false, |
| 48 | + }, |
| 49 | + { |
| 50 | + "Should locate a left to right word in two line grid", |
| 51 | + []string{"jefblpepre", "tclojurerm"}, |
| 52 | + []string{"clojure"}, |
| 53 | + map[string][2][2]int{"clojure": {{1, 1}, {7, 1}}}, |
| 54 | + false, |
| 55 | + }, |
| 56 | + { |
| 57 | + "Should locate a left to right word in three line grid", |
| 58 | + []string{"camdcimgtc", "jefblpepre", "clojurermt"}, |
| 59 | + []string{"clojure"}, |
| 60 | + map[string][2][2]int{"clojure": {{0, 2}, {6, 2}}}, |
| 61 | + false, |
| 62 | + }, |
| 63 | + { |
| 64 | + "Should locate a left to right word in ten line grid", |
| 65 | + []string{"jefblpepre", "camdcimgtc", "oivokprjsm", "pbwasqroua", "rixilelhrs", "wolcqlirpc", "screeaumgr", "alxhpburyi", "jalaycalmp", "clojurermt"}, |
| 66 | + []string{"clojure"}, |
| 67 | + map[string][2][2]int{"clojure": {{0, 9}, {6, 9}}}, |
| 68 | + false, |
| 69 | + }, |
| 70 | + { |
| 71 | + "Should locate that left to right word in a different position in a ten line grid", |
| 72 | + []string{"jefblpepre", "camdcimgtc", "oivokprjsm", "pbwasqroua", "rixilelhrs", "wolcqlirpc", "screeaumgr", "alxhpburyi", "clojurermt", "jalaycalmp"}, |
| 73 | + []string{"clojure"}, |
| 74 | + map[string][2][2]int{"clojure": {{0, 8}, {6, 8}}}, |
| 75 | + false, |
| 76 | + }, |
| 77 | + { |
| 78 | + "Should locate a different left to right word in a ten line grid", |
| 79 | + []string{"jefblpepre", "camdcimgtc", "oivokprjsm", "pbwasqroua", "rixilelhrs", "wolcqlirpc", "fortranftw", "alxhpburyi", "clojurermt", "jalaycalmp"}, |
| 80 | + []string{"fortran"}, |
| 81 | + map[string][2][2]int{"fortran": {{0, 6}, {6, 6}}}, |
| 82 | + false, |
| 83 | + }, |
| 84 | + { |
| 85 | + "Should locate multiple words", |
| 86 | + []string{"jefblpepre", "camdcimgtc", "oivokprjsm", "pbwasqroua", "rixilelhrs", "wolcqlirpc", "fortranftw", "alxhpburyi", "jalaycalmp", "clojurermt"}, |
| 87 | + []string{"fortran", "clojure"}, |
| 88 | + map[string][2][2]int{"clojure": {{0, 9}, {6, 9}}, "fortran": {{0, 6}, {6, 6}}}, |
| 89 | + false, |
| 90 | + }, |
| 91 | + { |
| 92 | + "Should locate a single word written right to left", |
| 93 | + []string{"rixilelhrs"}, |
| 94 | + []string{"elixir"}, |
| 95 | + map[string][2][2]int{"elixir": {{5, 0}, {0, 0}}}, |
| 96 | + false, |
| 97 | + }, |
| 98 | + { |
| 99 | + "Should locate multiple words written in different horizontal directions", |
| 100 | + []string{"jefblpepre", "camdcimgtc", "oivokprjsm", "pbwasqroua", "rixilelhrs", "wolcqlirpc", "screeaumgr", "alxhpburyi", "jalaycalmp", "clojurermt"}, |
| 101 | + []string{"elixir", "clojure"}, |
| 102 | + map[string][2][2]int{"clojure": {{0, 9}, {6, 9}}, "elixir": {{5, 4}, {0, 4}}}, |
| 103 | + false, |
| 104 | + }, |
| 105 | + { |
| 106 | + "Should locate words written top to bottom", |
| 107 | + []string{"jefblpepre", "camdcimgtc", "oivokprjsm", "pbwasqroua", "rixilelhrs", "wolcqlirpc", "screeaumgr", "alxhpburyi", "jalaycalmp", "clojurermt"}, |
| 108 | + []string{"clojure", "elixir", "ecmascript"}, |
| 109 | + map[string][2][2]int{"clojure": {{0, 9}, {6, 9}}, "ecmascript": {{9, 0}, {9, 9}}, "elixir": {{5, 4}, {0, 4}}}, |
| 110 | + false, |
| 111 | + }, |
| 112 | + { |
| 113 | + "Should locate words written bottom to top", |
| 114 | + []string{"jefblpepre", "camdcimgtc", "oivokprjsm", "pbwasqroua", "rixilelhrs", "wolcqlirpc", "screeaumgr", "alxhpburyi", "jalaycalmp", "clojurermt"}, |
| 115 | + []string{"clojure", "elixir", "ecmascript", "rust"}, |
| 116 | + map[string][2][2]int{"clojure": {{0, 9}, {6, 9}}, "ecmascript": {{9, 0}, {9, 9}}, "elixir": {{5, 4}, {0, 4}}, "rust": {{8, 4}, {8, 1}}}, |
| 117 | + false, |
| 118 | + }, |
| 119 | + { |
| 120 | + "Should locate words written top left to bottom right", |
| 121 | + []string{"jefblpepre", "camdcimgtc", "oivokprjsm", "pbwasqroua", "rixilelhrs", "wolcqlirpc", "screeaumgr", "alxhpburyi", "jalaycalmp", "clojurermt"}, |
| 122 | + []string{"clojure", "elixir", "ecmascript", "rust", "java"}, |
| 123 | + map[string][2][2]int{"clojure": {{0, 9}, {6, 9}}, "ecmascript": {{9, 0}, {9, 9}}, "elixir": {{5, 4}, {0, 4}}, "java": {{0, 0}, {3, 3}}, "rust": {{8, 4}, {8, 1}}}, |
| 124 | + false, |
| 125 | + }, |
| 126 | + { |
| 127 | + "Should locate words written bottom right to top left", |
| 128 | + []string{"jefblpepre", "camdcimgtc", "oivokprjsm", "pbwasqroua", "rixilelhrs", "wolcqlirpc", "screeaumgr", "alxhpburyi", "jalaycalmp", "clojurermt"}, |
| 129 | + []string{"clojure", "elixir", "ecmascript", "rust", "java", "lua"}, |
| 130 | + map[string][2][2]int{"clojure": {{0, 9}, {6, 9}}, "ecmascript": {{9, 0}, {9, 9}}, "elixir": {{5, 4}, {0, 4}}, "java": {{0, 0}, {3, 3}}, "lua": {{7, 8}, {5, 6}}, "rust": {{8, 4}, {8, 1}}}, |
| 131 | + false, |
| 132 | + }, |
| 133 | + { |
| 134 | + "Should locate words written bottom left to top right", |
| 135 | + []string{"jefblpepre", "camdcimgtc", "oivokprjsm", "pbwasqroua", "rixilelhrs", "wolcqlirpc", "screeaumgr", "alxhpburyi", "jalaycalmp", "clojurermt"}, |
| 136 | + []string{"clojure", "elixir", "ecmascript", "rust", "java", "lua", "lisp"}, |
| 137 | + map[string][2][2]int{"clojure": {{0, 9}, {6, 9}}, "ecmascript": {{9, 0}, {9, 9}}, "elixir": {{5, 4}, {0, 4}}, "java": {{0, 0}, {3, 3}}, "lisp": {{2, 5}, {5, 2}}, "lua": {{7, 8}, {5, 6}}, "rust": {{8, 4}, {8, 1}}}, |
| 138 | + false, |
| 139 | + }, |
| 140 | + { |
| 141 | + "Should locate words written top right to bottom left", |
| 142 | + []string{"jefblpepre", "camdcimgtc", "oivokprjsm", "pbwasqroua", "rixilelhrs", "wolcqlirpc", "screeaumgr", "alxhpburyi", "jalaycalmp", "clojurermt"}, |
| 143 | + []string{"clojure", "elixir", "ecmascript", "rust", "java", "lua", "lisp", "ruby"}, |
| 144 | + map[string][2][2]int{"clojure": {{0, 9}, {6, 9}}, "ecmascript": {{9, 0}, {9, 9}}, "elixir": {{5, 4}, {0, 4}}, "java": {{0, 0}, {3, 3}}, "lisp": {{2, 5}, {5, 2}}, "lua": {{7, 8}, {5, 6}}, "ruby": {{7, 5}, {4, 8}}, "rust": {{8, 4}, {8, 1}}}, |
| 145 | + false, |
| 146 | + }, |
| 147 | + { |
| 148 | + "Should fail to locate a word that is not in the puzzle", |
| 149 | + []string{"jefblpepre", "camdcimgtc", "oivokprjsm", "pbwasqroua", "rixilelhrs", "wolcqlirpc", "screeaumgr", "alxhpburyi", "jalaycalmp", "clojurermt"}, |
| 150 | + []string{"clojure", "elixir", "ecmascript", "rust", "java", "lua", "lisp", "ruby", "haskell"}, |
| 151 | + map[string][2][2]int{}, |
| 152 | + true, |
| 153 | + }, |
| 154 | +} |
0 commit comments