trackler 2.1.0.18 → 2.1.0.19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (230) hide show
  1. checksums.yaml +4 -4
  2. data/common/bin/transfer_blurb_to_description.rb +56 -0
  3. data/common/exercises/accumulate/description.md +2 -0
  4. data/common/exercises/acronym/canonical-data.json +1 -7
  5. data/common/exercises/acronym/description.md +2 -0
  6. data/common/exercises/all-your-base/description.md +2 -0
  7. data/common/exercises/allergies/description.md +2 -0
  8. data/common/exercises/alphametics/description.md +2 -0
  9. data/common/exercises/anagram/description.md +2 -0
  10. data/common/exercises/atbash-cipher/description.md +2 -0
  11. data/common/exercises/bank-account/description.md +2 -0
  12. data/common/exercises/beer-song/description.md +2 -0
  13. data/common/exercises/binary/description.md +2 -0
  14. data/common/exercises/binary-search/description.md +2 -0
  15. data/common/exercises/binary-search-tree/description.md +2 -0
  16. data/common/exercises/bob/description.md +2 -0
  17. data/common/exercises/book-store/description.md +2 -0
  18. data/common/exercises/bowling/description.md +2 -0
  19. data/common/exercises/bracket-push/description.md +2 -0
  20. data/common/exercises/change/description.md +2 -0
  21. data/common/exercises/circular-buffer/description.md +2 -0
  22. data/common/exercises/clock/description.md +2 -0
  23. data/common/exercises/connect/description.md +2 -0
  24. data/common/exercises/counter/description.md +2 -0
  25. data/common/exercises/crypto-square/description.md +2 -0
  26. data/common/exercises/custom-set/description.md +2 -0
  27. data/common/exercises/diamond/description.md +2 -0
  28. data/common/exercises/difference-of-squares/description.md +2 -0
  29. data/common/exercises/diffie-hellman/description.md +2 -0
  30. data/common/exercises/dominoes/description.md +2 -0
  31. data/common/exercises/dot-dsl/description.md +2 -0
  32. data/common/exercises/error-handling/description.md +2 -0
  33. data/common/exercises/etl/description.md +2 -0
  34. data/common/exercises/flatten-array/description.md +2 -0
  35. data/common/exercises/food-chain/description.md +2 -0
  36. data/common/exercises/forth/description.md +2 -0
  37. data/common/exercises/gigasecond/description.md +2 -0
  38. data/common/exercises/go-counting/description.md +2 -0
  39. data/common/exercises/grade-school/description.md +2 -0
  40. data/common/exercises/grains/description.md +2 -0
  41. data/common/exercises/grep/description.md +2 -0
  42. data/common/exercises/hamming/description.md +2 -0
  43. data/common/exercises/hangman/description.md +2 -0
  44. data/common/exercises/hello-world/description.md +2 -0
  45. data/common/exercises/hexadecimal/description.md +2 -0
  46. data/common/exercises/house/description.md +2 -0
  47. data/common/exercises/isogram/description.md +2 -0
  48. data/common/exercises/kindergarten-garden/description.md +2 -0
  49. data/common/exercises/largest-series-product/description.md +2 -0
  50. data/common/exercises/leap/description.md +2 -0
  51. data/common/exercises/ledger/description.md +2 -0
  52. data/common/exercises/lens-person/description.md +2 -0
  53. data/common/exercises/linked-list/description.md +2 -0
  54. data/common/exercises/list-ops/description.md +2 -0
  55. data/common/exercises/luhn/description.md +2 -0
  56. data/common/exercises/markdown/description.md +2 -0
  57. data/common/exercises/matrix/description.md +2 -0
  58. data/common/exercises/meetup/description.md +2 -0
  59. data/common/exercises/minesweeper/description.md +2 -0
  60. data/common/exercises/nth-prime/description.md +2 -0
  61. data/common/exercises/nucleotide-codons/description.md +2 -0
  62. data/common/exercises/nucleotide-count/description.md +2 -0
  63. data/common/exercises/ocr-numbers/description.md +2 -0
  64. data/common/exercises/octal/description.md +2 -0
  65. data/common/exercises/paasio/description.md +2 -0
  66. data/common/exercises/palindrome-products/description.md +2 -0
  67. data/common/exercises/parallel-letter-frequency/description.md +2 -0
  68. data/common/exercises/pascals-triangle/description.md +2 -0
  69. data/common/exercises/perfect-numbers/description.md +2 -0
  70. data/common/exercises/phone-number/description.md +2 -0
  71. data/common/exercises/pig-latin/description.md +2 -0
  72. data/common/exercises/point-mutations/description.md +2 -0
  73. data/common/exercises/poker/canonical-data.json +317 -0
  74. data/common/exercises/poker/description.md +2 -0
  75. data/common/exercises/pov/description.md +2 -0
  76. data/common/exercises/prime-factors/description.md +2 -0
  77. data/common/exercises/protein-translation/description.md +2 -0
  78. data/common/exercises/proverb/description.md +2 -0
  79. data/common/exercises/pythagorean-triplet/description.md +2 -0
  80. data/common/exercises/queen-attack/description.md +2 -0
  81. data/common/exercises/rail-fence-cipher/description.md +2 -0
  82. data/common/exercises/raindrops/description.md +2 -0
  83. data/common/exercises/react/description.md +2 -0
  84. data/common/exercises/rectangles/description.md +2 -0
  85. data/common/exercises/rna-transcription/description.md +2 -0
  86. data/common/exercises/robot-name/description.md +2 -0
  87. data/common/exercises/robot-simulator/description.md +2 -0
  88. data/common/exercises/roman-numerals/description.md +2 -0
  89. data/common/exercises/rotational-cipher/description.md +2 -0
  90. data/common/exercises/run-length-encoding/description.md +2 -0
  91. data/common/exercises/saddle-points/description.md +2 -0
  92. data/common/exercises/say/description.md +2 -0
  93. data/common/exercises/scale-generator/description.md +2 -0
  94. data/common/exercises/scrabble-score/description.md +2 -0
  95. data/common/exercises/secret-handshake/description.md +2 -0
  96. data/common/exercises/series/description.md +2 -0
  97. data/common/exercises/sgf-parsing/description.md +2 -0
  98. data/common/exercises/sieve/description.md +2 -0
  99. data/common/exercises/simple-cipher/description.md +2 -0
  100. data/common/exercises/simple-linked-list/description.md +2 -0
  101. data/common/exercises/space-age/description.md +2 -0
  102. data/common/exercises/strain/description.md +2 -0
  103. data/common/exercises/sublist/description.md +2 -0
  104. data/common/exercises/sum-of-multiples/description.md +2 -0
  105. data/common/exercises/transpose/description.md +2 -0
  106. data/common/exercises/tree-building/description.md +2 -0
  107. data/common/exercises/triangle/description.md +2 -0
  108. data/common/exercises/trinary/description.md +2 -0
  109. data/common/exercises/twelve-days/description.md +2 -0
  110. data/common/exercises/two-bucket/description.md +2 -0
  111. data/common/exercises/variable-length-quantity/description.md +2 -0
  112. data/common/exercises/word-count/description.md +2 -0
  113. data/common/exercises/word-search/description.md +2 -0
  114. data/common/exercises/wordy/description.md +2 -0
  115. data/common/exercises/zebra-puzzle/description.md +2 -0
  116. data/common/exercises/zipper/description.md +2 -0
  117. data/fixtures/tracks/fake/{hello-world → exercises/hello-world}/example.ext +0 -0
  118. data/fixtures/tracks/fake/{hello-world → exercises/hello-world}/hello_test.ext +0 -0
  119. data/fixtures/tracks/fake/{hello-world → exercises/hello-world}/world_test.ext +0 -0
  120. data/fixtures/tracks/fake/{one → exercises/one}/.dot +0 -0
  121. data/fixtures/tracks/fake/{one → exercises/one}/Fakefile +0 -0
  122. data/fixtures/tracks/fake/{one → exercises/one}/HINTS.md +0 -0
  123. data/fixtures/tracks/fake/{one → exercises/one}/example.ext +0 -0
  124. data/fixtures/tracks/fake/{one → exercises/one}/one_test.ext +0 -0
  125. data/fixtures/tracks/fake/{one → exercises/one}/sub/src/ExampleFile.ext +0 -0
  126. data/fixtures/tracks/fake/{one → exercises/one}/sub/src/stubfile.ext +0 -0
  127. data/fixtures/tracks/fake/{three → exercises/three}/example.ext +0 -0
  128. data/fixtures/tracks/fake/{three → exercises/three}/three_test.ext +0 -0
  129. data/fixtures/tracks/fake/{two → exercises/two}/example.ext +0 -0
  130. data/fixtures/tracks/fake/{two → exercises/two}/two_test.ext +0 -0
  131. data/lib/trackler/implementation.rb +29 -35
  132. data/lib/trackler/implementations.rb +7 -1
  133. data/lib/trackler/track.rb +4 -3
  134. data/lib/trackler/version.rb +1 -1
  135. data/lib/trackler.rb +1 -1
  136. data/tracks/ecmascript/.github/stale.yml +6 -0
  137. data/tracks/ecmascript/README.md +17 -9
  138. data/tracks/go/README.md +7 -4
  139. data/tracks/go/config.json +5 -2
  140. data/tracks/go/exercises/atbash-cipher/.meta/gen.go +0 -2
  141. data/tracks/go/exercises/bob/.meta/gen.go +0 -2
  142. data/tracks/go/exercises/bowling/.meta/gen.go +0 -2
  143. data/tracks/go/exercises/bracket-push/.meta/gen.go +0 -2
  144. data/tracks/go/exercises/change/.meta/gen.go +0 -2
  145. data/tracks/go/exercises/clock/.meta/gen.go +0 -2
  146. data/tracks/go/exercises/clock/example_clock_test.go +34 -20
  147. data/tracks/go/exercises/connect/.meta/gen.go +0 -2
  148. data/tracks/go/exercises/custom-set/.meta/gen.go +0 -2
  149. data/tracks/go/exercises/forth/.meta/gen.go +0 -2
  150. data/tracks/go/exercises/gigasecond/.meta/gen.go +0 -2
  151. data/tracks/go/exercises/hamming/.meta/gen.go +0 -2
  152. data/tracks/go/exercises/largest-series-product/.meta/gen.go +0 -2
  153. data/tracks/go/exercises/leap/.meta/gen.go +0 -2
  154. data/tracks/go/exercises/luhn/.meta/gen.go +0 -2
  155. data/tracks/go/exercises/meetup/.meta/gen.go +0 -2
  156. data/tracks/go/exercises/phone-number/.meta/gen.go +0 -2
  157. data/tracks/go/exercises/raindrops/.meta/gen.go +0 -2
  158. data/tracks/go/exercises/rna-transcription/.meta/gen.go +0 -2
  159. data/tracks/go/exercises/roman-numerals/.meta/gen.go +0 -2
  160. data/tracks/go/exercises/scrabble-score/.meta/gen.go +0 -2
  161. data/tracks/go/exercises/transpose/.meta/gen.go +0 -2
  162. data/tracks/go/exercises/variable-length-quantity/.meta/gen.go +113 -0
  163. data/tracks/go/exercises/variable-length-quantity/cases_test.go +161 -0
  164. data/tracks/go/exercises/variable-length-quantity/example.go +54 -11
  165. data/tracks/go/exercises/variable-length-quantity/variable_length_quantity_test.go +19 -31
  166. data/tracks/go/exercises/word-count/.meta/gen.go +0 -2
  167. data/tracks/java/exercises/acronym/src/test/java/AcronymTest.java +3 -16
  168. data/tracks/java/exercises/diamond/src/test/java/DiamondPrinterTest.java +1 -1
  169. data/tracks/java/exercises/hello-world/HINT.md +7 -0
  170. data/tracks/java/exercises/largest-series-product/src/test/java/LargestSeriesProductCalculatorTest.java +1 -1
  171. data/tracks/java/exercises/linked-list/src/test/java/DoublyLinkedListTest.java +48 -38
  172. data/tracks/java/exercises/luhn/src/main/java/LuhnValidator.java +7 -0
  173. data/tracks/java/exercises/minesweeper/src/test/java/MinesweeperBoardTest.java +1 -1
  174. data/tracks/java/exercises/perfect-numbers/src/test/java/NaturalNumberTest.java +1 -1
  175. data/tracks/java/exercises/queen-attack/src/test/java/QueenAttackCalculatorTest.java +1 -1
  176. data/tracks/java/exercises/rectangles/src/test/java/RectangleCounterTest.java +1 -1
  177. data/tracks/java/exercises/secret-handshake/src/main/java/HandshakeCalculator.java +5 -1
  178. data/tracks/java/exercises/sum-of-multiples/src/main/java/SumOfMultiples.java +10 -2
  179. data/tracks/java/exercises/triangle/src/example/java/Triangle.java +5 -5
  180. data/tracks/java/exercises/triangle/src/example/java/TriangleException.java +1 -3
  181. data/tracks/java/exercises/triangle/src/main/java/Triangle.java +11 -0
  182. data/tracks/java/exercises/triangle/src/main/java/TriangleException.java +1 -3
  183. data/tracks/javascript/.github/stale.yml +6 -0
  184. data/tracks/javascript/config.json +14 -0
  185. data/tracks/kotlin/docs/INSTALLATION.md +1 -1
  186. data/tracks/lisp/docs/INSTALLATION.md +1 -0
  187. data/tracks/perl6/README.md +9 -4
  188. data/tracks/perl6/config.json +5 -0
  189. data/tracks/perl6/exercises/luhn/Example.pm6 +15 -0
  190. data/tracks/perl6/exercises/luhn/Luhn.pm6 +4 -0
  191. data/tracks/perl6/exercises/luhn/example.yaml +6 -0
  192. data/tracks/perl6/exercises/luhn/luhn.t +122 -0
  193. data/tracks/python/exercises/acronym/acronym_test.py +1 -4
  194. data/tracks/r/exercises/hamming/test_hamming.R +15 -14
  195. data/tracks/ruby/lib/generator/command_line/generator_optparser.rb +3 -1
  196. data/tracks/ruby/lib/generator/exercise_case/assertion.rb +33 -5
  197. data/tracks/ruby/lib/generator/exercise_case/case_helpers.rb +39 -0
  198. data/tracks/ruby/lib/generator/exercise_case.rb +3 -37
  199. data/tracks/ruby/lib/generator/template_values.rb +2 -0
  200. data/tracks/ruby/test/generator/command_line/generator_optparser_test.rb +11 -2
  201. data/tracks/ruby/test/generator/exercise_case/case_helpers_test.rb +43 -0
  202. data/tracks/ruby/test/generator/underscore_test.rb +4 -0
  203. data/tracks/scala/config.json +10 -0
  204. data/tracks/scala/exercises/beer-song/build.sbt +3 -0
  205. data/tracks/scala/exercises/beer-song/example.scala +11 -0
  206. data/tracks/{java/exercises/luhn/src/main/java → scala/exercises/beer-song/src/main/scala}/.keep +0 -0
  207. data/tracks/scala/exercises/beer-song/src/test/scala/BeerSongTest.scala +52 -0
  208. data/tracks/vimscript/.travis.yml +13 -2
  209. data/tracks/vimscript/TRACK_HINTS.md +67 -0
  210. data/tracks/vimscript/bin/ci +21 -0
  211. data/tracks/vimscript/config.json +22 -8
  212. data/tracks/vimscript/docs/ABOUT.md +44 -0
  213. data/tracks/vimscript/docs/INSTALLATION.md +55 -0
  214. data/tracks/vimscript/docs/LEARNING.md +16 -0
  215. data/tracks/vimscript/docs/RESOURCES.md +24 -0
  216. data/tracks/vimscript/docs/TESTS.md +67 -0
  217. data/tracks/vimscript/exercises/bob/bob.vader +63 -0
  218. data/tracks/vimscript/exercises/bob/bob.vim +8 -0
  219. data/tracks/vimscript/exercises/bob/example.vim +23 -0
  220. data/tracks/vimscript/exercises/hamming/example.vim +18 -0
  221. data/tracks/vimscript/exercises/hamming/hamming.vader +20 -0
  222. data/tracks/vimscript/exercises/hamming/hamming.vim +13 -0
  223. data/tracks/vimscript/exercises/hello-world/example.vim +4 -0
  224. data/tracks/vimscript/exercises/hello-world/hello_world.vader +8 -0
  225. data/tracks/vimscript/exercises/hello-world/hello_world.vim +20 -0
  226. data/tracks/vimscript/exercises/leap/example.vim +3 -0
  227. data/tracks/vimscript/exercises/leap/leap.vader +11 -0
  228. data/tracks/vimscript/exercises/leap/leap.vim +9 -0
  229. metadata +47 -18
  230. data/tracks/vimscript/SETUP.md +0 -0
