trackler 2.2.1.153 → 2.2.1.154

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/lib/trackler/version.rb +1 -1
  3. data/problem-specifications/exercises/grade-school/canonical-data.json +68 -0
  4. data/problem-specifications/exercises/luhn/canonical-data.json +9 -1
  5. data/problem-specifications/exercises/say/description.md +1 -1
  6. data/problem-specifications/exercises/word-search/canonical-data.json +2 -3
  7. data/tracks/csharp/exercises/go-counting/Example.cs +49 -42
  8. data/tracks/csharp/exercises/go-counting/GoCounting.cs +3 -3
  9. data/tracks/csharp/exercises/go-counting/GoCountingTest.cs +137 -88
  10. data/tracks/csharp/exercises/palindrome-products/Example.cs +25 -34
  11. data/tracks/csharp/exercises/palindrome-products/PalindromeProducts.cs +3 -29
  12. data/tracks/csharp/exercises/palindrome-products/PalindromeProductsTest.cs +103 -0
  13. data/tracks/csharp/exercises/word-search/Example.cs +24 -16
  14. data/tracks/csharp/exercises/word-search/WordSearch.cs +2 -2
  15. data/tracks/csharp/exercises/word-search/WordSearchTest.cs +539 -66
  16. data/tracks/csharp/generators/Exercises/GoCounting.cs +95 -0
  17. data/tracks/csharp/generators/Exercises/PalindromeProducts.cs +47 -0
  18. data/tracks/csharp/generators/Exercises/WordSearch.cs +84 -0
  19. data/tracks/csharp/generators/Output/ValueFormatter.cs +6 -0
  20. data/tracks/delphi/exercises/grade-school/uGradeSchoolTest.pas +4 -4
  21. data/tracks/ecmascript/.travis.yml +3 -1
  22. data/tracks/ecmascript/exercises/linked-list/linked-list.spec.js +16 -0
  23. data/tracks/elm/config.json +9 -1
  24. data/tracks/elm/exercises/bracket-push/BracketPush.elm +6 -0
  25. data/tracks/elm/exercises/bracket-push/BracketPush.example.elm +50 -0
  26. data/tracks/elm/exercises/bracket-push/README.md +40 -0
  27. data/tracks/elm/exercises/bracket-push/elm-package.json +14 -0
  28. data/tracks/elm/exercises/bracket-push/tests/Tests.elm +71 -0
  29. data/tracks/elm/exercises/bracket-push/tests/elm-package.json +16 -0
  30. data/tracks/go/config.json +14 -3
  31. data/tracks/go/exercises/linked-list/README.md +59 -0
  32. data/tracks/go/exercises/linked-list/cases_test.go +189 -0
  33. data/tracks/go/exercises/linked-list/example.go +212 -0
  34. data/tracks/go/exercises/linked-list/linked_list_test.go +106 -0
  35. data/tracks/java/exercises/go-counting/.meta/src/reference/java/GoCounting.java +6 -12
  36. data/tracks/java/exercises/go-counting/src/test/java/GoCountingTest.java +12 -12
  37. data/tracks/java/exercises/kindergarten-garden/src/main/java/KindergartenGarden.java +0 -4
  38. data/tracks/python/exercises/hamming/README.md +4 -3
  39. data/tracks/rust/exercises/beer-song/src/lib.rs +7 -7
  40. data/tracks/rust/exercises/bob/src/lib.rs +3 -3
  41. data/tracks/rust/exercises/difference-of-squares/src/lib.rs +14 -14
  42. data/tracks/rust/exercises/leap/src/lib.rs +3 -3
  43. data/tracks/rust/exercises/perfect-numbers/src/lib.rs +10 -10
  44. data/tracks/rust/exercises/proverb/src/lib.rs +3 -3
  45. data/tracks/rust/exercises/pythagorean-triplet/src/lib.rs +3 -3
  46. data/tracks/rust/exercises/raindrops/src/lib.rs +3 -3
  47. data/tracks/rust/exercises/sum-of-multiples/src/lib.rs +3 -3
  48. metadata +17 -3
  49. data/tracks/csharp/exercises/palindrome-products/PalindromeTest.cs +0 -69
@@ -2,61 +2,52 @@
2
2
  using System.Collections.Generic;
3
3
  using System.Linq;
4
4
 
