trackler 2.2.1.71 → 2.2.1.72

Sign up to get free protection for your applications and to get access to all the features.
Files changed (270) hide show
  1. checksums.yaml +4 -4
  2. data/lib/trackler/version.rb +1 -1
  3. data/problem-specifications/exercises/book-store/canonical-data.json +9 -2
  4. data/problem-specifications/exercises/word-count/canonical-data.json +9 -0
  5. data/tracks/bash/CONTRIBUTING.md +199 -0
  6. data/tracks/bash/config.json +24 -11
  7. data/tracks/bash/exercises/triangle/README.md +38 -0
  8. data/tracks/bash/exercises/triangle/example.sh +56 -0
  9. data/tracks/bash/exercises/triangle/triangle_test.sh +126 -0
  10. data/tracks/bash/img/canonical-data-example.png +0 -0
  11. data/tracks/bash/img/create-pr.png +0 -0
  12. data/tracks/bash/img/fork-repository.png +0 -0
  13. data/tracks/c/exercises/acronym/makefile +1 -1
  14. data/tracks/c/exercises/all-your-base/makefile +1 -1
  15. data/tracks/c/exercises/allergies/makefile +1 -1
  16. data/tracks/c/exercises/anagram/makefile +1 -1
  17. data/tracks/c/exercises/atbash-cipher/makefile +1 -1
  18. data/tracks/c/exercises/beer-song/makefile +1 -1
  19. data/tracks/c/exercises/binary-search/makefile +1 -1
  20. data/tracks/c/exercises/binary/makefile +1 -1
  21. data/tracks/c/exercises/bob/makefile +1 -1
  22. data/tracks/c/exercises/clock/makefile +1 -1
  23. data/tracks/c/exercises/collatz-conjecture/makefile +1 -1
  24. data/tracks/c/exercises/difference-of-squares/makefile +1 -1
  25. data/tracks/c/exercises/gigasecond/makefile +1 -1
  26. data/tracks/c/exercises/grains/makefile +1 -1
  27. data/tracks/c/exercises/hamming/makefile +1 -1
  28. data/tracks/c/exercises/hamming/test/test_hamming.c +2 -2
  29. data/tracks/c/exercises/hello-world/makefile +1 -1
  30. data/tracks/c/exercises/isogram/makefile +1 -1
  31. data/tracks/c/exercises/largest-series-product/makefile +1 -1
  32. data/tracks/c/exercises/leap/makefile +1 -1
  33. data/tracks/c/exercises/meetup/makefile +1 -1
  34. data/tracks/c/exercises/nth-prime/makefile +1 -1
  35. data/tracks/c/exercises/nucleotide-count/makefile +1 -1
  36. data/tracks/c/exercises/palindrome-products/makefile +1 -1
  37. data/tracks/c/exercises/pangram/makefile +1 -1
  38. data/tracks/c/exercises/pascals-triangle/makefile +1 -1
  39. data/tracks/c/exercises/perfect-numbers/makefile +1 -1
  40. data/tracks/c/exercises/phone-number/makefile +1 -1
  41. data/tracks/c/exercises/queen-attack/makefile +1 -1
  42. data/tracks/c/exercises/raindrops/makefile +1 -1
  43. data/tracks/c/exercises/react/makefile +1 -1
  44. data/tracks/c/exercises/rna-transcription/makefile +1 -1
  45. data/tracks/c/exercises/robot-simulator/makefile +1 -1
  46. data/tracks/c/exercises/roman-numerals/makefile +1 -1
  47. data/tracks/c/exercises/scrabble-score/makefile +1 -1
  48. data/tracks/c/exercises/series/makefile +1 -1
  49. data/tracks/c/exercises/sieve/makefile +1 -1
  50. data/tracks/c/exercises/space-age/makefile +1 -1
  51. data/tracks/c/exercises/sublist/makefile +1 -1
  52. data/tracks/c/exercises/sum-of-multiples/makefile +1 -1
  53. data/tracks/c/exercises/triangle/makefile +1 -1
  54. data/tracks/c/exercises/word-count/makefile +1 -1
  55. data/tracks/delphi/exercises/allergies/README.md +1 -1
  56. data/tracks/delphi/exercises/bank-account/README.md +1 -1
  57. data/tracks/delphi/exercises/beer-song/README.md +1 -1
  58. data/tracks/delphi/exercises/binary-search/README.md +1 -1
  59. data/tracks/delphi/exercises/bob/README.md +1 -1
  60. data/tracks/delphi/exercises/book-store/README.md +1 -1
  61. data/tracks/delphi/exercises/book-store/uBookStoreExample.pas +34 -14
  62. data/tracks/delphi/exercises/book-store/uBookStoreTests.pas +36 -1
  63. data/tracks/delphi/exercises/bowling/README.md +1 -1
  64. data/tracks/delphi/exercises/circular-buffer/README.md +1 -1
  65. data/tracks/delphi/exercises/clock/README.md +1 -1
  66. data/tracks/delphi/exercises/collatz-conjecture/README.md +1 -1
  67. data/tracks/delphi/exercises/etl/README.md +1 -1
  68. data/tracks/delphi/exercises/grains/README.md +1 -1
  69. data/tracks/delphi/exercises/hamming/README.md +1 -1
  70. data/tracks/delphi/exercises/hello-world/README.md +1 -1
  71. data/tracks/delphi/exercises/leap/README.md +1 -1
  72. data/tracks/delphi/exercises/minesweeper/README.md +1 -1
  73. data/tracks/delphi/exercises/nucleotide-count/README.md +1 -1
  74. data/tracks/delphi/exercises/perfect-numbers/README.md +1 -1
  75. data/tracks/delphi/exercises/phone-number/README.md +1 -1
  76. data/tracks/delphi/exercises/pig-latin/README.md +1 -1
  77. data/tracks/delphi/exercises/poker/README.md +1 -1
  78. data/tracks/delphi/exercises/raindrops/README.md +1 -1
  79. data/tracks/delphi/exercises/reverse-string/README.md +1 -1
  80. data/tracks/delphi/exercises/rna-transcription/README.md +1 -1
  81. data/tracks/delphi/exercises/roman-numerals/README.md +1 -1
  82. data/tracks/delphi/exercises/saddle-points/README.md +1 -1
  83. data/tracks/delphi/exercises/triangle/README.md +1 -1
  84. data/tracks/delphi/exercises/two-fer/README.md +1 -1
  85. data/tracks/delphi/exercises/wordy/README.md +1 -1
  86. data/tracks/ecmascript/.travis.yml +1 -1
  87. data/tracks/ecmascript/Makefile +4 -5
  88. data/tracks/ecmascript/README.md +2 -1
  89. data/tracks/ecmascript/config.json +12 -0
  90. data/tracks/ecmascript/exercises/change/package.json +5 -3
  91. data/tracks/ecmascript/exercises/protein-translation/package.json +2 -2
  92. data/tracks/ecmascript/exercises/react/README.md +41 -0
  93. data/tracks/ecmascript/exercises/react/example.js +101 -0
  94. data/tracks/ecmascript/exercises/react/package.json +71 -0
  95. data/tracks/ecmascript/exercises/react/react.spec.js +211 -0
  96. data/tracks/ecmascript/exercises/rectangles/package.json +1 -2
  97. data/tracks/ecmascript/exercises/rotational-cipher/package.json +1 -2
  98. data/tracks/ecmascript/exercises/spiral-matrix/package.json +1 -2
  99. data/tracks/ecmascript/exercises/transpose/package.json +2 -2
  100. data/tracks/erlang/docs/ABOUT.md +1 -1
  101. data/tracks/go/exercises/binary-search/.meta/gen.go +55 -0
  102. data/tracks/go/exercises/binary-search/binary_search_test.go +26 -167
  103. data/tracks/go/exercises/binary-search/cases_test.go +73 -0
  104. data/tracks/go/exercises/binary-search/example.go +8 -30
  105. data/tracks/go/exercises/nth-prime/.meta/gen.go +76 -0
  106. data/tracks/go/exercises/nth-prime/cases_test.go +43 -0
  107. data/tracks/go/exercises/nth-prime/nth_prime_test.go +4 -18
  108. data/tracks/go/exercises/prime-factors/.meta/gen.go +54 -0
  109. data/tracks/go/exercises/prime-factors/cases_test.go +48 -0
  110. data/tracks/go/exercises/prime-factors/prime_factors_test.go +4 -19
  111. data/tracks/groovy/config.json +13 -1
  112. data/tracks/groovy/exercises/linked-list/DoubleLinkedList.groovy +19 -0
  113. data/tracks/groovy/exercises/linked-list/DoubleLinkedListSpec.groovy +79 -0
  114. data/tracks/groovy/exercises/linked-list/Example.groovy +57 -0
  115. data/tracks/groovy/exercises/linked-list/README.md +49 -0
  116. data/tracks/java/bin/run-journey-test-from-ci.sh +1 -1
  117. data/tracks/java/config.json +10 -0
  118. data/tracks/java/config/maintainers.json +8 -1
  119. data/tracks/java/docs/MAINTAINING.md +3 -3
  120. data/tracks/java/exercises/accumulate/.meta/src/reference/java/Accumulate.java +2 -2
  121. data/tracks/java/exercises/binary/.meta/src/reference/java/Binary.java +3 -3
  122. data/tracks/java/exercises/circular-buffer/.meta/src/reference/java/BufferIOException.java +1 -1
  123. data/tracks/java/exercises/circular-buffer/.meta/src/reference/java/CircularBuffer.java +6 -6
  124. data/tracks/java/exercises/circular-buffer/src/main/java/BufferIOException.java +1 -1
  125. data/tracks/java/exercises/clock/.meta/src/reference/java/Clock.java +3 -3
  126. data/tracks/java/exercises/crypto-square/.meta/src/reference/java/Crypto.java +7 -7
  127. data/tracks/java/exercises/etl/.meta/src/reference/java/Etl.java +2 -2
  128. data/tracks/java/exercises/etl/src/main/java/Etl.java +2 -2
  129. data/tracks/java/exercises/kindergarten-garden/.meta/src/reference/java/KindergartenGarden.java +4 -4
  130. data/tracks/java/exercises/kindergarten-garden/.meta/src/reference/java/Plant.java +2 -2
  131. data/tracks/java/exercises/kindergarten-garden/src/main/java/Plant.java +2 -2
  132. data/tracks/java/exercises/nth-prime/.meta/src/reference/java/PrimeCalculator.java +2 -2
  133. data/tracks/java/exercises/reverse-string/.meta/src/reference/java/ReverseString.java +7 -0
  134. data/tracks/java/exercises/reverse-string/.meta/version +1 -0
  135. data/tracks/java/exercises/reverse-string/README.md +25 -0
  136. data/tracks/java/exercises/reverse-string/build.gradle +17 -0
  137. data/tracks/java/exercises/reverse-string/src/main/java/ReverseString.java +7 -0
  138. data/tracks/java/exercises/reverse-string/src/test/java/ReverseStringTest.java +37 -0
  139. data/tracks/java/exercises/run-length-encoding/.meta/src/reference/java/RunLengthEncoding.java +4 -4
  140. data/tracks/java/exercises/settings.gradle +1 -0
  141. data/tracks/kotlin/docs/RESOURCES.md +1 -1
  142. data/tracks/kotlin/exercises/accumulate/build.gradle +1 -1
  143. data/tracks/kotlin/exercises/acronym/build.gradle +1 -1
  144. data/tracks/kotlin/exercises/all-your-base/build.gradle +1 -1
  145. data/tracks/kotlin/exercises/allergies/build.gradle +1 -1
  146. data/tracks/kotlin/exercises/anagram/build.gradle +1 -1
  147. data/tracks/kotlin/exercises/atbash-cipher/build.gradle +1 -1
  148. data/tracks/kotlin/exercises/bank-account/build.gradle +1 -1
  149. data/tracks/kotlin/exercises/beer-song/build.gradle +1 -1
  150. data/tracks/kotlin/exercises/binary-search/build.gradle +1 -1
  151. data/tracks/kotlin/exercises/binary/build.gradle +1 -1
  152. data/tracks/kotlin/exercises/bob/build.gradle +1 -1
  153. data/tracks/kotlin/exercises/bracket-push/build.gradle +1 -1
  154. data/tracks/kotlin/exercises/change/build.gradle +1 -1
  155. data/tracks/kotlin/exercises/clock/build.gradle +1 -1
  156. data/tracks/kotlin/exercises/collatz-conjecture/build.gradle +1 -1
  157. data/tracks/kotlin/exercises/complex-numbers/build.gradle +1 -1
  158. data/tracks/kotlin/exercises/diamond/build.gradle +1 -1
  159. data/tracks/kotlin/exercises/difference-of-squares/build.gradle +1 -1
  160. data/tracks/kotlin/exercises/etl/build.gradle +1 -1
  161. data/tracks/kotlin/exercises/flatten-array/build.gradle +1 -1
  162. data/tracks/kotlin/exercises/forth/build.gradle +1 -1
  163. data/tracks/kotlin/exercises/gigasecond/build.gradle +1 -1
  164. data/tracks/kotlin/exercises/grade-school/build.gradle +1 -1
  165. data/tracks/kotlin/exercises/grains/build.gradle +1 -1
  166. data/tracks/kotlin/exercises/hamming/build.gradle +1 -1
  167. data/tracks/kotlin/exercises/hello-world/build.gradle +1 -1
  168. data/tracks/kotlin/exercises/hexadecimal/build.gradle +1 -1
  169. data/tracks/kotlin/exercises/isogram/build.gradle +1 -1
  170. data/tracks/kotlin/exercises/largest-series-product/build.gradle +1 -1
  171. data/tracks/kotlin/exercises/leap/build.gradle +1 -1
  172. data/tracks/kotlin/exercises/linked-list/build.gradle +1 -1
  173. data/tracks/kotlin/exercises/list-ops/build.gradle +1 -1
  174. data/tracks/kotlin/exercises/luhn/build.gradle +1 -1
  175. data/tracks/kotlin/exercises/meetup/build.gradle +1 -1
  176. data/tracks/kotlin/exercises/minesweeper/build.gradle +1 -1
  177. data/tracks/kotlin/exercises/nth-prime/build.gradle +1 -1
  178. data/tracks/kotlin/exercises/nucleotide-count/build.gradle +1 -1
  179. data/tracks/kotlin/exercises/pangram/build.gradle +1 -1
  180. data/tracks/kotlin/exercises/pascals-triangle/build.gradle +1 -1
  181. data/tracks/kotlin/exercises/perfect-numbers/build.gradle +1 -1
  182. data/tracks/kotlin/exercises/phone-number/build.gradle +1 -1
  183. data/tracks/kotlin/exercises/pig-latin/build.gradle +1 -1
  184. data/tracks/kotlin/exercises/prime-factors/build.gradle +1 -1
  185. data/tracks/kotlin/exercises/raindrops/build.gradle +1 -1
  186. data/tracks/kotlin/exercises/react/build.gradle +1 -1
  187. data/tracks/kotlin/exercises/rna-transcription/build.gradle +1 -1
  188. data/tracks/kotlin/exercises/robot-name/build.gradle +1 -1
  189. data/tracks/kotlin/exercises/robot-simulator/build.gradle +1 -1
  190. data/tracks/kotlin/exercises/roman-numerals/build.gradle +1 -1
  191. data/tracks/kotlin/exercises/rotational-cipher/build.gradle +1 -1
  192. data/tracks/kotlin/exercises/saddle-points/build.gradle +1 -1
  193. data/tracks/kotlin/exercises/say/build.gradle +1 -1
  194. data/tracks/kotlin/exercises/scrabble-score/build.gradle +1 -1
  195. data/tracks/kotlin/exercises/secret-handshake/build.gradle +1 -1
  196. data/tracks/kotlin/exercises/series/build.gradle +1 -1
  197. data/tracks/kotlin/exercises/sieve/build.gradle +1 -1
  198. data/tracks/kotlin/exercises/simple-cipher/README.md +4 -6
  199. data/tracks/kotlin/exercises/simple-cipher/build.gradle +1 -1
  200. data/tracks/kotlin/exercises/space-age/build.gradle +1 -1
  201. data/tracks/kotlin/exercises/spiral-matrix/build.gradle +1 -1
  202. data/tracks/kotlin/exercises/strain/build.gradle +1 -1
  203. data/tracks/kotlin/exercises/sublist/build.gradle +1 -1
  204. data/tracks/kotlin/exercises/sum-of-multiples/build.gradle +1 -1
  205. data/tracks/kotlin/exercises/triangle/build.gradle +1 -1
  206. data/tracks/kotlin/exercises/two-fer/build.gradle +1 -1
  207. data/tracks/kotlin/exercises/word-count/build.gradle +1 -1
  208. data/tracks/lua/.gitignore +1 -0
  209. data/tracks/lua/config.json +12 -0
  210. data/tracks/lua/exercises/isbn-verifier/README.md +52 -0
  211. data/tracks/lua/exercises/isbn-verifier/example.lua +16 -0
  212. data/tracks/lua/exercises/isbn-verifier/isbn-verifier_spec.lua +55 -0
  213. data/tracks/ocaml/.travis-ci.sh +1 -1
  214. data/tracks/ocaml/.travis.yml +1 -1
  215. data/tracks/ocaml/README.md +1 -1
  216. data/tracks/perl6/config.json +10 -0
  217. data/tracks/perl6/exercises/acronym/Acronym.pm6 +4 -0
  218. data/tracks/perl6/exercises/acronym/Example.pm6 +5 -0
  219. data/tracks/perl6/exercises/acronym/README.md +33 -0
  220. data/tracks/perl6/exercises/acronym/acronym.t +96 -0
  221. data/tracks/perl6/exercises/acronym/example.yaml +19 -0
  222. data/tracks/perl6/exercises/word-count/Example.pm6 +1 -1
  223. data/tracks/perl6/exercises/word-count/WordCount.pm6 +1 -1
  224. data/tracks/perl6/exercises/word-count/example.yaml +2 -2
  225. data/tracks/perl6/exercises/word-count/word-count.t +11 -2
  226. data/tracks/pony/docs/RESOURCES.md +1 -1
  227. data/tracks/purescript/docs/INSTALLATION.md +1 -3
  228. data/tracks/python/config.json +1 -1
  229. data/tracks/r/exercises/word-count/test_word-count.R +5 -0
  230. data/tracks/ruby/README.md +73 -10
  231. data/tracks/rust/config.json +34 -0
  232. data/tracks/rust/exercises/book-store/Cargo.toml +1 -1
  233. data/tracks/rust/exercises/book-store/tests/book-store.rs +7 -0
  234. data/tracks/rust/exercises/diffie-hellman/.gitignore +9 -0
  235. data/tracks/rust/exercises/diffie-hellman/Cargo-example.toml +6 -0
  236. data/tracks/rust/exercises/diffie-hellman/Cargo.toml +5 -0
  237. data/tracks/rust/exercises/diffie-hellman/README.md +77 -0
  238. data/tracks/rust/exercises/diffie-hellman/example.rs +15 -0
  239. data/tracks/rust/exercises/diffie-hellman/src/lib.rs +11 -0
  240. data/tracks/rust/exercises/diffie-hellman/tests/diffie-hellman.rs +60 -0
  241. data/tracks/rust/exercises/macros/.gitignore +3 -0
  242. data/tracks/rust/exercises/macros/.meta/description.md +29 -0
  243. data/tracks/rust/exercises/macros/.meta/metadata.yml +3 -0
  244. data/tracks/rust/exercises/macros/Cargo.toml +6 -0
  245. data/tracks/rust/exercises/macros/README.md +70 -0
  246. data/tracks/rust/exercises/macros/example.rs +16 -0
  247. data/tracks/rust/exercises/macros/src/lib.rs +6 -0
  248. data/tracks/rust/exercises/macros/tests/macros.rs +62 -0
  249. data/tracks/rust/exercises/simple-linked-list/.gitignore +7 -0
  250. data/tracks/rust/exercises/simple-linked-list/.meta/hints.md +34 -0
  251. data/tracks/rust/exercises/simple-linked-list/Cargo.toml +5 -0
  252. data/tracks/rust/exercises/simple-linked-list/README.md +96 -0
  253. data/tracks/rust/exercises/simple-linked-list/example.rs +87 -0
  254. data/tracks/rust/exercises/simple-linked-list/src/lib.rs +46 -0
  255. data/tracks/rust/exercises/simple-linked-list/tests/simple-linked-list.rs +91 -0
  256. data/tracks/swift/.travis.yml +1 -1
  257. data/tracks/swift/config.json +24 -0
  258. data/tracks/swift/exercises/isbn-verifier/Package.swift +5 -0
  259. data/tracks/swift/exercises/isbn-verifier/README.md +39 -0
  260. data/tracks/swift/exercises/isbn-verifier/Sources/IsbnVerifier.swift +1 -0
  261. data/tracks/swift/exercises/isbn-verifier/Sources/IsbnVerifierExample.swift +35 -0
  262. data/tracks/swift/exercises/isbn-verifier/Tests/IsbnVerifierTests/IsbnVerifierTests.swift +75 -0
  263. data/tracks/swift/exercises/isbn-verifier/Tests/LinuxMain.swift +6 -0
  264. data/tracks/swift/exercises/two-fer/Package.swift +5 -0
  265. data/tracks/swift/exercises/two-fer/README.md +54 -0
  266. data/tracks/swift/exercises/two-fer/Sources/TwoFer.swift +1 -0
  267. data/tracks/swift/exercises/two-fer/Sources/TwoFerExample.swift +6 -0
  268. data/tracks/swift/exercises/two-fer/Tests/LinuxMain.swift +6 -0
  269. data/tracks/swift/exercises/two-fer/Tests/TwoFerTests/TwoFerTests.swift +25 -0
  270. metadata +71 -2