@@ -0,0 +1,161 @@
1
+ package variablelengthquantity
2
+
3
+ // Source: exercism/x-common
4
+ // Commit: d6a62f7 variable-length-quantity: Fix canonical-data.json formatting
5
+ // x-common version: 1.0.0
6
+
7
+ // Encode a series of integers, producing a series of bytes.
8
+ var encodeTestCases = []struct {
9
+ description string
10
+ input []uint32
11
+ output []byte
12
+ }{
13
+ {
14
+ "zero",
15
+ []uint32{0x0},
16
+ []byte{0x0},
17
+ },
18
+ {
19
+ "arbitrary single byte",
20
+ []uint32{0x40},
21
+ []byte{0x40},
22
+ },
23
+ {
24
+ "largest single byte",
25
+ []uint32{0x7f},
26
+ []byte{0x7f},
27
+ },
28
+ {
29
+ "smallest double byte",
30
+ []uint32{0x80},
31
+ []byte{0x81, 0x0},
32
+ },
33
+ {
34
+ "arbitrary double byte",
35
+ []uint32{0x2000},
36
+ []byte{0xc0, 0x0},
37
+ },
38
+ {
39
+ "largest double byte",
40
+ []uint32{0x3fff},
41
+ []byte{0xff, 0x7f},
42
+ },
43
+ {
44
+ "smallest triple byte",
45
+ []uint32{0x4000},
46
+ []byte{0x81, 0x80, 0x0},
47
+ },
48
+ {
49
+ "arbitrary triple byte",
50
+ []uint32{0x100000},
51
+ []byte{0xc0, 0x80, 0x0},
52
+ },
53
+ {
54
+ "largest triple byte",
55
+ []uint32{0x1fffff},
56
+ []byte{0xff, 0xff, 0x7f},
57
+ },
58
+ {
59
+ "smallest quadruple byte",
60
+ []uint32{0x200000},
61
+ []byte{0x81, 0x80, 0x80, 0x0},
62
+ },
63
+ {
64
+ "arbitrary quadruple byte",
65
+ []uint32{0x8000000},
66
+ []byte{0xc0, 0x80, 0x80, 0x0},
67
+ },
68
+ {
69
+ "largest quadruple byte",
70
+ []uint32{0xfffffff},
71
+ []byte{0xff, 0xff, 0xff, 0x7f},
72
+ },
73
+ {
74
+ "smallest quintuple byte",
75
+ []uint32{0x10000000},
76
+ []byte{0x81, 0x80, 0x80, 0x80, 0x0},
77
+ },
78
+ {
79
+ "arbitrary quintuple byte",
80
+ []uint32{0xff000000},
81
+ []byte{0x8f, 0xf8, 0x80, 0x80, 0x0},
82
+ },
83
+ {
84
+ "maximum 32-bit integer input",
85
+ []uint32{0xffffffff},
86
+ []byte{0x8f, 0xff, 0xff, 0xff, 0x7f},
87
+ },
88
+ {
89
+ "two single-byte values",
90
+ []uint32{0x40, 0x7f},
91
+ []byte{0x40, 0x7f},
92
+ },
93
+ {
94
+ "two multi-byte values",
95
+ []uint32{0x4000, 0x123456},
96
+ []byte{0x81, 0x80, 0x0, 0xc8, 0xe8, 0x56},
97
+ },
98
+ {
99
+ "many multi-byte values",
100
+ []uint32{0x2000, 0x123456, 0xfffffff, 0x0, 0x3fff, 0x4000},
101
+ []byte{0xc0, 0x0, 0xc8, 0xe8, 0x56, 0xff, 0xff, 0xff, 0x7f, 0x0, 0xff, 0x7f, 0x81, 0x80, 0x0},
102
+ },
103
+ }
104
+
105
+ // Decode a series of bytes, producing a series of integers.
106
+ var decodeTestCases = []struct {
107
+ description string
108
+ input []byte
109
+ output []uint32 // nil slice indicates error expected.
110
+ size int
111
+ }{
112
+
113
+ {
114
+ "one byte",
115
+ []byte{0x7f},
116
+ []uint32{0x7f},
117
+ 1,
118
+ },
119
+ {
120
+ "two bytes",
121
+ []byte{0xc0, 0x0},
122
+ []uint32{0x2000},
123
+ 2,
124
+ },
125
+ {
126
+ "three bytes",
127
+ []byte{0xff, 0xff, 0x7f},
128
+ []uint32{0x1fffff},
129
+ 3,
130
+ },
131
+ {
132
+ "four bytes",
133
+ []byte{0x81, 0x80, 0x80, 0x0},
134
+ []uint32{0x200000},
135
+ 4,
136
+ },
137
+ {
138
+ "maximum 32-bit integer",
139
+ []byte{0x8f, 0xff, 0xff, 0xff, 0x7f},
140
+ []uint32{0xffffffff},
141
+ 5,
142
+ },
143
+ {
144
+ "incomplete sequence causes error",
145
+ []byte{0xff},
146
+ []uint32(nil),
147
+ 1,
148
+ },
149
+ {
150
+ "incomplete sequence causes error, even if value is zero",
151
+ []byte{0x80},
152
+ []uint32(nil),
153
+ 1,
154
+ },
155
+ {
156
+ "multiple values",
157
+ []byte{0xc0, 0x0, 0xc8, 0xe8, 0x56, 0xff, 0xff, 0xff, 0x7f, 0x0, 0xff, 0x7f, 0x81, 0x80, 0x0},
158
+ []uint32{0x2000, 0x123456, 0xfffffff, 0x0, 0x3fff, 0x4000},
159
+ 15,
160
+ },
161
+ }
@@ -1,9 +1,13 @@
1
1
  package variablelengthquantity