5
- public class Palindrome
5
+ public static class PalindromeProducts
6
6
  {
7
- private Palindrome(int value, ISet<Tuple<int, int>> factors)
8
- {
9
- Value = value;
10
- Factors = factors;
11
- }
12
-
13
- public int Value { get; }
14
-
15
- public ISet<Tuple<int, int>> Factors { get; }
16
-
17
- public static Palindrome Largest(int maxFactor)
18
- {
19
- return Largest(1, maxFactor);
20
- }
21
-
22
- public static Palindrome Largest(int minFactor, int maxFactor)
7
+ public static (int, IEnumerable<(int,int)>) Largest(int minFactor, int maxFactor)
23
8
  {
24
9
  return FindPalindrome(minFactor, maxFactor, x => x.Max(p => p.Item1));
25
10
  }
26
11
 
27
- public static Palindrome Smallest(int maxFactor)
28
- {
29
- return Smallest(1, maxFactor);
30
- }
31
-
32
- public static Palindrome Smallest(int minFactor, int maxFactor)
12
+ public static (int, IEnumerable<(int,int)>) Smallest(int minFactor, int maxFactor)
33
13
  {
34
14
  return FindPalindrome(minFactor, maxFactor, x => x.Min(p => p.Item1));
35
15
  }
36
-
37
- private static Palindrome FindPalindrome(int minFactor, int maxFactor, Func<List<Tuple<int, Tuple<int, int>>>, int> valueSelector)
38
- {
39
- var palindromes = FindAllPalindromes(minFactor, maxFactor);
40
- var value = valueSelector(palindromes);
41
- var factors = new HashSet<Tuple<int, int>>(palindromes.Where(p => p.Item1 == value).Select(p => p.Item2));
42
16
 
43
- return new Palindrome(value, factors);
17
+ private static (int, IEnumerable<(int, int)>) FindPalindrome(int minFactor, int maxFactor,
18
+ Func<List<(int, (int, int))>, int> valueSelector)
19
+ {
20
+ if (minFactor > maxFactor || maxFactor < minFactor)
21
+ {
22
+ throw new ArgumentException();
23
+ }
24
+
25
+ try
26
+ {
27
+ var palindromes = FindAllPalindromes(minFactor, maxFactor);
28
+ var value = valueSelector(palindromes);
29
+ var factors = new HashSet<(int, int)>(palindromes.Where(p => p.Item1 == value).Select(p => p.Item2));
30
+ return (value, factors);
31
+ } catch (InvalidOperationException)
32
+ {
33
+ throw new ArgumentException();
34
+ }
44
35
  }
45
36
 
46
- private static List<Tuple<int, Tuple<int, int>>> FindAllPalindromes(int minFactor, int maxFactor)
37
+ private static List<(int, (int, int))> FindAllPalindromes(int minFactor, int maxFactor)
47
38
  {
48
39
  return (from pair in Pairs(minFactor, maxFactor)
49
40
  let product = pair.Item1 * pair.Item2
50
41
  where IsPalindrome(product)
51
- select Tuple.Create(product, pair))
42
+ select (product, pair))
52
43
  .ToList();
53
44
  }
54
45
 
55
- private static IEnumerable<Tuple<int, int>> Pairs(int minFactor, int maxFactor)
46
+ private static IEnumerable<(int, int)> Pairs(int minFactor, int maxFactor)
56
47
  {
57
48
  return from x in Enumerable.Range(minFactor, maxFactor + 1 - minFactor)
58
49
  from y in Enumerable.Range(x, maxFactor + 1 - x)
59
- select Tuple.Create(x, y);
50
+ select (x, y);
60
51
  }
61
52
 
62
53
  private static bool IsPalindrome(int num)
@@ -2,40 +2,14 @@
2
2
  using System.Collections.Generic;
3
3
  using System.Linq;
4
4
 
5
- public class Palindrome
5
+ public static class PalindromeProducts
6
6
  {
7
- public int Value
8
- {
9
- get
10
- {
11
- throw new NotImplementedException("You need to implement this function.");
12
- }
13
- }
14
-
15
- public ISet<Tuple<int, int>> Factors
16
- {
17
- get
18
- {
19
- throw new NotImplementedException("You need to implement this function.");
20
- }
21
- }
22
-
23
- public static Palindrome Largest(int maxFactor)
24
- {
25
- throw new NotImplementedException("You need to implement this function.");
26
- }
27
-
28
- public static Palindrome Largest(int minFactor, int maxFactor)
29
- {
30
- throw new NotImplementedException("You need to implement this function.");
31
- }
32
-
33
- public static Palindrome Smallest(int maxFactor)
7
+ public static (int, IEnumerable<(int,int)>) Largest(int minFactor, int maxFactor)
34
8
  {
35
9
  throw new NotImplementedException("You need to implement this function.");
36
10
  }
37
11
 
38
- public static Palindrome Smallest(int minFactor, int maxFactor)
12
+ public static (int, IEnumerable<(int,int)>) Smallest(int minFactor, int maxFactor)
39
13
  {
40
14
  throw new NotImplementedException("You need to implement this function.");
41
15
  }
@@ -0,0 +1,103 @@
1
+ // This file was auto-generated based on version 1.1.0 of the canonical data.
2
+
3
+ using Xunit;
4
+ using System;
5
+
6
+ public class PalindromeProductsTest
7
+ {
8
+ [Fact]
9
+ public void Finds_the_smallest_palindrome_from_single_digit_factors()
10
+ {
11
+ var actual = PalindromeProducts.Smallest(1, 9);
12
+ var expected = (1, new[] { (1, 1) });
13
+ Assert.Equal(expected.Item1, actual.Item1);
14
+ Assert.Equal(expected.Item2, actual.Item2);
15
+ }
16
+
17
+ [Fact(Skip = "Remove to run test")]
18
+ public void Finds_the_largest_palindrome_from_single_digit_factors()
19
+ {
20
+ var actual = PalindromeProducts.Largest(1, 9);
21
+ var expected = (9, new[] { (1, 9), (3, 3) });
22
+ Assert.Equal(expected.Item1, actual.Item1);
23
+ Assert.Equal(expected.Item2, actual.Item2);
24
+ }
25
+
26
+ [Fact(Skip = "Remove to run test")]
27
+ public void Find_the_smallest_palindrome_from_double_digit_factors()
28
+ {
29
+ var actual = PalindromeProducts.Smallest(10, 99);
30
+ var expected = (121, new[] { (11, 11) });
31
+ Assert.Equal(expected.Item1, actual.Item1);
32
+ Assert.Equal(expected.Item2, actual.Item2);
33
+ }
34
+
35
+ [Fact(Skip = "Remove to run test")]
36
+ public void Find_the_largest_palindrome_from_double_digit_factors()
37
+ {
38
+ var actual = PalindromeProducts.Largest(10, 99);
39
+ var expected = (9009, new[] { (91, 99) });
40
+ Assert.Equal(expected.Item1, actual.Item1);
41
+ Assert.Equal(expected.Item2, actual.Item2);
42
+ }
43
+
44
+ [Fact(Skip = "Remove to run test")]
45
+ public void Find_smallest_palindrome_from_triple_digit_factors()
46
+ {
47
+ var actual = PalindromeProducts.Smallest(100, 999);
48
+ var expected = (10201, new[] { (101, 101) });
49
+ Assert.Equal(expected.Item1, actual.Item1);
50
+ Assert.Equal(expected.Item2, actual.Item2);
51
+ }
52
+
53
+ [Fact(Skip = "Remove to run test")]
54
+ public void Find_the_largest_palindrome_from_triple_digit_factors()
55
+ {
56
+ var actual = PalindromeProducts.Largest(100, 999);
57
+ var expected = (906609, new[] { (913, 993) });
58
+ Assert.Equal(expected.Item1, actual.Item1);
59
+ Assert.Equal(expected.Item2, actual.Item2);
60
+ }
61
+
62
+ [Fact(Skip = "Remove to run test")]
63
+ public void Find_smallest_palindrome_from_four_digit_factors()
64
+ {
65
+ var actual = PalindromeProducts.Smallest(1000, 9999);
66
+ var expected = (1002001, new[] { (1001, 1001) });
67
+ Assert.Equal(expected.Item1, actual.Item1);
68
+ Assert.Equal(expected.Item2, actual.Item2);
69
+ }
70
+
71
+ [Fact(Skip = "Remove to run test")]
72
+ public void Find_the_largest_palindrome_from_four_digit_factors()
73
+ {
74
+ var actual = PalindromeProducts.Largest(1000, 9999);
75
+ var expected = (99000099, new[] { (9901, 9999) });
76
+ Assert.Equal(expected.Item1, actual.Item1);
77
+ Assert.Equal(expected.Item2, actual.Item2);
78
+ }
79
+
80
+ [Fact(Skip = "Remove to run test")]
81
+ public void Empty_result_for_smallest_if_no_palindrome_in_the_range()
82
+ {
83
+ Assert.Throws<ArgumentException>(() => PalindromeProducts.Smallest(1002, 1003));
84
+ }
85
+
86
+ [Fact(Skip = "Remove to run test")]
87
+ public void Empty_result_for_largest_if_no_palindrome_in_the_range()
88
+ {
89
+ Assert.Throws<ArgumentException>(() => PalindromeProducts.Largest(15, 15));
90
+ }
91
+
92
+ [Fact(Skip = "Remove to run test")]
93
+ public void Error_result_for_smallest_if_min_is_more_than_max()
94
+ {
95
+ Assert.Throws<ArgumentException>(() => PalindromeProducts.Smallest(10000, 1));
96
+ }
97
+
98
+ [Fact(Skip = "Remove to run test")]
99
+ public void Error_result_for_largest_if_min_is_more_than_max()
100
+ {
101
+ Assert.Throws<ArgumentException>(() => PalindromeProducts.Largest(2, 1));
102
+ }
103
+ }
@@ -7,17 +7,18 @@ public class WordSearch
7
7
  private readonly string[] rows;
8
8
  private readonly int width;
9
9
  private readonly int height;
10
+ private (int, int)[] positions;
10
11
 
11
- private static readonly Tuple<int, int>[] Directions =
12
+ private static readonly ValueTuple<int, int>[] Directions =
12
13
  {
13
- new Tuple<int, int>( 1, 0),
14
- new Tuple<int, int>( 0, 1),
15
- new Tuple<int, int>(-1, 0),
16
- new Tuple<int, int>( 0, -1),
17
- new Tuple<int, int>( 1, 1),
18
- new Tuple<int, int>( 1, -1),
19
- new Tuple<int, int>(-1, 1),
20
- new Tuple<int, int>(-1, -1)
14
+ ( 1, 0),
15
+ ( 0, 1),
16
+ (-1, 0),
17
+ ( 0, -1),
18
+ ( 1, 1),
19
+ ( 1, -1),
20
+ (-1, 1),
21
+ (-1, -1)
21
22
  };
22
23
 
23
24
  public WordSearch(string puzzle)
@@ -25,9 +26,15 @@ public WordSearch(string puzzle)
25
26
  rows = puzzle.Split('\n');
26
27
  width = rows[0].Length;
27
28
  height = rows.Length;
29
+ positions = Positions();
28
30
  }
29
31
 
30
- public Tuple<Tuple<int, int>, Tuple<int, int>> Find(string word)
32
+ public Dictionary<string, ValueTuple<ValueTuple<int, int>, ValueTuple<int, int>>?> Search(IEnumerable<string> words)
33
+ {
34
+ return words.ToDictionary(word => word, Search);
35
+ }
36
+
37
+ private ValueTuple<ValueTuple<int, int>, ValueTuple<int, int>>? Search(string word)
31
38
  {
32
39
  return
33
40
  Positions()
@@ -35,7 +42,7 @@ public WordSearch(string puzzle)
35
42
  .FirstOrDefault();
36
43
  }
37
44
 
38
- private IEnumerable<Tuple<Tuple<int, int>, Tuple<int, int>>> Find(string word, Tuple<int, int> position, Tuple<int, int> direction)
45
+ private IEnumerable<ValueTuple<ValueTuple<int, int>, ValueTuple<int, int>>> Find(string word, ValueTuple<int, int> position, ValueTuple<int, int> direction)
39
46
  {
40
47
  var current = position;
41
48
 
@@ -46,13 +53,13 @@ public WordSearch(string puzzle)
46
53
  yield break;
47
54
  }
48
55
 
49
- current = new Tuple<int, int>(current.Item1 + direction.Item1, current.Item2 + direction.Item2);
56
+ current = (current.Item1 + direction.Item1, current.Item2 + direction.Item2);
50
57
  }