@@ -0,0 +1,76 @@
1
+ package main
2
+
3
+ import (
4
+ "log"
5
+ "text/template"
6
+
7
+ "../../../gen"
8
+ )
9
+
10
+ func main() {
11
+ t, err := template.New("").Parse(tmpl)
12
+ if err != nil {
13
+ log.Fatal(err)
14
+ }
15
+ var j js
16
+ if err := gen.Gen("nth-prime", &j, t); err != nil {
17
+ log.Fatal(err)
18
+ }
19
+ }
20
+
21
+ type OneCase struct {
22
+ Description string
23
+ Input int
24
+ Expected interface{}
25
+ }
26
+
27
+ // The JSON structure we expect to be able to unmarshal into
28
+ type js struct {
29
+ Cases []OneCase
30
+ }
31
+
32
+ func (c OneCase) HasPrimeAnswer() bool {
33
+ hasPrimeAnswer, _ := determineExpected(c.Expected)
34
+ return hasPrimeAnswer
35
+ }
36
+
37
+ func (c OneCase) PrimeAnswer() int {
38
+ _, answer := determineExpected(c.Expected)
39
+ return answer
40
+ }
41
+
42
+ // determineExpected examines an .Expected interface{} object and determines
43
+ // whether a test case has a Prime answer or expects an error,
44
+ // returning true and the answer, or false and zero.
45
+ func determineExpected(expected interface{}) (bool, int) {
46
+ value, ok := expected.(float64)
47
+ if ok {
48
+ return true, int(value)
49
+ }
50
+ return false, 0
51
+ }
52
+
53
+ // template applied to above data structure generates the Go test cases
54
+ var tmpl = `package prime
55
+
56
+ {{.Header}}
57
+
58
+ var tests = []struct {
59
+ description string
60
+ n int
61
+ p int
62
+ ok bool
63
+ }{
64
+ {{range .J.Cases}}{
65
+ "{{.Description}}",
66
+ {{.Input}},
67
+ {{- if .HasPrimeAnswer}}
68
+ {{.PrimeAnswer}},
69
+ true,
70
+ {{- else}}
71
+ 0,
72
+ false,
73
+ {{- end}}
74
+ },
75
+ {{end}}}
76
+ `
@@ -0,0 +1,43 @@
1
+ package prime
2
+
3
+ // Source: exercism/problem-specifications
4
+ // Commit: e82cbcd nth-prime: Use object instead of bool for invalid value (#969)
5
+ // Problem Specifications Version: 2.0.0
6
+
7
+ var tests = []struct {
8
+ description string
9
+ n int
10
+ p int
11
+ ok bool
12
+ }{
13
+ {
14
+ "first prime",
15
+ 1,
16
+ 2,
17
+ true,
18
+ },
19
+ {
20
+ "second prime",
21
+ 2,
22
+ 3,
23
+ true,
24
+ },
25
+ {
26
+ "sixth prime",
27
+ 6,
28
+ 13,
29
+ true,
30
+ },
31
+ {
32
+ "big prime",
33
+ 10001,
34
+ 104743,
35
+ true,
36
+ },
37
+ {
38
+ "there is no zeroth prime",
39
+ 0,
40
+ 0,
41
+ false,
42
+ },
43
+ }
@@ -2,33 +2,19 @@ package prime
2
2
 
