trackler 2.0.7.0 → 2.0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/common/exercises/counter/metadata.yml +0 -4
  4. data/common/exercises/error-handling/metadata.yml +0 -4
  5. data/common/exercises/etl/canonical-data.json +1 -1
  6. data/common/exercises/hello-world/canonical-data.json +9 -21
  7. data/common/exercises/hello-world/description.md +7 -42
  8. data/common/exercises/hello-world/metadata.yml +1 -1
  9. data/common/exercises/lens-person/metadata.yml +0 -3
  10. data/common/exercises/luhn/canonical-data.json +17 -17
  11. data/common/exercises/nucleotide-codons/metadata.yml +0 -2
  12. data/common/exercises/react/metadata.yml +0 -2
  13. data/common/exercises/rectangles/metadata.yml +0 -3
  14. data/common/exercises/variable-length-quantity/metadata.yml +0 -2
  15. data/fixtures/tracks/snowflake/config.json +17 -0
  16. data/fixtures/tracks/snowflake/exercises/snowflake-only/description.md +1 -0
  17. data/fixtures/tracks/snowflake/exercises/snowflake-only/metadata.yml +4 -0
  18. data/lib/trackler/description.rb +27 -0
  19. data/lib/trackler/guaranteed_file.rb +77 -0
  20. data/lib/trackler/implementations.rb +5 -5
  21. data/lib/trackler/metadata.rb +27 -0
  22. data/lib/trackler/null_track.rb +22 -0
  23. data/lib/trackler/problem.rb +32 -34
  24. data/lib/trackler/track.rb +1 -1
  25. data/lib/trackler/version.rb +1 -1
  26. data/tracks/csharp/exercises/hello-world/Example.cs +2 -5
  27. data/tracks/csharp/exercises/hello-world/HelloWorldTest.cs +2 -16
  28. data/tracks/elixir/config.json +7 -0
  29. data/tracks/elixir/exercises/series/example.exs +13 -0
  30. data/tracks/elixir/exercises/series/series.exs +11 -0
  31. data/tracks/elixir/exercises/series/series_test.exs +53 -0
  32. data/tracks/erlang/README.md +3 -3
  33. data/tracks/erlang/config.json +15 -11
  34. data/tracks/erlang/exercises/{binary → all-your-base}/include/exercism.hrl +0 -0
  35. data/tracks/erlang/exercises/{binary → all-your-base}/rebar.config +0 -0
  36. data/tracks/erlang/exercises/{trinary/src/trinary.app.src → all-your-base/src/all_your_base.app.src} +2 -2
  37. data/tracks/erlang/exercises/all-your-base/src/example.erl +33 -0
  38. data/tracks/erlang/exercises/all-your-base/test/all_your_base_tests.erl +69 -0
  39. data/tracks/erlang/exercises/hello-world/src/example.erl +4 -4
  40. data/tracks/erlang/exercises/hello-world/test/hello_world_tests.erl +3 -12
  41. data/tracks/erlang/exercises/{trinary → rotational-cipher}/include/exercism.hrl +0 -0
  42. data/tracks/erlang/exercises/{trinary → rotational-cipher}/rebar.config +8 -1
  43. data/tracks/erlang/exercises/rotational-cipher/src/example.erl +19 -0
  44. data/tracks/erlang/exercises/{binary/src/binary.app.src → rotational-cipher/src/rotational_cipher.app.src} +2 -2
  45. data/tracks/erlang/exercises/rotational-cipher/test/rotational_cipher_tests.erl +98 -0
  46. data/tracks/fsharp/exercises/grep/GrepTest.fs +57 -0
  47. data/tracks/fsharp/exercises/hello-world/Example.fs +1 -1
  48. data/tracks/fsharp/exercises/hello-world/HelloWorldTest.fs +2 -12
  49. data/tracks/go/.travis.yml +7 -15
  50. data/tracks/go/exercises/hello-world/example.go +4 -8
  51. data/tracks/go/exercises/hello-world/hello_test.go +20 -16
  52. data/tracks/go/exercises/hello-world/hello_world.go +12 -2
  53. data/tracks/groovy/exercises/hello-world/Example.groovy +2 -2
  54. data/tracks/groovy/exercises/hello-world/HelloWorld.groovy +1 -1
  55. data/tracks/groovy/exercises/hello-world/HelloWorldSpec.groovy +1 -14
  56. data/tracks/haskell/config.json +6 -0
  57. data/tracks/haskell/exercises/hello-world/HINTS.md +6 -0
  58. data/tracks/haskell/exercises/hello-world/examples/success-standard/package.yaml +16 -0
  59. data/tracks/haskell/exercises/hello-world/examples/success-standard/src/HelloWorld.hs +4 -0
  60. data/tracks/haskell/exercises/hello-world/package.yaml +19 -0
  61. data/tracks/haskell/exercises/hello-world/src/HelloWorld.hs +4 -0
  62. data/tracks/haskell/exercises/hello-world/stack.yaml +1 -0
  63. data/tracks/haskell/exercises/hello-world/test/Tests.hs +13 -0
  64. data/tracks/idris/config.json +9 -0
  65. data/tracks/idris/exercises/leap/Leap.ipkg +5 -0
  66. data/tracks/idris/exercises/leap/Makefile +23 -0
  67. data/tracks/idris/exercises/leap/src/Leap.idr +5 -0
  68. data/tracks/idris/exercises/leap/src/Test/Leap.idr +37 -0
  69. data/tracks/idris/exercises/leap/src/example.idr +8 -0
  70. data/tracks/{typescript/exercises → java}/.keep +0 -0
  71. data/tracks/java/config.json +115 -172
  72. data/tracks/java/exercises/anagram/src/test/java/AnagramTest.java +41 -13
  73. data/tracks/java/exercises/list-ops/build.gradle +18 -0
  74. data/tracks/java/exercises/list-ops/src/example/java/ListOps.java +51 -0
  75. data/tracks/java/exercises/list-ops/src/main/java/.keep +0 -0
  76. data/tracks/java/exercises/list-ops/src/test/java/ListOpsTest.java +316 -0
  77. data/tracks/java/exercises/palindrome-products/src/example/java/Palindromes.java +28 -62
  78. data/tracks/java/exercises/palindrome-products/src/test/java/PalindromesTest.java +26 -83
  79. data/tracks/java/exercises/settings.gradle +1 -0
  80. data/tracks/julia/config.json +1 -2
  81. data/tracks/julia/exercises/hello-world/example.jl +2 -2
  82. data/tracks/julia/exercises/hello-world/runtests.jl +1 -6
  83. data/tracks/lua/exercises/TRACK_HINTS.md +8 -0
  84. data/tracks/lua/exercises/hello-world/example.lua +2 -3
  85. data/tracks/lua/exercises/hello-world/hello-world.lua +18 -0
  86. data/tracks/lua/exercises/hello-world/hello-world_spec.lua +6 -12
  87. data/tracks/ocaml/exercises/phone-number/example.ml +8 -18
  88. data/tracks/ocaml/exercises/phone-number/phone_number.mli +1 -7
  89. data/tracks/ocaml/exercises/phone-number/test.ml +24 -23
  90. data/tracks/ocaml/tools/test-generator/src/special_cases.ml +6 -0
  91. data/tracks/ocaml/tools/test-generator/templates/phone-number/template.ml +21 -0
  92. data/tracks/pony/config.json +2 -2
  93. data/tracks/pony/exercises/hello-world/example.pony +1 -2
  94. data/tracks/pony/exercises/hello-world/test.pony +0 -1
  95. data/tracks/rust/config.json +0 -1
  96. data/tracks/rust/exercises/hello-world/example.rs +2 -5
  97. data/tracks/rust/exercises/hello-world/tests/hello-world.rs +2 -14
  98. data/tracks/scala/config.json +11 -2
  99. data/tracks/scala/docs/LEARNING.md +10 -2
  100. data/tracks/scala/docs/RESOURCES.md +0 -1
  101. data/tracks/scala/docs/TESTS.md +10 -6
  102. data/tracks/scala/exercises/rail-fence-cipher/build.sbt +3 -0
  103. data/tracks/scala/exercises/rail-fence-cipher/example.scala +46 -0
  104. data/tracks/scala/exercises/rail-fence-cipher/src/main/scala/RailFenceCipher.scala +0 -0
  105. data/tracks/scala/exercises/rail-fence-cipher/src/test/scala/RailFenceCipherTest.scala +42 -0
  106. data/tracks/scala/testgen/src/main/scala/RailFenceCipherTestGenerator.scala +59 -0
  107. data/tracks/typescript/.gitignore +7 -0
  108. data/tracks/typescript/.travis.yml +18 -1
  109. data/tracks/typescript/Dangerfile +43 -0
  110. data/tracks/typescript/Makefile +57 -0
  111. data/tracks/typescript/README.md +38 -5
  112. data/tracks/typescript/SETUP.md +24 -0
  113. data/tracks/typescript/common/package.json +37 -0
  114. data/tracks/typescript/common/tsconfig.json +21 -0
  115. data/tracks/typescript/common/tslint.json +127 -0
  116. data/tracks/typescript/common/yarn.lock +2697 -0
  117. data/tracks/typescript/config.json +82 -2
  118. data/tracks/typescript/docs/ABOUT.md +1 -0
  119. data/tracks/typescript/docs/INSTALLATION.md +17 -0
  120. data/tracks/typescript/docs/LEARNING.md +8 -0
  121. data/tracks/typescript/docs/RESOURCES.md +7 -0
  122. data/tracks/typescript/docs/TESTS.md +36 -0
  123. data/tracks/typescript/exercises/anagram/anagram.example.ts +23 -0
  124. data/tracks/typescript/exercises/anagram/anagram.test.ts +82 -0
  125. data/tracks/typescript/exercises/anagram/package.json +37 -0
  126. data/tracks/typescript/exercises/anagram/tsconfig.json +21 -0
  127. data/tracks/typescript/exercises/anagram/tslint.json +127 -0
  128. data/tracks/typescript/exercises/anagram/yarn.lock +2697 -0
  129. data/tracks/typescript/exercises/beer-song/beer-song.example.ts +36 -0
  130. data/tracks/typescript/exercises/beer-song/beer-song.test.ts +360 -0
  131. data/tracks/typescript/exercises/beer-song/package.json +37 -0
  132. data/tracks/typescript/exercises/beer-song/tsconfig.json +21 -0
  133. data/tracks/typescript/exercises/beer-song/tslint.json +127 -0
  134. data/tracks/typescript/exercises/beer-song/yarn.lock +2697 -0
  135. data/tracks/typescript/exercises/bob/bob.example.ts +24 -0
  136. data/tracks/typescript/exercises/bob/bob.test.ts +92 -0
  137. data/tracks/typescript/exercises/bob/package.json +37 -0
  138. data/tracks/typescript/exercises/bob/tsconfig.json +21 -0
  139. data/tracks/typescript/exercises/bob/tslint.json +127 -0
  140. data/tracks/typescript/exercises/bob/yarn.lock +2697 -0
  141. data/tracks/typescript/exercises/gigasecond/gigasecond.example.ts +11 -0
  142. data/tracks/typescript/exercises/gigasecond/gigasecond.test.ts +29 -0
  143. data/tracks/typescript/exercises/gigasecond/package.json +37 -0
  144. data/tracks/typescript/exercises/gigasecond/tsconfig.json +21 -0
  145. data/tracks/typescript/exercises/gigasecond/tslint.json +127 -0
  146. data/tracks/typescript/exercises/gigasecond/yarn.lock +2697 -0
  147. data/tracks/typescript/exercises/hamming/hamming.example.ts +19 -0
  148. data/tracks/typescript/exercises/hamming/hamming.test.ts +39 -0
  149. data/tracks/typescript/exercises/hamming/package.json +37 -0
  150. data/tracks/typescript/exercises/hamming/tsconfig.json +21 -0
  151. data/tracks/typescript/exercises/hamming/tslint.json +127 -0
  152. data/tracks/typescript/exercises/hamming/yarn.lock +2697 -0
  153. data/tracks/typescript/exercises/hello-world/hello-world.example.ts +8 -0
  154. data/tracks/typescript/exercises/hello-world/hello-world.test.ts +17 -0
  155. data/tracks/typescript/exercises/hello-world/package.json +37 -0
  156. data/tracks/typescript/exercises/hello-world/tsconfig.json +21 -0
  157. data/tracks/typescript/exercises/hello-world/tslint.json +127 -0
  158. data/tracks/typescript/exercises/hello-world/yarn.lock +2697 -0
  159. data/tracks/typescript/exercises/leap/leap.example.ts +6 -0
  160. data/tracks/typescript/exercises/leap/leap.test.ts +39 -0
  161. data/tracks/typescript/exercises/leap/package.json +37 -0
  162. data/tracks/typescript/exercises/leap/tsconfig.json +21 -0
  163. data/tracks/typescript/exercises/leap/tslint.json +127 -0
  164. data/tracks/typescript/exercises/leap/yarn.lock +2697 -0
  165. data/tracks/typescript/exercises/pangram/package.json +37 -0
  166. data/tracks/typescript/exercises/pangram/pangram.example.ts +32 -0
  167. data/tracks/typescript/exercises/pangram/pangram.test.ts +50 -0
  168. data/tracks/typescript/exercises/pangram/tsconfig.json +21 -0
  169. data/tracks/typescript/exercises/pangram/tslint.json +127 -0
  170. data/tracks/typescript/exercises/pangram/yarn.lock +2697 -0
  171. data/tracks/typescript/exercises/phone-number/package.json +37 -0
  172. data/tracks/typescript/exercises/phone-number/phone-number.example.ts +21 -0
  173. data/tracks/typescript/exercises/phone-number/phone-number.test.ts +55 -0
  174. data/tracks/typescript/exercises/phone-number/tsconfig.json +21 -0
  175. data/tracks/typescript/exercises/phone-number/tslint.json +127 -0
  176. data/tracks/typescript/exercises/phone-number/yarn.lock +2697 -0
  177. data/tracks/typescript/exercises/rna-transcription/package.json +37 -0
  178. data/tracks/typescript/exercises/rna-transcription/rna-transcription.example.ts +13 -0
  179. data/tracks/typescript/exercises/rna-transcription/rna-transcription.test.ts +45 -0
  180. data/tracks/typescript/exercises/rna-transcription/tsconfig.json +21 -0
  181. data/tracks/typescript/exercises/rna-transcription/tslint.json +127 -0
  182. data/tracks/typescript/exercises/rna-transcription/yarn.lock +2697 -0
  183. data/tracks/typescript/exercises/say/package.json +37 -0
  184. data/tracks/typescript/exercises/say/say.example.ts +95 -0
  185. data/tracks/typescript/exercises/say/say.test.ts +78 -0
  186. data/tracks/typescript/exercises/say/tsconfig.json +21 -0
  187. data/tracks/typescript/exercises/say/tslint.json +127 -0
  188. data/tracks/typescript/exercises/say/yarn.lock +2697 -0
  189. data/tracks/typescript/exercises/word-count/package.json +37 -0
  190. data/tracks/typescript/exercises/word-count/tsconfig.json +21 -0
  191. data/tracks/typescript/exercises/word-count/tslint.json +127 -0
  192. data/tracks/typescript/exercises/word-count/word-count.example.ts +16 -0
  193. data/tracks/typescript/exercises/word-count/word-count.test.ts +65 -0
  194. data/tracks/typescript/exercises/word-count/yarn.lock +2697 -0
  195. data/tracks/typescript/exercises/wordy/package.json +37 -0
  196. data/tracks/typescript/exercises/wordy/tsconfig.json +21 -0
  197. data/tracks/typescript/exercises/wordy/tslint.json +127 -0
  198. data/tracks/typescript/exercises/wordy/wordy.example.ts +40 -0
  199. data/tracks/typescript/exercises/wordy/wordy.test.ts +89 -0
  200. data/tracks/typescript/exercises/wordy/yarn.lock +2697 -0
  201. data/tracks/typescript/img/icon.png +0 -0
  202. data/tracks/typescript/img/icon.svg +10 -0
  203. metadata +134 -15
  204. data/tracks/erlang/exercises/binary/src/example.erl +0 -20
  205. data/tracks/erlang/exercises/binary/test/binary_string_tests.erl +0 -26
  206. data/tracks/erlang/exercises/trinary/Makefile +0 -10
  207. data/tracks/erlang/exercises/trinary/src/example.erl +0 -66
  208. data/tracks/erlang/exercises/trinary/test/trinary_tests.erl +0 -36
  209. data/tracks/fsharp/exercises/hello-world/HINTS.md +0 -5