51
58
 
52
- yield return Tuple.Create(position, new Tuple<int, int>(current.Item1 - direction.Item1, current.Item2 - direction.Item2));
59
+ yield return ValueTuple.Create(position, (current.Item1 - direction.Item1, current.Item2 - direction.Item2));
53
60
  }
54
61
 
55
- private char? FindChar(Tuple<int, int> coordinate)
62
+ private char? FindChar(ValueTuple<int, int> coordinate)
56
63
  {
57
64
  if (coordinate.Item1 > 0 && coordinate.Item1 <= width && coordinate.Item2 > 0 && coordinate.Item2 <= height)
58
65
  {
@@ -62,9 +69,10 @@ public WordSearch(string puzzle)
62
69
  return null;
63
70
  }
64
71
 
65
- private IEnumerable<Tuple<int, int>> Positions()
72
+ private ValueTuple<int, int>[] Positions()
66
73
  {
67
74
  return Enumerable.Range(1, width).SelectMany(x =>
68
- Enumerable.Range(1, height).Select(y => new Tuple<int, int>(x, y)));
75
+ Enumerable.Range(1, height).Select(y => (x, y)))
76
+ .ToArray();
69
77
  }
70
78
  }
@@ -4,12 +4,12 @@
4
4
 
5
5
  public class WordSearch