3
3
  import "testing"
4
4
 
5
- var tests = []struct {
6
- n int
7
- p int
8
- ok bool
9
- }{
10
- {1, 2, true},
11
- {2, 3, true},
12
- {3, 5, true},
13
- {4, 7, true},
14
- {5, 11, true},
15
- {6, 13, true},
16
- {10001, 104743, true},
17
- {0, 0, false},
18
- }
19
-
20
5
  func TestNth(t *testing.T) {
21
6
  for _, test := range tests {
22
7
  switch p, ok := Nth(test.n); {
23
8
  case !ok:
24
9
  if test.ok {
25
- t.Fatalf("Nth(%d) returned !ok. Expecting ok.", test.n)
10
+ t.Fatalf("FAIL %s\nNth(%d) returned !ok. Expecting ok.", test.description, test.n)
26
11
  }
27
12
  case !test.ok:
28
- t.Fatalf("Nth(%d) = %d, ok = %t. Expecting !ok.", test.n, p, ok)
13
+ t.Fatalf("FAIL %s\nNth(%d) = %d, ok = %t. Expecting !ok.", test.description, test.n, p, ok)
29
14
  case p != test.p:
30
- t.Fatalf("Nth(%d) = %d, want %d.", test.n, p, test.p)
15
+ t.Fatalf("FAIL %s\nNth(%d) = %d, want %d.", test.description, test.n, p, test.p)
31
16
  }
17
+ t.Logf("PASS %s", test.description)
32
18
  }
33
19
  }