@@ -1,77 +1,43 @@
1
-
2
- import java.util.ArrayList;
3
- import java.util.Arrays;
4
- import java.util.Collections;
5
- import java.util.List;
6
- import java.util.SortedMap;
7
- import java.util.TreeMap;
1
+ import java.util.*;
8
2
 
9
3
  public class Palindromes {
10
4
 
11
- public static class PalindromeSortedSetBuilder {
12
-
13
- private int minFactor = 1;
14
- private int maxFactor = 1;
15
-
16
- public PalindromeSortedSetBuilder() {
17
- }
18
-
19
- public PalindromeSortedSetBuilder withFactorsLessThanOrEqualTo(
20
- final int maxFactor) {
21
- this.maxFactor = maxFactor;
22
- return this;
23
- }
24
-
25
- public PalindromeSortedSetBuilder withFactorsGreaterThanOrEqualTo(
26
- final int minFactor) {
27
- this.minFactor = minFactor;
28
- return this;
29
- }
30
-
31
- public SortedMap<Long, List<List<Integer>>> build() {
32
- SortedMap<Long, List<List<Integer>>> palindromes = new TreeMap<>();
33
- long num;
34
- List<List<Integer>> factors;
35
- for (int i = this.maxFactor; i >= this.minFactor; i--) {
36
- for (int j = this.maxFactor; j >= i; j--) {
37
- num = i * j;
38
- if (isPalindrome(num)) {
39
- factors = palindromes.get(num);
40
- if (factors == null) {
41
- factors = new ArrayList<>();
42
- }
43
- factors.add(Arrays.asList(i, j));
44
- palindromes.put(num, factors);
5
+ public static SortedMap<Long, List<List<Integer>>> getPalindromeProductsWithFactors(int minFactor, int maxFactor) {
6
+ SortedMap<Long, List<List<Integer>>> palindromeSortedList = new TreeMap<>();
7
+ long num;
8
+ List<List<Integer>> factors;
9
+ for (int i = maxFactor; i >= minFactor; i--) {
10
+ for (int j = maxFactor; j >= i; j--) {
11
+ num = i * j;
12
+ if (isPalindrome(num)) {
13
+ factors = palindromeSortedList.get(num);
14
+ if (factors == null) {
15
+ factors = new ArrayList<>();
45
16
  }
17
+ factors.add(Arrays.asList(i, j));
18
+ palindromeSortedList.put(num, factors);
46
19
  }
47
20
  }
48
- return Collections.unmodifiableSortedMap(palindromes);
49
21
  }
22
+ return Collections.unmodifiableSortedMap(palindromeSortedList);
23
+ }
50
24
 
51
- // http://stackoverflow.com/questions/23984654/how-to-print-all-palindromes-upto-1000-without-using-any-string-stringbuilder
52
- private long reverseNumber(long number) {
53
- if (number < 10l) {
54
- return number;
55
- }
56
- long result = 0;
57
- long tmp = number;
58
- while (tmp > 0) {
59
- result = result * 10 + (tmp % 10);
60
- tmp /= 10;
61
-
62
- }
63
- return result;
25
+ // http://stackoverflow.com/questions/23984654/how-to-print-all-palindromes-upto-1000-without-using-any-string-stringbuilder
26
+ private static long reverseNumber(long number) {
27
+ if (number < 10l) {
28
+ return number;
64
29
  }
30
+ long result = 0;
31
+ long tmp = number;
32
+ while (tmp > 0) {
33
+ result = result * 10 + (tmp % 10);
34
+ tmp /= 10;
65
35
 
66
- private boolean isPalindrome(long number) {
67
- return number == reverseNumber(number);
68
36
  }
37
+ return result;
69
38
  }
70
39
 
71
- private Palindromes() {
72
- }
73
-
74
- public static PalindromeSortedSetBuilder getPalindromeSortedListBuilder() {
75
- return new PalindromeSortedSetBuilder();
40
+ private static boolean isPalindrome(long number) {
41
+ return number == reverseNumber(number);
76
42
  }
77
43
  }
@@ -1,14 +1,13 @@
1
+ import org.junit.Ignore;
2
+ import org.junit.Test;
1
3
 
2
4
  import java.util.Arrays;
3
5
  import java.util.Collections;
4
6
  import java.util.List;
5
7
  import java.util.SortedMap;
6
8
  import java.util.stream.Collectors;
7
- import static junit.framework.TestCase.assertEquals;
8
- import static junit.framework.TestCase.assertFalse;
9
- import static junit.framework.TestCase.assertNotNull;
10
- import org.junit.Ignore;
11
- import org.junit.Test;
9
+
10
+ import static junit.framework.TestCase.*;
12
11
 
13
12
  public class PalindromesTest {
14
13
 
@@ -22,22 +21,9 @@ public class PalindromesTest {
22
21
  );
23
22
  final long expectedValue = 9l;
24
23
 
25
- final SortedMap<Long, List<List<Integer>>> palindromes
26
- = Palindromes.getPalindromeSortedListBuilder()
27
- .withFactorsLessThanOrEqualTo(9).build();
28
-
29
- assertNotNull(palindromes);
30
- assertFalse(palindromes.isEmpty());
31
-
32
- long actualValue = palindromes.lastKey();
33
- assertEquals(expectedValue, actualValue);
24
+ final SortedMap<Long, List<List<Integer>>> palindromes = Palindromes.getPalindromeProductsWithFactors(1, 9);
34
25
 
35
- List<List<Integer>> actual = palindromes
36
- .get(palindromes.lastKey())
37
- .stream()
38
- .sorted((a, b) -> Integer.compare(a.get(0), b.get(0)))
39
- .collect(Collectors.toList());
40
- assertEquals(expected, actual);
26
+ checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.lastKey());
41
27
  }
42
28
 
43
29
  @Test
@@ -50,24 +36,9 @@ public class PalindromesTest {
50
36
  );
51
37
  final long expectedValue = 9009l;
52
38
 
53
- final SortedMap<Long, List<List<Integer>>> palindromes
54
- = Palindromes.getPalindromeSortedListBuilder()
55
- .withFactorsLessThanOrEqualTo(99)
56
- .withFactorsGreaterThanOrEqualTo(10)
57
- .build();
58
-
59
- assertNotNull(palindromes);
60
- assertFalse(palindromes.isEmpty());
39
+ final SortedMap<Long, List<List<Integer>>> palindromes = Palindromes.getPalindromeProductsWithFactors(10, 99);
61
40
 
62
- long actualValue = palindromes.lastKey();
63
- assertEquals(expectedValue, actualValue);
64
-
65
- List<List<Integer>> actual = palindromes
66
- .get(palindromes.lastKey())
67
- .stream()
68
- .sorted((a, b) -> Integer.compare(a.get(0), b.get(0)))
69
- .collect(Collectors.toList());
70
- assertEquals(expected, actual);
41
+ checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.lastKey());
71
42
  }
72
43
 
73
44
  @Test
@@ -80,24 +51,9 @@ public class PalindromesTest {
80
51
  );
81
52
  final long expectedValue = 121l;
82
53
 
83
- final SortedMap<Long, List<List<Integer>>> palindromes
84
- = Palindromes.getPalindromeSortedListBuilder()
85
- .withFactorsLessThanOrEqualTo(99)
86
- .withFactorsGreaterThanOrEqualTo(10)
87
- .build();
88
-
89
- assertNotNull(palindromes);
90
- assertFalse(palindromes.isEmpty());
54
+ final SortedMap<Long, List<List<Integer>>> palindromes = Palindromes.getPalindromeProductsWithFactors(10, 99);
91
55
 
92
- long actualValue = palindromes.firstKey();
93
- assertEquals(expectedValue, actualValue);
94
-
95
- List<List<Integer>> actual = palindromes
96
- .get(palindromes.firstKey())
97
- .stream()
98
- .sorted((a, b) -> Integer.compare(a.get(0), b.get(0)))
99
- .collect(Collectors.toList());
100
- assertEquals(expected, actual);
56
+ checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.firstKey());
101
57
  }
102
58
 
103
59
  @Test
@@ -110,24 +66,9 @@ public class PalindromesTest {
110
66
  );
111
67
  final long expectedValue = 906609l;
112
68
 
113
- final SortedMap<Long, List<List<Integer>>> palindromes
114
- = Palindromes.getPalindromeSortedListBuilder()
115
- .withFactorsLessThanOrEqualTo(999)
116
- .withFactorsGreaterThanOrEqualTo(100)
117
- .build();
118
-
119
- assertNotNull(palindromes);
120
- assertFalse(palindromes.isEmpty());
69
+ final SortedMap<Long, List<List<Integer>>> palindromes = Palindromes.getPalindromeProductsWithFactors(100, 999);
121
70
 
122
- long actualValue = palindromes.lastKey();
123
- assertEquals(expectedValue, actualValue);
124
-
125
- List<List<Integer>> actual = palindromes
126
- .get(palindromes.lastKey())
127
- .stream()
128
- .sorted((a, b) -> Integer.compare(a.get(0), b.get(0)))
129
- .collect(Collectors.toList());
130
- assertEquals(expected, actual);
71
+ checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.lastKey());
131
72
  }
132
73
 
133
74
  @Test
@@ -140,23 +81,25 @@ public class PalindromesTest {
140
81
  );
141
82
  final long expectedValue = 10201l;
142
83
 
143
- final SortedMap<Long, List<List<Integer>>> palindromes
144
- = Palindromes.getPalindromeSortedListBuilder()
145
- .withFactorsLessThanOrEqualTo(999)
146
- .withFactorsGreaterThanOrEqualTo(100)
147
- .build();
84
+ final SortedMap<Long, List<List<Integer>>> palindromes = Palindromes.getPalindromeProductsWithFactors(100, 999);
85
+
86
+ checkPalindromeWithFactorsMatchesExpected(expected, expectedValue, palindromes, palindromes.firstKey());
87
+ }
148
88
 