6
6
  {
7
- public WordSearch(string puzzle)
7
+ public WordSearch(string grid)
8
8
  {
9
9
  throw new NotImplementedException("You need to implement this function.");
10
10
  }
11
11
 
12
- public Tuple<Tuple<int, int>, Tuple<int, int>> Find(string word)
12
+ public ((int, int), (int, int)) Search(string wordsToSearchFor)
13
13
  {
14
14
  throw new NotImplementedException("You need to implement this function.");
15
15
  }
@@ -1,111 +1,584 @@
1
- using System;
1
+ // This file was auto-generated based on version 1.2.0 of the canonical data.
2
+
2
3
  using Xunit;
4
+ using System;
5
+ using System.Collections.Generic;
3
6
 
4
7
  public class WordSearchTest
5
8
  {
6
- private const string Puzzle =
7
- "jefblpepre\n" +
8
- "camdcimgtc\n" +
9
- "oivokprjsm\n" +
10
- "pbwasqroua\n" +
11
- "rixilelhrs\n" +
12
- "wolcqlirpc\n" +
13
- "screeaumgr\n" +
14
- "alxhpburyi\n" +
15
- "jalaycalmp\n" +
16
- "clojurermt";
17
-
18
9
  [Fact]
19
- public void Should_find_horizontal_words_written_left_to_right()
10
+ public void Should_accept_an_initial_game_grid_and_a_target_search_word()
11
+ {
12
+ var wordsToSearchFor = new[]
13
+ {
14
+ "clojure"
15
+ };
16
+ var grid = "jefblpepre";
17
+ var sut = new WordSearch(grid);
18
+ var actual = sut.Search(wordsToSearchFor);
19
+ var expected = new Dictionary<string, ((int, int), (int, int))?>
20
+ {
21
+ ["clojure"] = null
22
+ };
23
+ Assert.Null(expected["clojure"]);
24
+ }
25
+
26
+ [Fact(Skip = "Remove to run test")]
27
+ public void Should_locate_one_word_written_left_to_right()
20
28
  {
21
- var wordSearch = new WordSearch(Puzzle);
22
- var actual = wordSearch.Find("clojure");
23
- Assert.Equal(new Tuple<int, int>(1, 10), actual.Item1);
24
- Assert.Equal(new Tuple<int, int>(7, 10), actual.Item2);
29
+ var wordsToSearchFor = new[]
30
+ {
31
+ "clojure"
32
+ };
33
+ var grid = "clojurermt";
34
+ var sut = new WordSearch(grid);
35
+ var actual = sut.Search(wordsToSearchFor);
36
+ var expected = new Dictionary<string, ((int, int), (int, int))?>
37
+ {
38
+ ["clojure"] = ((1, 1), (7, 1))
39
+ };
40
+ Assert.Equal(expected["clojure"], actual["clojure"]);
25
41
  }
26
42
 
27
43
  [Fact(Skip = "Remove to run test")]
28
- public void Should_find_horizontal_words_written_right_to_left()
44
+ public void Should_locate_the_same_word_written_left_to_right_in_a_different_position()
29
45
  {
30
- var wordSearch = new WordSearch(Puzzle);
31
- var actual = wordSearch.Find("elixir");
32
- Assert.Equal(new Tuple<int, int>(6, 5), actual.Item1);
33
- Assert.Equal(new Tuple<int, int>(1, 5), actual.Item2);
46
+ var wordsToSearchFor = new[]
47
+ {
48
+ "clojure"
49
+ };
50
+ var grid = "mtclojurer";
51
+ var sut = new WordSearch(grid);
52
+ var actual = sut.Search(wordsToSearchFor);
53
+ var expected = new Dictionary<string, ((int, int), (int, int))?>
54
+ {
55
+ ["clojure"] = ((3, 1), (9, 1))
56
+ };
57
+ Assert.Equal(expected["clojure"], actual["clojure"]);
34
58
  }
35
59
 
36
60
  [Fact(Skip = "Remove to run test")]
37
- public void Should_find_vertical_words_written_top_to_bottom()
61
+ public void Should_locate_a_different_left_to_right_word()
38
62
  {
39
- var wordSearch = new WordSearch(Puzzle);
40
- var actual = wordSearch.Find("ecmascript");
41
- Assert.Equal(new Tuple<int, int>(10, 1), actual.Item1);
42
- Assert.Equal(new Tuple<int, int>(10, 10), actual.Item2);
63
+ var wordsToSearchFor = new[]
64
+ {
65
+ "coffee"
66
+ };
67
+ var grid = "coffeelplx";
68
+ var sut = new WordSearch(grid);
69
+ var actual = sut.Search(wordsToSearchFor);
70
+ var expected = new Dictionary<string, ((int, int), (int, int))?>
71
+ {
72
+ ["coffee"] = ((1, 1), (6, 1))
73
+ };
74
+ Assert.Equal(expected["coffee"], actual["coffee"]);
43
75
  }
44
76
 
45
77
  [Fact(Skip = "Remove to run test")]
46
- public void Should_find_vertical_words_written_bottom_to_top()
78
+ public void Should_locate_that_different_left_to_right_word_in_a_different_position()
47
79
  {
48
- var wordSearch = new WordSearch(Puzzle);
49
- var actual = wordSearch.Find("rust");
50
- Assert.Equal(new Tuple<int, int>(9, 5), actual.Item1);
51
- Assert.Equal(new Tuple<int, int>(9, 2), actual.Item2);
80
+ var wordsToSearchFor = new[]
81
+ {
82
+ "coffee"
83
+ };
84
+ var grid = "xcoffeezlp";
85
+ var sut = new WordSearch(grid);
86
+ var actual = sut.Search(wordsToSearchFor);
87
+ var expected = new Dictionary<string, ((int, int), (int, int))?>
88
+ {
89
+ ["coffee"] = ((2, 1), (7, 1))
90
+ };
91
+ Assert.Equal(expected["coffee"], actual["coffee"]);
52
92
  }
53
93
 
54
94
  [Fact(Skip = "Remove to run test")]
55
- public void Should_find_diagonal_words_written_top_left_to_bottom_right()
95
+ public void Should_locate_a_left_to_right_word_in_two_line_grid()
56
96
  {
57
- var wordSearch = new WordSearch(Puzzle);
58
- var actual = wordSearch.Find("java");
59
- Assert.Equal(new Tuple<int, int>(1, 1), actual.Item1);
60
- Assert.Equal(new Tuple<int, int>(4, 4), actual.Item2);
97
+ var wordsToSearchFor = new[]
98
+ {
99
+ "clojure"
100
+ };
101
+ var grid =
102
+ "jefblpepre\n" +
103
+ "tclojurerm";
104
+ var sut = new WordSearch(grid);
105
+ var actual = sut.Search(wordsToSearchFor);
106
+ var expected = new Dictionary<string, ((int, int), (int, int))?>
107
+ {
108
+ ["clojure"] = ((2, 2), (8, 2))
109
+ };
110
+ Assert.Equal(expected["clojure"], actual["clojure"]);
61
111
  }
62
112
 
63
113
  [Fact(Skip = "Remove to run test")]
64
- public void Should_find_diagonal_upper_written_bottom_right_to_top_left()
114
+ public void Should_locate_a_left_to_right_word_in_three_line_grid()
65
115
  {
66
- var wordSearch = new WordSearch(Puzzle);
67
- var actual = wordSearch.Find("lua");
68
- Assert.Equal(new Tuple<int, int>(8, 9), actual.Item1);
69
- Assert.Equal(new Tuple<int, int>(6, 7), actual.Item2);
116
+ var wordsToSearchFor = new[]
117
+ {
118
+ "clojure"
119
+ };
120
+ var grid =
121
+ "camdcimgtc\n" +
122
+ "jefblpepre\n" +
123
+ "clojurermt";
124
+ var sut = new WordSearch(grid);
125
+ var actual = sut.Search(wordsToSearchFor);
126
+ var expected = new Dictionary<string, ((int, int), (int, int))?>
127
+ {
128
+ ["clojure"] = ((1, 3), (7, 3))
129
+ };
130
+ Assert.Equal(expected["clojure"], actual["clojure"]);
70
131
  }
71
132
 
72
133
  [Fact(Skip = "Remove to run test")]
73
- public void Should_find_diagonal_upper_written_bottom_left_to_top_right()
134
+ public void Should_locate_a_left_to_right_word_in_ten_line_grid()
74
135
  {
75
- var wordSearch = new WordSearch(Puzzle);
76
- var actual = wordSearch.Find("lisp");
77
- Assert.Equal(new Tuple<int, int>(3, 6), actual.Item1);
78
- Assert.Equal(new Tuple<int, int>(6, 3), actual.Item2);
136
+ var wordsToSearchFor = new[]
137
+ {
138
+ "clojure"
139
+ };
140
+ var grid =
141
+ "jefblpepre\n" +
142
+ "camdcimgtc\n" +
143
+ "oivokprjsm\n" +
144
+ "pbwasqroua\n" +
145
+ "rixilelhrs\n" +
146
+ "wolcqlirpc\n" +
147
+ "screeaumgr\n" +
148
+ "alxhpburyi\n" +
149
+ "jalaycalmp\n" +
150
+ "clojurermt";
151
+ var sut = new WordSearch(grid);
152
+ var actual = sut.Search(wordsToSearchFor);
153
+ var expected = new Dictionary<string, ((int, int), (int, int))?>
154
+ {
155
+ ["clojure"] = ((1, 10), (7, 10))
156
+ };
157
+ Assert.Equal(expected["clojure"], actual["clojure"]);
79
158
  }
80
159
 
81
160
  [Fact(Skip = "Remove to run test")]
82
- public void Should_find_diagonal_upper_written_top_right_to_bottom_left()
161
+ public void Should_locate_that_left_to_right_word_in_a_different_position_in_a_ten_line_grid()
83
162
  {
84
- var wordSearch = new WordSearch(Puzzle);
85
- var actual = wordSearch.Find("ruby");
86
- Assert.Equal(new Tuple<int, int>(8, 6), actual.Item1);
87
- Assert.Equal(new Tuple<int, int>(5, 9), actual.Item2);
163
+ var wordsToSearchFor = new[]
164
+ {
165
+ "clojure"
166
+ };
167
+ var grid =
168
+ "jefblpepre\n" +
169
+ "camdcimgtc\n" +
170
+ "oivokprjsm\n" +
171
+ "pbwasqroua\n" +
172
+ "rixilelhrs\n" +
173
+ "wolcqlirpc\n" +
174
+ "screeaumgr\n" +
175
+ "alxhpburyi\n" +
176
+ "clojurermt\n" +
177
+ "jalaycalmp";
178
+ var sut = new WordSearch(grid);
179
+ var actual = sut.Search(wordsToSearchFor);
180
+ var expected = new Dictionary<string, ((int, int), (int, int))?>
181
+ {
182
+ ["clojure"] = ((1, 9), (7, 9))
183
+ };
184
+ Assert.Equal(expected["clojure"], actual["clojure"]);
88
185
  }
89
186
 
90
187
  [Fact(Skip = "Remove to run test")]
91
- public void Should_not_find_words_that_are_not_in_the_puzzle()
188
+ public void Should_locate_a_different_left_to_right_word_in_a_ten_line_grid()
92
189
  {
93
- var wordSearch = new WordSearch(Puzzle);
94
- var actual = wordSearch.Find("haskell");
95
- Assert.Null(actual);
190
+ var wordsToSearchFor = new[]
191
+ {
192
+ "fortran"
193
+ };
194
+ var grid =
195
+ "jefblpepre\n" +
196
+ "camdcimgtc\n" +
197
+ "oivokprjsm\n" +
198
+ "pbwasqroua\n" +
199
+ "rixilelhrs\n" +
200
+ "wolcqlirpc\n" +
201
+ "fortranftw\n" +
202
+ "alxhpburyi\n" +
203
+ "clojurermt\n" +
204
+ "jalaycalmp";
205
+ var sut = new WordSearch(grid);
206
+ var actual = sut.Search(wordsToSearchFor);
207
+ var expected = new Dictionary<string, ((int, int), (int, int))?>
208
+ {
209
+ ["fortran"] = ((1, 7), (7, 7))
210
+ };
211
+ Assert.Equal(expected["fortran"], actual["fortran"]);
96
212
  }
97
213
 
98
214
  [Fact(Skip = "Remove to run test")]
99
- public void Should_be_able_to_search_differently_sized_puzzles()
215
+ public void Should_locate_multiple_words()
100
216
  {
101
- const string differentSizePuzzle =
102
- "qwertyuiopz\n" +
103
- "luamsicrexe\n" +
104
- "abcdefghijk";
105
- var wordSearch = new WordSearch(differentSizePuzzle);
217
+ var wordsToSearchFor = new[]
218
+ {
219
+ "fortran",
220
+ "clojure"
221
+ };
222
+ var grid =
223
+ "jefblpepre\n" +
224
+ "camdcimgtc\n" +
225
+ "oivokprjsm\n" +
226
+ "pbwasqroua\n" +
227
+ "rixilelhrs\n" +
228
+ "wolcqlirpc\n" +
229
+ "fortranftw\n" +
230
+ "alxhpburyi\n" +
231
+ "jalaycalmp\n" +
232
+ "clojurermt";
233
+ var sut = new WordSearch(grid);
234
+ var actual = sut.Search(wordsToSearchFor);
235
+ var expected = new Dictionary<string, ((int, int), (int, int))?>
236
+ {
237
+ ["clojure"] = ((1, 10), (7, 10)),
238
+ ["fortran"] = ((1, 7), (7, 7))
239
+ };
240
+ Assert.Equal(expected["clojure"], actual["clojure"]);
241
+ Assert.Equal(expected["fortran"], actual["fortran"]);
242
+ }
243
+
244
+ [Fact(Skip = "Remove to run test")]
245
+ public void Should_locate_a_single_word_written_right_to_left()
246
+ {
247
+ var wordsToSearchFor = new[]
248
+ {
249
+ "elixir"
250
+ };
251
+ var grid = "rixilelhrs";
252
+ var sut = new WordSearch(grid);
253
+ var actual = sut.Search(wordsToSearchFor);
254
+ var expected = new Dictionary<string, ((int, int), (int, int))?>
255
+ {
256
+ ["elixir"] = ((6, 1), (1, 1))
257
+ };
258
+ Assert.Equal(expected["elixir"], actual["elixir"]);
259
+ }
106
260
 
107
- var actual = wordSearch.Find("exercism");
108
- Assert.Equal(new Tuple<int, int>(11, 2), actual.Item1);
109
- Assert.Equal(new Tuple<int, int>(4, 2), actual.Item2);
261
+ [Fact(Skip = "Remove to run test")]
262
+ public void Should_locate_multiple_words_written_in_different_horizontal_directions()
263
+ {
264
+ var wordsToSearchFor = new[]
265
+ {
266
+ "elixir",
267
+ "clojure"
268
+ };
269
+ var grid =
270
+ "jefblpepre\n" +
271
+ "camdcimgtc\n" +
272
+ "oivokprjsm\n" +
273
+ "pbwasqroua\n" +
274
+ "rixilelhrs\n" +
275
+ "wolcqlirpc\n" +
276
+ "screeaumgr\n" +
277
+ "alxhpburyi\n" +
278
+ "jalaycalmp\n" +
279
+ "clojurermt";
280
+ var sut = new WordSearch(grid);
281
+ var actual = sut.Search(wordsToSearchFor);
282
+ var expected = new Dictionary<string, ((int, int), (int, int))?>
283
+ {
284
+ ["clojure"] = ((1, 10), (7, 10)),
285
+ ["elixir"] = ((6, 5), (1, 5))
286
+ };
287
+ Assert.Equal(expected["clojure"], actual["clojure"]);
288
+ Assert.Equal(expected["elixir"], actual["elixir"]);
289
+ }
290
+
291
+ [Fact(Skip = "Remove to run test")]
292
+ public void Should_locate_words_written_top_to_bottom()
293
+ {
294
+ var wordsToSearchFor = new[]
295
+ {
296
+ "clojure",
297
+ "elixir",
298
+ "ecmascript"
299
+ };
300
+ var grid =
301
+ "jefblpepre\n" +
302
+ "camdcimgtc\n" +
303
+ "oivokprjsm\n" +
304
+ "pbwasqroua\n" +
305
+ "rixilelhrs\n" +
306
+ "wolcqlirpc\n" +
307
+ "screeaumgr\n" +
308
+ "alxhpburyi\n" +
309
+ "jalaycalmp\n" +
310
+ "clojurermt";
311
+ var sut = new WordSearch(grid);
312
+ var actual = sut.Search(wordsToSearchFor);
313
+ var expected = new Dictionary<string, ((int, int), (int, int))?>
314
+ {
315
+ ["clojure"] = ((1, 10), (7, 10)),
316
+ ["elixir"] = ((6, 5), (1, 5)),
317
+ ["ecmascript"] = ((10, 1), (10, 10))
318
+ };
319
+ Assert.Equal(expected["clojure"], actual["clojure"]);
320
+ Assert.Equal(expected["elixir"], actual["elixir"]);
321
+ Assert.Equal(expected["ecmascript"], actual["ecmascript"]);
322
+ }
323
+
324
+ [Fact(Skip = "Remove to run test")]
325
+ public void Should_locate_words_written_bottom_to_top()
326
+ {
327
+ var wordsToSearchFor = new[]
328
+ {
329
+ "clojure",
330
+ "elixir",
331
+ "ecmascript",
332
+ "rust"
333
+ };
334
+ var grid =
335
+ "jefblpepre\n" +
336
+ "camdcimgtc\n" +
337
+ "oivokprjsm\n" +
338
+ "pbwasqroua\n" +
339
+ "rixilelhrs\n" +
340
+ "wolcqlirpc\n" +
341
+ "screeaumgr\n" +
342
+ "alxhpburyi\n" +
343
+ "jalaycalmp\n" +
344
+ "clojurermt";
345
+ var sut = new WordSearch(grid);
346
+ var actual = sut.Search(wordsToSearchFor);
347
+ var expected = new Dictionary<string, ((int, int), (int, int))?>
348
+ {
349
+ ["clojure"] = ((1, 10), (7, 10)),
350
+ ["elixir"] = ((6, 5), (1, 5)),
351
+ ["ecmascript"] = ((10, 1), (10, 10)),
352
+ ["rust"] = ((9, 5), (9, 2))
353
+ };
354
+ Assert.Equal(expected["clojure"], actual["clojure"]);
355
+ Assert.Equal(expected["elixir"], actual["elixir"]);
356
+ Assert.Equal(expected["ecmascript"], actual["ecmascript"]);
357
+ Assert.Equal(expected["rust"], actual["rust"]);
358
+ }
359
+
360
+ [Fact(Skip = "Remove to run test")]
361
+ public void Should_locate_words_written_top_left_to_bottom_right()
362
+ {
363
+ var wordsToSearchFor = new[]
364
+ {
365
+ "clojure",
366
+ "elixir",
367
+ "ecmascript",
368
+ "rust",
369
+ "java"
370
+ };
371
+ var grid =
372
+ "jefblpepre\n" +
373
+ "camdcimgtc\n" +
374
+ "oivokprjsm\n" +
375
+ "pbwasqroua\n" +
376
+ "rixilelhrs\n" +
377
+ "wolcqlirpc\n" +
378
+ "screeaumgr\n" +
379
+ "alxhpburyi\n" +
380
+ "jalaycalmp\n" +
381
+ "clojurermt";
382
+ var sut = new WordSearch(grid);
383
+ var actual = sut.Search(wordsToSearchFor);
384
+ var expected = new Dictionary<string, ((int, int), (int, int))?>
385
+ {
386
+ ["clojure"] = ((1, 10), (7, 10)),
387
+ ["elixir"] = ((6, 5), (1, 5)),
388
+ ["ecmascript"] = ((10, 1), (10, 10)),
389
+ ["rust"] = ((9, 5), (9, 2)),
390
+ ["java"] = ((1, 1), (4, 4))
391
+ };
392
+ Assert.Equal(expected["clojure"], actual["clojure"]);
393
+ Assert.Equal(expected["elixir"], actual["elixir"]);
394
+ Assert.Equal(expected["ecmascript"], actual["ecmascript"]);
395
+ Assert.Equal(expected["rust"], actual["rust"]);
396
+ Assert.Equal(expected["java"], actual["java"]);
397
+ }
398
+
399
+ [Fact(Skip = "Remove to run test")]
400
+ public void Should_locate_words_written_bottom_right_to_top_left()
401
+ {
402
+ var wordsToSearchFor = new[]
403
+ {
404
+ "clojure",
405
+ "elixir",
406
+ "ecmascript",
407
+ "rust",
408
+ "java",
409
+ "lua"
410
+ };
411
+ var grid =
412
+ "jefblpepre\n" +
413
+ "camdcimgtc\n" +
414
+ "oivokprjsm\n" +
415
+ "pbwasqroua\n" +
416
+ "rixilelhrs\n" +
417
+ "wolcqlirpc\n" +
418
+ "screeaumgr\n" +
419
+ "alxhpburyi\n" +
420
+ "jalaycalmp\n" +
421
+ "clojurermt";
422
+ var sut = new WordSearch(grid);
423
+ var actual = sut.Search(wordsToSearchFor);
424
+ var expected = new Dictionary<string, ((int, int), (int, int))?>
425
+ {
426
+ ["clojure"] = ((1, 10), (7, 10)),
427
+ ["elixir"] = ((6, 5), (1, 5)),
428
+ ["ecmascript"] = ((10, 1), (10, 10)),
429
+ ["rust"] = ((9, 5), (9, 2)),
430
+ ["java"] = ((1, 1), (4, 4)),
431
+ ["lua"] = ((8, 9), (6, 7))
432
+ };
433
+ Assert.Equal(expected["clojure"], actual["clojure"]);
434
+ Assert.Equal(expected["elixir"], actual["elixir"]);
435
+ Assert.Equal(expected["ecmascript"], actual["ecmascript"]);
436
+ Assert.Equal(expected["rust"], actual["rust"]);
437
+ Assert.Equal(expected["java"], actual["java"]);
438
+ Assert.Equal(expected["lua"], actual["lua"]);
439
+ }
440
+
441
+ [Fact(Skip = "Remove to run test")]
442
+ public void Should_locate_words_written_bottom_left_to_top_right()
443
+ {
444
+ var wordsToSearchFor = new[]
445
+ {
446
+ "clojure",
447
+ "elixir",
448
+ "ecmascript",
449
+ "rust",
450
+ "java",
451
+ "lua",
452
+ "lisp"
453
+ };
454
+ var grid =
455
+ "jefblpepre\n" +
456
+ "camdcimgtc\n" +
457
+ "oivokprjsm\n" +
458
+ "pbwasqroua\n" +
459
+ "rixilelhrs\n" +
460
+ "wolcqlirpc\n" +
461
+ "screeaumgr\n" +
462
+ "alxhpburyi\n" +
463
+ "jalaycalmp\n" +
464
+ "clojurermt";
465
+ var sut = new WordSearch(grid);
466
+ var actual = sut.Search(wordsToSearchFor);
467
+ var expected = new Dictionary<string, ((int, int), (int, int))?>
468
+ {
469
+ ["clojure"] = ((1, 10), (7, 10)),
470
+ ["elixir"] = ((6, 5), (1, 5)),
471
+ ["ecmascript"] = ((10, 1), (10, 10)),
472
+ ["rust"] = ((9, 5), (9, 2)),
473
+ ["java"] = ((1, 1), (4, 4)),
474
+ ["lua"] = ((8, 9), (6, 7)),
475
+ ["lisp"] = ((3, 6), (6, 3))
476
+ };
477
+ Assert.Equal(expected["clojure"], actual["clojure"]);
478
+ Assert.Equal(expected["elixir"], actual["elixir"]);
479
+ Assert.Equal(expected["ecmascript"], actual["ecmascript"]);
480
+ Assert.Equal(expected["rust"], actual["rust"]);
481
+ Assert.Equal(expected["java"], actual["java"]);
482
+ Assert.Equal(expected["lua"], actual["lua"]);
483
+ Assert.Equal(expected["lisp"], actual["lisp"]);
484
+ }
485
+
486
+ [Fact(Skip = "Remove to run test")]
487
+ public void Should_locate_words_written_top_right_to_bottom_left()
488
+ {
489
+ var wordsToSearchFor = new[]
490
+ {
491
+ "clojure",
492
+ "elixir",
493
+ "ecmascript",
494
+ "rust",
495
+ "java",
496
+ "lua",
497
+ "lisp",
498
+ "ruby"
499
+ };
500
+ var grid =
501
+ "jefblpepre\n" +
502
+ "camdcimgtc\n" +
503
+ "oivokprjsm\n" +
504
+ "pbwasqroua\n" +
505
+ "rixilelhrs\n" +
506
+ "wolcqlirpc\n" +
507
+ "screeaumgr\n" +
508
+ "alxhpburyi\n" +
509
+ "jalaycalmp\n" +
510
+ "clojurermt";
511
+ var sut = new WordSearch(grid);
512
+ var actual = sut.Search(wordsToSearchFor);
513
+ var expected = new Dictionary<string, ((int, int), (int, int))?>
514
+ {
515
+ ["clojure"] = ((1, 10), (7, 10)),
516
+ ["elixir"] = ((6, 5), (1, 5)),
517
+ ["ecmascript"] = ((10, 1), (10, 10)),
518
+ ["rust"] = ((9, 5), (9, 2)),
519
+ ["java"] = ((1, 1), (4, 4)),
520
+ ["lua"] = ((8, 9), (6, 7)),
521
+ ["lisp"] = ((3, 6), (6, 3)),
522
+ ["ruby"] = ((8, 6), (5, 9))
523
+ };
524
+ Assert.Equal(expected["clojure"], actual["clojure"]);
525
+ Assert.Equal(expected["elixir"], actual["elixir"]);
526
+ Assert.Equal(expected["ecmascript"], actual["ecmascript"]);
527
+ Assert.Equal(expected["rust"], actual["rust"]);
528
+ Assert.Equal(expected["java"], actual["java"]);
529
+ Assert.Equal(expected["lua"], actual["lua"]);
530
+ Assert.Equal(expected["lisp"], actual["lisp"]);
531
+ Assert.Equal(expected["ruby"], actual["ruby"]);
532
+ }
533
+
534
+ [Fact(Skip = "Remove to run test")]
535
+ public void Should_fail_to_locate_a_word_that_is_not_in_the_puzzle()
536
+ {
537
+ var wordsToSearchFor = new[]
538
+ {
539
+ "clojure",
540
+ "elixir",
541
+ "ecmascript",
542
+ "rust",
543
+ "java",
544
+ "lua",
545
+ "lisp",
546
+ "ruby",
547
+ "haskell"
548
+ };
549
+ var grid =
550
+ "jefblpepre\n" +
551
+ "camdcimgtc\n" +
552
+ "oivokprjsm\n" +
553
+ "pbwasqroua\n" +
554
+ "rixilelhrs\n" +
555
+ "wolcqlirpc\n" +
556
+ "screeaumgr\n" +
557
+ "alxhpburyi\n" +
558
+ "jalaycalmp\n" +
559
+ "clojurermt";
560
+ var sut = new WordSearch(grid);
561
+ var actual = sut.Search(wordsToSearchFor);
562
+ var expected = new Dictionary<string, ((int, int), (int, int))?>
563
+ {
564
+ ["clojure"] = ((1, 10), (7, 10)),
565
+ ["elixir"] = ((6, 5), (1, 5)),
566
+ ["ecmascript"] = ((10, 1), (10, 10)),
567
+ ["rust"] = ((9, 5), (9, 2)),
568
+ ["java"] = ((1, 1), (4, 4)),
569
+ ["lua"] = ((8, 9), (6, 7)),
570
+ ["lisp"] = ((3, 6), (6, 3)),
571
+ ["ruby"] = ((8, 6), (5, 9)),
572
+ ["haskell"] = null
573
+ };
574
+ Assert.Equal(expected["clojure"], actual["clojure"]);
575
+ Assert.Equal(expected["elixir"], actual["elixir"]);
576
+ Assert.Equal(expected["ecmascript"], actual["ecmascript"]);
577
+ Assert.Equal(expected["rust"], actual["rust"]);
578
+ Assert.Equal(expected["java"], actual["java"]);
579
+ Assert.Equal(expected["lua"], actual["lua"]);
580
+ Assert.Equal(expected["lisp"], actual["lisp"]);
581
+ Assert.Equal(expected["ruby"], actual["ruby"]);
582
+ Assert.Null(expected["haskell"]);
110
583
  }
111
584
  }