34
20
 
@@ -0,0 +1,54 @@
1
+ package main
2
+
3
+ import (
4
+ "log"
5
+ "text/template"
6
+
7
+ "../../../gen"
8
+ )
9
+
10
+ func main() {
11
+ t, err := template.New("").Parse(tmpl)
12
+ if err != nil {
13
+ log.Fatal(err)
14
+ }
15
+ var j js
16
+ if err := gen.Gen("prime-factors", &j, t); err != nil {
17
+ log.Fatal(err)
18
+ }
19
+ }
20
+
21
+ // The JSON structure we expect to be able to unmarshal into
22
+ type js struct {
23
+ Groups []TestGroup `json:"cases"`
24
+ }
25
+
26
+ type TestGroup struct {
27
+ Description string
28
+ Cases []OneCase
29
+ }
30
+
31
+ type OneCase struct {
32
+ Description string
33
+ Input int64
34
+ Expected []int64
35
+ }
36
+
37
+ // template applied to above data structure generates the Go test cases
38
+ var tmpl = `package prime
39
+
40
+ {{.Header}}
41
+
42
+ var tests = []struct {
43
+ description string
44
+ input int64
45
+ expected []int64
46
+ }{
47
+ {{range .J.Groups}}
48
+ {{range .Cases}} {
49
+ "{{.Description}}",
50
+ {{.Input}},
51
+ {{printf "%#v" .Expected}},
52
+ },
53
+ {{end}}{{end}}}
54
+ `
@@ -0,0 +1,48 @@
1
+ package prime
2
+
3
+ // Source: exercism/problem-specifications
4
+ // Commit: bf5bb2b prime-factors: Fix canonical-data.json formatting
5
+ // Problem Specifications Version: 1.0.0
6
+
7
+ var tests = []struct {
8
+ description string
9
+ input int64
10
+ expected []int64
11
+ }{
12
+
13
+ {
14
+ "no factors",
15
+ 1,
16
+ []int64{},
17
+ },
18
+ {
19
+ "prime number",
20
+ 2,
21
+ []int64{2},
22
+ },
23
+ {
24
+ "square of a prime",
25
+ 9,
26
+ []int64{3, 3},
27
+ },
28
+ {
29
+ "cube of a prime",
30
+ 8,
31
+ []int64{2, 2, 2},
32
+ },
33
+ {
34
+ "product of primes and non-primes",
35
+ 12,
36
+ []int64{2, 2, 3},
37
+ },
38
+ {
39
+ "product of primes",
40
+ 901255,
41
+ []int64{5, 17, 23, 461},
42
+ },
43
+ {
44
+ "factors include a large prime",
45
+ 93819012551,
46
+ []int64{11, 9539, 894119},
47
+ },
48
+ }
@@ -7,30 +7,15 @@ import (
7
7
  "testing"
8
8
  )