149
- assertNotNull(palindromes);
150
- assertFalse(palindromes.isEmpty());
89
+ private void checkPalindromeWithFactorsMatchesExpected(List<List<Integer>> expectedPalindromeFactors,
90
+ long expectedValueOfPalindrome,
91
+ SortedMap<Long, List<List<Integer>>> actualPalindromes,
92
+ long actualValueOfPalindrome) {
93
+ assertNotNull(actualPalindromes);
94
+ assertFalse(actualPalindromes.isEmpty());
151
95
 
152
- long actualValue = palindromes.firstKey();
153
- assertEquals(expectedValue, actualValue);
96
+ assertEquals(expectedValueOfPalindrome, actualValueOfPalindrome);
154
97
 
155
- List<List<Integer>> actual = palindromes
156
- .get(palindromes.firstKey())
98
+ List<List<Integer>> actualPalindromeFactors = actualPalindromes
99
+ .get(actualValueOfPalindrome)
157
100
  .stream()
158
101
  .sorted((a, b) -> Integer.compare(a.get(0), b.get(0)))
159
102
  .collect(Collectors.toList());
160
- assertEquals(expected, actual);
103
+ assertEquals(expectedPalindromeFactors, actualPalindromeFactors);
161
104
  }
162
105
  }
@@ -25,6 +25,7 @@ include 'hexadecimal'
25
25
  include 'hello-world'