2
2
 
3
- const testVersion = 2
3
+ import "errors"
4
4
 
5
- // EncodeVarint returns the varint encoding of x.
6
- func EncodeVarint(x uint32) []byte {
5
+ const testVersion = 3
6
+
7
+ var ErrUnterminatedSequence = errors.New("unterminated sequence")
8
+
9
+ // encodeInt returns the varint encoding of x.
10
+ func encodeInt(x uint32) []byte {
7
11
  if x>>7 == 0 {
8
12
  return []byte{
9
13
  byte(x),
@@ -25,7 +29,17 @@ func EncodeVarint(x uint32) []byte {
25
29
  }
26
30
  }
27
31
 
32
+ if x>>28 == 0 {
33
+ return []byte{
34
+ byte(0x80 | x>>21),
35
+ byte(0x80 | x>>14),
36
+ byte(0x80 | x>>6),
37
+ byte(127 & x),
38
+ }
39
+ }
40
+
28
41
  return []byte{
42
+ byte(0x80 | x>>28),
29
43
  byte(0x80 | x>>21),
30
44
  byte(0x80 | x>>14),
31
45
  byte(0x80 | x>>7),
@@ -33,26 +47,55 @@ func EncodeVarint(x uint32) []byte {
33
47
  }
34
48
  }
35
49
 
36
- // DecodeVarint reads a varint-encoded integer from the slice.
50
+ // decodeInt reads a varint-encoded integer from the slice.
37
51
  // It returns the integer and the number of bytes consumed, or
38
52
  // zero if there is not enough.
39
- func DecodeVarint(buf []byte) (x uint32, n int) {
53
+ func decodeInt(buf []byte) (x uint32, n int, err error) {
40
54
  if len(buf) < 1 {
41
- return 0, 0
55
+ return 0, 0, nil
42
56
  }
43
57
 
44
- if buf[0] <= 0x80 {
45
- return uint32(buf[0]), 1
58
+ if buf[0] < 0x80 {
59
+ return uint32(buf[0]), 1, nil
46
60
  }
47
61
 
48
62
  var b byte
49
63
  for n, b = range buf {
50
64
  x = x << 7
51
- x |= uint32(b) & 0x7F
65
+ x |= uint32(b) & 0x7f
52
66
  if (b & 0x80) == 0 {
53
- return x, n + 1
67
+ return x, n + 1, nil
54
68
  }
55
69
  }
56
70
 
57
- return x, 0
71
+ return x, 0, ErrUnterminatedSequence
72
+ }
73
+
74
+ // EncodeVarint encodes a slice of uint32 into a var-int encoded bytes.
75
+ func EncodeVarint(xa []uint32) []byte {
76
+ result := make([]byte, 0)
77
+ for _, x := range xa {
78
+ result = append(result, encodeInt(x)...)
79
+ }
80
+ return result
81
+ }
82
+
83
+ // DecodeVarint decodes a buffer of var-int encoded values into
84
+ // a slice of uint32 values; an error is returned if buf doesn't
85
+ // decode var-int successfully.
86
+ func DecodeVarint(buf []byte) (ra []uint32, n int, err error) {
87
+ if len(buf) == 0 {
88
+ return []uint32{0}, 1, nil
89
+ }
90
+ usedBytes := 0
91
+ ra = make([]uint32, 0)
92
+ for usedBytes < len(buf) {
93
+ r, nUsed, err := decodeInt(buf[usedBytes:])
94
+ if err != nil {
95
+ return nil, usedBytes, err
96
+ }
97
+ ra = append(ra, r)
98
+ usedBytes += nUsed
99
+ }
100
+ return ra, usedBytes, nil
58
101
  }
@@ -2,28 +2,11 @@ package variablelengthquantity
2
2
 
3
3
  import (
4
4
  "bytes"
5
+ "reflect"
5
6
  "testing"
6
7
  )
7
8
 
8
- const targetTestVersion = 2
9
-
10
- var testCases = []struct {
11
- input []byte
12
- output uint32
13
- size int
14
- }{
15
- 0: {[]byte{0x7F}, 127, 1},
16
- 1: {[]byte{0x81, 0x00}, 128, 2},
17
- 2: {[]byte{0xC0, 0x00}, 8192, 2},
18
- 3: {[]byte{0xFF, 0x7F}, 16383, 2},
19
- 4: {[]byte{0x81, 0x80, 0x00}, 16384, 3},
20
- 5: {[]byte{0xFF, 0xFF, 0x7F}, 2097151, 3},
21
- 6: {[]byte{0x81, 0x80, 0x80, 0x00}, 2097152, 4},
22
- 7: {[]byte{0xC0, 0x80, 0x80, 0x00}, 134217728, 4},
23
- 8: {[]byte{0xFF, 0xFF, 0xFF, 0x7F}, 268435455, 4},
24
- 9: {[]byte{0x82, 0x00}, 256, 2},
25
- 10: {[]byte{0x81, 0x10}, 144, 2},
26
- }
9
+ const targetTestVersion = 3
27
10
 
28
11
  func TestTestVersion(t *testing.T) {
29
12
  if testVersion != targetTestVersion {
@@ -32,24 +15,29 @@ func TestTestVersion(t *testing.T) {
32
15
  }
33
16
 
34
17
  func TestDecodeVarint(t *testing.T) {
35
- for i, tc := range testCases {
36
- o, size := DecodeVarint(tc.input)
37
- if o != tc.output {
38
- t.Fatalf("FAIL: case %d - expected %d got %d\n", i, tc.output, o)
18
+ for i, tc := range decodeTestCases {
19
+ o, size, err := DecodeVarint(tc.input)
20
+ if err != nil {
21
+ var _ error = err
22
+ if tc.output != nil {
23
+ t.Fatalf("FAIL: case %d | %s\nexpected %#v got error: %q\n", i, tc.description, tc.output, err)
24
+ }
25
+ } else if tc.output == nil {
26
+ t.Fatalf("FAIL: case %d | %s\nexpected error, got %#v\n", i, tc.description, o)
27
+ } else if !reflect.DeepEqual(o, tc.output) {
28
+ t.Fatalf("FAIL: case %d | %s\nexpected\t%#v\ngot\t\t%#v\n", i, tc.description, tc.output, o)
39
29
  } else if size != tc.size {
40
- t.Fatalf("FAIL: case %d - expected encoding size of %d bytes\ngot %d bytes\n", i, tc.size, size)
41
- } else {
42
- t.Logf("PASS: case %d - %#v\n", i, tc.input)
30
+ t.Fatalf("FAIL: case %d | %s\n expected encoding size of %d bytes\ngot %d bytes\n", i, tc.description, tc.size, size)
43
31
  }
32
+ t.Logf("PASS: case %d | %s\n", i, tc.description)
44
33
  }
45
34
  }
46
35
 
47
36
  func TestEncodeVarint(t *testing.T) {
48
- for i, tc := range testCases {
49
- if encoded := EncodeVarint(tc.output); bytes.Compare(encoded, tc.input) != 0 {
50
- t.Fatalf("FAIL: case %d - %d \nexpected\t%#v\ngot\t\t%#v\n", i, tc.output, tc.input, encoded)
51
- } else {
52
- t.Logf("PASS: case %d - %#v\n", i, tc.input)
37
+ for i, tc := range encodeTestCases {
38
+ if encoded := EncodeVarint(tc.input); bytes.Compare(encoded, tc.output) != 0 {
39
+ t.Fatalf("FAIL: case %d | %s\nexpected\t%#v\ngot\t\t%#v\n", i, tc.description, tc.output, encoded)
53
40
  }
41
+ t.Logf("PASS: case %d | %s\n", i, tc.description)
54
42
  }
55
43
  }
@@ -1,5 +1,3 @@
1
- // +build ignore
2
-
3
1
  package main
4
2
 
5
3
  import (
@@ -3,6 +3,9 @@ import org.junit.Ignore;
3
3
 
4
4
  import static org.junit.Assert.assertEquals;
5
5
 
6
+ /*
7
+ * version: 1.1.0
8
+ */
6
9
  public class AcronymTest {
7
10
 
8
11
  @Test
@@ -20,14 +23,6 @@ public class AcronymTest {
20
23
  assertEquals(expected, new Acronym(phrase).get());
21
24
  }
22
25
 
23
- @Ignore("Remove to run test")
24
- @Test
25
- public void fromInconsistentlyCasedPhrases() {
26
- final String phrase = "HyperText Markup Language";
27
- final String expected = "HTML";
28
- assertEquals(expected, new Acronym(phrase).get());
29
- }
30
-
31
26
  @Ignore("Remove to run test")
32
27
  @Test
33
28
  public void fromPhrasesWithPunctuation() {
@@ -60,12 +55,4 @@ public class AcronymTest {
60
55
  assertEquals(expected, new Acronym(phrase).get());
61
56
  }
62
57
 
63
- @Ignore("Remove to run test")
64
- @Test
65
- public void fromPhraseWithSingleLetterWord() {
66
- final String phrase = "Cat in a Hat";
67
- final String expected = "CIAH";
68
- assertEquals(expected, new Acronym(phrase).get());
69
- }
70
-
71
58
  }
@@ -9,7 +9,7 @@ import static java.util.Collections.singletonList;
9
9
  import static org.hamcrest.CoreMatchers.is;
10
10
  import static org.junit.Assert.assertThat;
11
11
 
12
- public final class DiamondPrinterTest {
12
+ public class DiamondPrinterTest {
13
13
  private DiamondPrinter diamondPrinter;
14
14
 
15
15
  @Before
@@ -0,0 +1,7 @@
1
+ The default implementation for this exercise uses an [exception](https://docs.oracle.com/javase/tutorial/essential/exceptions/)
2
+ which will cause the test to fail with the provided error message.
3
+ This particular exception type, [UnsupportedOperationException](http://docs.oracle.com/javase/8/docs/api/?java/lang/UnsupportedOperationException.html),
4
+ is commonly thrown to alert developers that a method has not yet been implemented.
5
+ Throwing exceptions in this manner means the tests will compile but not pass right away.
6
+
7
+ To make the test pass you need to remove the line which throws the exception and replace it with your implementation of the method.
@@ -5,7 +5,7 @@ import org.junit.rules.ExpectedException;
5
5
 
6
6
  import static org.junit.Assert.assertEquals;
7
7
 
8
- public final class LargestSeriesProductCalculatorTest {
8
+ public class LargestSeriesProductCalculatorTest {
9
9
 
10
10
  /*
11
11
  * See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
@@ -1,68 +1,78 @@
1
- import org.junit.Before;
2
1
  import org.junit.Ignore;
3
2
  import org.junit.Test;
4
3
 
5
- import static org.hamcrest.CoreMatchers.*;
6
- import static org.junit.Assert.*;
4
+ import static org.hamcrest.CoreMatchers.is;
5
+ import static org.junit.Assert.assertThat;
7
6
 
8
7
  public class DoublyLinkedListTest {
9
- private DoublyLinkedList<Integer> subject;
10
-
11
- @Before
12
- public void setUp() {
13
- subject = new DoublyLinkedList<>();
14
- }
15
-
16
8
 
17
9
  @Test
18
10
  public void testPushPop() {
19
- subject.push(10);
20
- subject.push(20);
21
- assertThat(subject.pop(), is(20));
22
- assertThat(subject.pop(), is(10));
11
+ DoublyLinkedList<Integer> list = new DoublyLinkedList<>();
12
+
13
+ list.push(10);
14
+ list.push(20);
15
+
16
+ assertThat(list.pop(), is(20));
17
+ assertThat(list.pop(), is(10));
23
18
  }
24
19
 
25
20
  @Ignore("Remove to run test")
26
21
  @Test
27
22
  public void testPushShift() {
28
- subject.push(10);
29
- subject.push(20);
30
- assertThat(subject.shift(), is(10));
31
- assertThat(subject.shift(), is(20));
23
+ DoublyLinkedList<String> list = new DoublyLinkedList<>();
24
+
25
+ list.push("10");
26
+ list.push("20");
27
+
28
+ assertThat(list.shift(), is("10"));
29
+ assertThat(list.shift(), is("20"));
32
30
  }
33
31
 
34
32
  @Ignore("Remove to run test")
35
33
  @Test
36
34
  public void testUnshiftShift() {
37
- subject.unshift(10);
38
- subject.unshift(20);
39
- assertThat(subject.shift(), is(20));
40
- assertThat(subject.shift(), is(10));
35
+ DoublyLinkedList<Character> list = new DoublyLinkedList<>();
36
+
37
+ list.unshift('1');
38
+ list.unshift('2');
39
+
40
+ assertThat(list.shift(), is('2'));
41
+ assertThat(list.shift(), is('1'));
41
42
  }
42
43
 
43
44
  @Ignore("Remove to run test")
44
45
  @Test
45
46
  public void testUnshiftPop() {
46
- subject.unshift(10);
47
- subject.unshift(20);
48
- assertThat(subject.pop(), is(10));
49
- assertThat(subject.pop(), is(20));
47
+ DoublyLinkedList<Integer> list = new DoublyLinkedList<>();
48
+
49
+ list.unshift(10);
50
+ list.unshift(20);
51
+
52
+ assertThat(list.pop(), is(10));
53
+ assertThat(list.pop(), is(20));
50
54
  }
51
55
 
52
56
  @Ignore("Remove to run test")
53
57
  @Test
54
58
  public void testExample() {
55
- subject.push(10);
56
- subject.push(20);
57
- assertThat(subject.pop(), is(20));
58
-
59
- subject.push(30);
60
- assertThat(subject.shift(), is(10));
61
-
62
- subject.unshift(40);
63
- subject.push(50);
64
- assertThat(subject.shift(), is(40));
65
- assertThat(subject.pop(), is(50));
66
- assertThat(subject.shift(), is(30));
59
+ DoublyLinkedList<String> list = new DoublyLinkedList<>();
60
+
61
+ list.push("ten");
62
+ list.push("twenty");
63
+
64
+ assertThat(list.pop(), is("twenty"));
65
+
66
+ list.push("thirty");
67
+
68
+ assertThat(list.shift(), is("ten"));
69
+
70
+ list.unshift("forty");
71
+ list.push("fifty");
72
+
73
+ assertThat(list.shift(), is("forty"));
74
+ assertThat(list.pop(), is("fifty"));
75
+ assertThat(list.shift(), is("thirty"));
67
76
  }
77
+
68
78
  }
@@ -0,0 +1,7 @@
1
+ final class LuhnValidator {
2
+
3
+ boolean isValid(String candidate) {
4
+ throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
5
+ }
6
+
7
+ }
@@ -9,7 +9,7 @@ import java.util.List;
9
9
 
10
10
  import static org.junit.Assert.assertEquals;
11
11
 
12
- public final class MinesweeperBoardTest {
12
+ public class MinesweeperBoardTest {
13
13
 
14
14
  /*
15
15
  * See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
@@ -9,7 +9,7 @@ import static org.junit.Assert.assertEquals;
9
9
  * version: 1.0.0
10
10
  * https://github.com/exercism/x-common/blob/19d0c7714ce664a1ad762af624c17f8e269fa8b2/exercises/perfect-numbers/canonical-data.json
11
11
  */
12
- public final class NaturalNumberTest {
12
+ public class NaturalNumberTest {
13
13
 
14
14
  /*
15
15
  * See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
@@ -6,7 +6,7 @@ import org.junit.rules.ExpectedException;
6
6
  import static org.junit.Assert.assertFalse;
7
7
  import static org.junit.Assert.assertTrue;
8
8
 
9
- public final class QueenAttackCalculatorTest {
9
+ public class QueenAttackCalculatorTest {
10
10
 
11
11
  /*
12
12
  * See https://github.com/junit-team/junit4/wiki/Rules for information on JUnit Rules in general and
@@ -4,7 +4,7 @@ import org.junit.Test;
4
4
 
5
5
  import static org.junit.Assert.assertEquals;
6
6
 
7
- public final class RectangleCounterTest {
7
+ public class RectangleCounterTest {
8
8
 
9
9
  private RectangleCounter rectangleCounter;
10
10
 
@@ -1,5 +1,9 @@
1
- final class HandshakeCalculator {
1
+ import java.util.List;
2
2
 
3
+ final class HandshakeCalculator {
3
4
 
5
+ List<Signal> calculateHandshake(int number) {
6
+ throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
7
+ }
4
8
 
5
9
  }
@@ -1,3 +1,11 @@
1
- public class SumOfMultiples {
2
-
1
+ class SumOfMultiples {
2
+
3
+ SumOfMultiples(int number, int[] set) {
4
+ throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
5
+ }
6
+
7
+ int getSum() {
8
+ throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
9
+ }
10
+
3
11
  }
@@ -1,13 +1,13 @@
1
1
  import java.util.HashSet;
2
2
  import java.util.Set;
3
3
 
4
- public class Triangle {
4
+ class Triangle {
5
5
 
6
6
  private double side1;
7
7
  private double side2;
8
8
  private double side3;
9
9
 
10
- public Triangle(double side1, double side2, double side3) throws TriangleException {
10
+ Triangle(double side1, double side2, double side3) throws TriangleException {
11
11
  this.side1 = side1;
12
12
  this.side2 = side2;
13
13
  this.side3 = side3;
@@ -17,7 +17,7 @@ public class Triangle {
17
17
  }
18
18
  }
19
19
 
20
- public TriangleKind getKind() {
20
+ TriangleKind getKind() {
21
21
  int uniqueSides = getNumberOfUniqueSides();
22
22
 
23
23
  if (uniqueSides == 1) {
@@ -43,8 +43,7 @@ public class Triangle {
43
43
  return side1 + side2 <= side3 || side1 + side3 <= side2 || side2 + side3 <= side1;
44
44
  }
45
45
 
46
-
47
- public int getNumberOfUniqueSides() {
46
+ private int getNumberOfUniqueSides() {
48
47
  Set<Double> sides = new HashSet<>();
49
48
 
50
49
  sides.add(side1);
@@ -53,4 +52,5 @@ public class Triangle {
53
52
 
54
53
  return sides.size();
55
54
  }
55
+
56
56
  }
@@ -1,5 +1,3 @@
1
- public class TriangleException extends Exception {
1
+ class TriangleException extends Exception {
2
2
 
3
- public TriangleException() {
4
- }
5
3
  }
@@ -0,0 +1,11 @@
1
+ class Triangle {
2
+
3
+ Triangle(double side1, double side2, double side3) throws TriangleException {
4
+ throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
5
+ }
6
+
7
+ TriangleKind getKind() {
8
+ throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
9
+ }
10
+
11
+ }
@@ -1,5 +1,3 @@
1
- public class TriangleException extends Exception {
1
+ class TriangleException extends Exception {
2
2
 
3
- public TriangleException() {
4
- }
5
3
  }
@@ -0,0 +1,6 @@
1
+ # Issues or Pull Requests with these labels will never be considered stale
2
+ exemptLabels:
3
+ - pinned
4
+ - security
5
+ - good first patch
6
+ - first-timers only