9
9
 
10
- var tests = []struct {
11
- input int64
12
- expected []int64
13
- }{
14
- {1, []int64{}},
15
- {2, []int64{2}},
16
- {3, []int64{3}},
17
- {4, []int64{2, 2}},
18
- {6, []int64{2, 3}},
19
- {8, []int64{2, 2, 2}},
20
- {9, []int64{3, 3}},
21
- {27, []int64{3, 3, 3}},
22
- {625, []int64{5, 5, 5, 5}},
23
- {901255, []int64{5, 17, 23, 461}},
24
- {93819012551, []int64{11, 9539, 894119}},
25
- }
26
-
27
10
  func TestPrimeFactors(t *testing.T) {
28
11
  for _, test := range tests {
29
12
  actual := Factors(test.input)
30
13
  if !reflect.DeepEqual(actual, test.expected) {
31
- t.Errorf("prime.Factors(%d) = %#v; expected %#v",
32
- test.input, actual, test.expected)
14
+ t.Fatalf("FAIL %s\nFactors(%d) = %#v;\nexpected %#v",
15
+ test.description, test.input,
16
+ actual, test.expected)
33
17
  }
18
+ t.Logf("PASS %s", test.description)
34
19
  }
35
20
  }
36
21
 
@@ -180,9 +180,21 @@
180
180
  ],