26
26
  include 'largest-series-product'
27
27
  include 'linked-list'
28
+ include 'list-ops'
28
29
  include 'luhn'
29
30
  include 'matrix'
30
31
  include 'meetup'
@@ -8,8 +8,7 @@
8
8
  "slug": "hello-world",
9
9
  "difficulty": 1,
10
10
  "topics": [
11
- "strings",
12
- "string interpolation"
11
+ "strings"
13
12
  ]
14
13
  },
15
14
  {
@@ -1,3 +1,3 @@
1
- function hello(name::AbstractString="World")
2
- return "Hello, $(name)!"
1
+ function hello()
2
+ return "Hello, World!"
3
3
  end
@@ -2,11 +2,6 @@ using Base.Test
2
2
 
3
3
  include("hello-world.jl")
4
4
 
5
- @testset "no name" begin
5
+ @testset "Say Hi!" begin
6
6
  @test hello() == "Hello, World!"
7
7
  end
8
-
9
- @testset "names" begin
10
- @test hello("Alice") == "Hello, Alice!"
11
- @test hello("Bob") == "Hello, Bob!"
12
- end
@@ -0,0 +1,8 @@
1
+ ## Running the tests
2
+
3
+ To run the tests, run the command `busted .` from within the exercise directory.
4
+
5
+ ## Further information
6
+
7
+ For more detailed information about the Lua track, including how to get help if
8
+ you're having trouble, please visit the exercism.io [Lua language page](http://exercism.io/languages/lua/about).
@@ -1,8 +1,7 @@
1
1
  local hello_world = {}
2
2
 
3
- function hello_world.hello( name )
4
- if not name or name == '' then name = 'world' end
5
- return 'Hello, ' .. name .. '!'
3
+ function hello_world.hello()
4
+ return 'Hello, World!'
6
5
  end
7
6
 
8
7
  return hello_world
@@ -0,0 +1,18 @@
1
+ -- This is a "stub" file. It's a little start on your solution.
2
+ -- It's not a complete solution though; you have to write some code.
3
+
4
+ -- Table to be returned by the hello-world module.
5
+ local hello_world = {}
6
+
7
+ -- Add the hello() function to the table returned by this module.
8
+ function hello_world.hello()
9
+ -- Write some code here to pass the test suite.
10
+
11
+ -- When you have a working solution, REMOVE ALL THE STOCK COMMENTS.
12
+ -- They're here to help you get started but they only clutter a finished solution.
13
+ -- If you leave them in, reviewers will protest!
14
+ return ''
15
+ end
16
+
17
+ -- Return the hello_world table to make it accessible as a module.
18
+ return hello_world
@@ -1,18 +1,12 @@
1
+ -- Require the hello-world module
1
2
  local hello_world = require('hello-world')
2
3
 
4
+ -- Define a module named hello-world. This module should return a single
5
+ -- function named hello that takes no arguments and returns a string.
6
+
3
7
  describe('hello-world', function()
4
- it('says hello world with no name', function()
8
+ it('says hello world', function()
5
9
  local result = hello_world.hello()
6
- assert.are.equal('Hello, world!', result)
7
- end)
8
-
9
- it('says hello to Bob', function()
10
- local result = hello_world.hello('Bob')
11
- assert.are.equal('Hello, Bob!', result)
12
- end)
13
-
14
- it('says hello to Sally', function()
15
- local result = hello_world.hello('Sally')
16
- assert.are.equal('Hello, Sally!', result)
10
+ assert.are.equal('Hello, World!', result)
17
11
  end)
18
12
  end)
@@ -1,21 +1,11 @@
1
1
  open Core.Std
2
2
 
3
3
  let number s =
4
- let s' = String.filter ~f:Char.is_digit s in
5
- match String.length s' with
6
- | 10 -> Some s'
7
- | 11 when String.get s' 0 = '1' -> Some (String.drop_prefix s' 1)
8
- | _ -> None
9
-
10
- let split_number s =
11
- (String.slice s 0 3, String.slice s 3 6, String.slice s 6 10)
12
-
13
- let area_code s =
14
- let open Option in (* >>| for Option *)
15
- number s >>| split_number >>| (fun (area, _, _) -> area)
16
-
17
- let pretty s =
18
- let open Option in
19
- number s
20
- >>| split_number
21
- >>| fun (area, exch, subscr) -> sprintf "(%s) %s-%s" area exch subscr
4
+ if not @@ String.is_empty (String.filter ~f:(Char.is_alpha) s)
5
+ then None
6
+ else
7
+ let s = String.filter ~f:(Char.is_digit) s in
8
+ match String.length s with
9
+ | 10 -> Some s
10
+ | 11 when String.get s 0 = '1' -> Some (String.drop_prefix s 1)
11
+ | _ -> None
@@ -1,8 +1,2 @@
1
1
  (** Extract the digits from a valid phone number. *)
2
- val number : string -> string option
3
-
4
- (** Extract the area code from a valid phone number. *)
5
- val area_code : string -> string option
6
-
7
- (** Pretty print a valid phone number. *)
8
- val pretty : string -> string option
2
+ val number : string -> string option
@@ -1,5 +1,6 @@
1
1
  open Core.Std
2
2
  open OUnit2
3
+ open Phone_number
3
4
 
4
5
  let option_to_string f = function
5
6
  | None -> "None"
@@ -8,28 +9,28 @@ let option_to_string f = function
8
9
  let ae exp got _test_ctxt =
9
10
  assert_equal ~printer:(option_to_string String.to_string) exp got
10
11
 
11
- let tests =
12
- ["cleans number">::
13
- ae (Some "1234567890") (Phone_number.number "(123) 456-7890");
14
- "cleans number with dots">::
15
- ae (Some "1234567890") (Phone_number.number "123.456.7890");
16
- "valid when 11 digits and first is 1">::
17
- ae (Some "1234567890") (Phone_number.number "11234567890");
18
- "invalid when 11 digits">::
19
- ae None (Phone_number.number "21234567890");
20
- "invalid when 9 digits">::
21
- ae None (Phone_number.number "123456789");
22
- "area code">::
23
- ae (Some "123") (Phone_number.area_code "1234567890");
24
- "area code of invalid number">::
25
- ae None (Phone_number.area_code "1234567890123");
26
- "pretty print">::
27
- ae (Some "(123) 456-7890") (Phone_number.pretty "1234567890");
28
- "pretty print with full us phone number">::
29
- ae (Some "(123) 456-7890") (Phone_number.pretty "11234567890");
30
- "pretty print invalid number">::
31
- ae None (Phone_number.pretty "123456789");
32
- ]
12
+ let number_tests = [
13
+ "cleans the number" >::
14
+ ae (Some "1234567890") (number "(123) 456-7890");
15
+ "cleans numbers with dots" >::
16
+ ae (Some "1234567890") (number "123.456.7890");
17
+ "cleans numbers with multiple spaces" >::
18
+ ae (Some "1234567890") (number "123 456 7890 ");
19
+ "invalid when 9 digits" >::
20
+ ae None (number "123456789");
21
+ "invalid when 11 digits" >::
22
+ ae None (number "21234567890");
23
+ "valid when 11 digits and starting with 1" >::
24
+ ae (Some "1234567890") (number "11234567890");
25
+ "invalid when 12 digits" >::
26
+ ae None (number "321234567890");
27
+ "invalid with letters" >::
28
+ ae None (number "123-abc-7890");
29
+ "invalid with punctuations" >::
30
+ ae None (number "123-@:!-7890");
31
+ "invalid with right number of digits but letters mixed in" >::
32
+ ae None (number "1a2b3c4d5e6f7g8h9i0j");
33
+ ]
33
34
 
34
35
  let () =
35
- run_test_tt_main ("phone-number tests" >::: tests)
36
+ run_test_tt_main ("phone-number tests" >::: number_tests)