181
181
  "unlocked_by": null,
182
182
  "uuid": "aa34b8a4-6958-42d4-b0ca-d846811afef1"
183
+ },
184
+ {
185
+ "core": true,
186
+ "difficulty": 6,
187
+ "slug": "linked-list",
188
+ "topics": [
189
+ "algorithms",
190
+ "generics",
191
+ "lists"
192
+ ],
193
+ "unlocked_by": null,
194
+ "uuid": "6a5e6d90-e0f3-43e7-8088-a4137bf2b125"
183
195
  }
184
196
  ],
185
197
  "foregone": [],
186
198
  "language": "Groovy",
187
199
  "test_pattern": "(Spec)[.]groovy"
188
- }
200
+ }
@@ -0,0 +1,19 @@
1
+ class DoubleLinkedList<T> {
2
+
3
+ void push(T value) {
4
+ throw new UnsupportedOperationException('Method implementation is missing')
5
+ }
6
+
7
+ T pop() {
8
+ throw new UnsupportedOperationException('Method implementation is missing')
9
+ }
10
+
11
+ T shift() {
12
+ throw new UnsupportedOperationException('Method implementation is missing')
13
+ }
14
+
15
+ void unshift(T value) {
16
+ throw new UnsupportedOperationException('Method implementation is missing')
17
+ }
18
+
19
+ }
@@ -0,0 +1,79 @@
1
+ @Grab('org.spockframework:spock-core:1.0-groovy-2.4')
2
+ import spock.lang.*
3
+
4
+ class DoubleLinkedListSpec extends Specification {
5
+
6
+ def 'can push and pop'() {
7
+ DoubleLinkedList<Integer> list = new DoubleLinkedList<>()
8
+ when:
9
+ list.push(10)
10
+ list.push(20)
11
+ then:
12
+ list.pop() == 20
13
+ and:
14
+ list.pop() == 10
15
+ }
16
+
17
+ @Ignore
18
+ def 'can push and shift'() {
19
+ DoubleLinkedList<String> list = new DoubleLinkedList<>()
20
+ when:
21
+ list.push("10")
22
+ list.push("20")
23
+ then:
24
+ list.shift() == "10"
25
+ and:
26
+ list.shift() == "20"
27
+ }
28
+
29
+ @Ignore
30
+ def 'can unshift an shift'() {
31
+ DoubleLinkedList<Character> list = new DoubleLinkedList<>()
32
+ when:
33
+ list.unshift('1')
34
+ list.unshift('2')
35
+ then:
36
+ list.shift() == '2'
37
+ and:
38
+ list.shift() == '1'
39
+ }
40
+
41
+ @Ignore
42
+ def 'can unshift and pop'() {
43
+ DoubleLinkedList<Integer> list = new DoubleLinkedList<>()
44
+ when:
45
+ list.unshift(10)
46
+ list.unshift(20)
47
+ then:
48
+ list.pop() == 10
49
+ and:
50
+ list.pop() == 20
51
+ }
52
+
53
+ @Ignore
54
+ def 'complete example'() {
55
+ DoubleLinkedList<String> list = new DoubleLinkedList<>()
56
+ when:
57
+ list.push("ten")
58
+ list.push("twenty")
59
+
60
+ then:
61
+ list.pop() == "twenty"
62
+
63
+ when:
64
+ list.push("thirty")
65
+
66
+ then:
67
+ list.shift() == "ten"
68
+
69
+ when:
70
+ list.unshift("forty")
71
+ list.push("fifty")
72
+
73
+ then:
74
+ list.shift() == "forty"
75
+ list.pop() == "fifty"
76
+ list.shift() == "thirty"
77
+
78
+ }
79
+ }
@@ -0,0 +1,57 @@
1
+ class DoubleLinkedList<T> {
2
+
3
+ Element<T> head
4
+
5
+ void push(T value) {
6
+ if(!head) {
7
+ head = new Element<>(value, null, null)
8
+ head.next = head
9
+ head.prev = head
10
+ return
11
+ }
12
+
13
+ def oldTail = head.prev
14
+ def tail = new Element<>(value, oldTail, head)
15
+ oldTail.next = tail
16
+ head.prev = tail
17
+ }
18
+
19
+ T pop() {
20
+ head = head.prev
21
+ shift()
22
+ }
23
+
24
+ T shift() {
25
+ T value = head.value
26
+
27
+ def newHead = head.next
28
+ def newTail = head.prev
29
+
30
+ if(newHead.is(head)) {
31
+ head = null
32
+ } else {
33
+ newHead.prev = newTail
34
+ newTail.next = newHead
35
+ head = newHead
36
+ }
37
+
38
+ value
39
+ }
40
+
41
+ void unshift(T value) {
42
+ push(value)
43
+ head = head.prev
44
+ }
45
+
46
+ private static final class Element<T> {
47
+ final T value
48
+ Element<T> prev
49
+ Element<T> next
50
+
51
+ Element(T value, Element<T> prev, Element<T> next) {
52
+ this.value = value
53
+ this.prev = prev
54
+ this.next = next
55
+ }
56
+ }
57
+ }