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.
- checksums.yaml +4 -4
- data/common/bin/transfer_blurb_to_description.rb +56 -0
- data/common/exercises/accumulate/description.md +2 -0
- data/common/exercises/acronym/canonical-data.json +1 -7
- data/common/exercises/acronym/description.md +2 -0
- data/common/exercises/all-your-base/description.md +2 -0
- data/common/exercises/allergies/description.md +2 -0
- data/common/exercises/alphametics/description.md +2 -0
- data/common/exercises/anagram/description.md +2 -0
- data/common/exercises/atbash-cipher/description.md +2 -0
- data/common/exercises/bank-account/description.md +2 -0
- data/common/exercises/beer-song/description.md +2 -0
- data/common/exercises/binary/description.md +2 -0
- data/common/exercises/binary-search/description.md +2 -0
- data/common/exercises/binary-search-tree/description.md +2 -0
- data/common/exercises/bob/description.md +2 -0
- data/common/exercises/book-store/description.md +2 -0
- data/common/exercises/bowling/description.md +2 -0
- data/common/exercises/bracket-push/description.md +2 -0
- data/common/exercises/change/description.md +2 -0
- data/common/exercises/circular-buffer/description.md +2 -0
- data/common/exercises/clock/description.md +2 -0
- data/common/exercises/connect/description.md +2 -0
- data/common/exercises/counter/description.md +2 -0
- data/common/exercises/crypto-square/description.md +2 -0
- data/common/exercises/custom-set/description.md +2 -0
- data/common/exercises/diamond/description.md +2 -0
- data/common/exercises/difference-of-squares/description.md +2 -0
- data/common/exercises/diffie-hellman/description.md +2 -0
- data/common/exercises/dominoes/description.md +2 -0
- data/common/exercises/dot-dsl/description.md +2 -0
- data/common/exercises/error-handling/description.md +2 -0
- data/common/exercises/etl/description.md +2 -0
- data/common/exercises/flatten-array/description.md +2 -0
- data/common/exercises/food-chain/description.md +2 -0
- data/common/exercises/forth/description.md +2 -0
- data/common/exercises/gigasecond/description.md +2 -0
- data/common/exercises/go-counting/description.md +2 -0
- data/common/exercises/grade-school/description.md +2 -0
- data/common/exercises/grains/description.md +2 -0
- data/common/exercises/grep/description.md +2 -0
- data/common/exercises/hamming/description.md +2 -0
- data/common/exercises/hangman/description.md +2 -0
- data/common/exercises/hello-world/description.md +2 -0
- data/common/exercises/hexadecimal/description.md +2 -0
- data/common/exercises/house/description.md +2 -0
- data/common/exercises/isogram/description.md +2 -0
- data/common/exercises/kindergarten-garden/description.md +2 -0
- data/common/exercises/largest-series-product/description.md +2 -0
- data/common/exercises/leap/description.md +2 -0
- data/common/exercises/ledger/description.md +2 -0
- data/common/exercises/lens-person/description.md +2 -0
- data/common/exercises/linked-list/description.md +2 -0
- data/common/exercises/list-ops/description.md +2 -0
- data/common/exercises/luhn/description.md +2 -0
- data/common/exercises/markdown/description.md +2 -0
- data/common/exercises/matrix/description.md +2 -0
- data/common/exercises/meetup/description.md +2 -0
- data/common/exercises/minesweeper/description.md +2 -0
- data/common/exercises/nth-prime/description.md +2 -0
- data/common/exercises/nucleotide-codons/description.md +2 -0
- data/common/exercises/nucleotide-count/description.md +2 -0
- data/common/exercises/ocr-numbers/description.md +2 -0
- data/common/exercises/octal/description.md +2 -0
- data/common/exercises/paasio/description.md +2 -0
- data/common/exercises/palindrome-products/description.md +2 -0
- data/common/exercises/parallel-letter-frequency/description.md +2 -0
- data/common/exercises/pascals-triangle/description.md +2 -0
- data/common/exercises/perfect-numbers/description.md +2 -0
- data/common/exercises/phone-number/description.md +2 -0
- data/common/exercises/pig-latin/description.md +2 -0
- data/common/exercises/point-mutations/description.md +2 -0
- data/common/exercises/poker/canonical-data.json +317 -0
- data/common/exercises/poker/description.md +2 -0
- data/common/exercises/pov/description.md +2 -0
- data/common/exercises/prime-factors/description.md +2 -0
- data/common/exercises/protein-translation/description.md +2 -0
- data/common/exercises/proverb/description.md +2 -0
- data/common/exercises/pythagorean-triplet/description.md +2 -0
- data/common/exercises/queen-attack/description.md +2 -0
- data/common/exercises/rail-fence-cipher/description.md +2 -0
- data/common/exercises/raindrops/description.md +2 -0
- data/common/exercises/react/description.md +2 -0
- data/common/exercises/rectangles/description.md +2 -0
- data/common/exercises/rna-transcription/description.md +2 -0
- data/common/exercises/robot-name/description.md +2 -0
- data/common/exercises/robot-simulator/description.md +2 -0
- data/common/exercises/roman-numerals/description.md +2 -0
- data/common/exercises/rotational-cipher/description.md +2 -0
- data/common/exercises/run-length-encoding/description.md +2 -0
- data/common/exercises/saddle-points/description.md +2 -0
- data/common/exercises/say/description.md +2 -0
- data/common/exercises/scale-generator/description.md +2 -0
- data/common/exercises/scrabble-score/description.md +2 -0
- data/common/exercises/secret-handshake/description.md +2 -0
- data/common/exercises/series/description.md +2 -0
- data/common/exercises/sgf-parsing/description.md +2 -0
- data/common/exercises/sieve/description.md +2 -0
- data/common/exercises/simple-cipher/description.md +2 -0
- data/common/exercises/simple-linked-list/description.md +2 -0
- data/common/exercises/space-age/description.md +2 -0
- data/common/exercises/strain/description.md +2 -0
- data/common/exercises/sublist/description.md +2 -0
- data/common/exercises/sum-of-multiples/description.md +2 -0
- data/common/exercises/transpose/description.md +2 -0
- data/common/exercises/tree-building/description.md +2 -0
- data/common/exercises/triangle/description.md +2 -0
- data/common/exercises/trinary/description.md +2 -0
- data/common/exercises/twelve-days/description.md +2 -0
- data/common/exercises/two-bucket/description.md +2 -0
- data/common/exercises/variable-length-quantity/description.md +2 -0
- data/common/exercises/word-count/description.md +2 -0
- data/common/exercises/word-search/description.md +2 -0
- data/common/exercises/wordy/description.md +2 -0
- data/common/exercises/zebra-puzzle/description.md +2 -0
- data/common/exercises/zipper/description.md +2 -0
- data/fixtures/tracks/fake/{hello-world → exercises/hello-world}/example.ext +0 -0
- data/fixtures/tracks/fake/{hello-world → exercises/hello-world}/hello_test.ext +0 -0
- data/fixtures/tracks/fake/{hello-world → exercises/hello-world}/world_test.ext +0 -0
- data/fixtures/tracks/fake/{one → exercises/one}/.dot +0 -0
- data/fixtures/tracks/fake/{one → exercises/one}/Fakefile +0 -0
- data/fixtures/tracks/fake/{one → exercises/one}/HINTS.md +0 -0
- data/fixtures/tracks/fake/{one → exercises/one}/example.ext +0 -0
- data/fixtures/tracks/fake/{one → exercises/one}/one_test.ext +0 -0
- data/fixtures/tracks/fake/{one → exercises/one}/sub/src/ExampleFile.ext +0 -0
- data/fixtures/tracks/fake/{one → exercises/one}/sub/src/stubfile.ext +0 -0
- data/fixtures/tracks/fake/{three → exercises/three}/example.ext +0 -0
- data/fixtures/tracks/fake/{three → exercises/three}/three_test.ext +0 -0
- data/fixtures/tracks/fake/{two → exercises/two}/example.ext +0 -0
- data/fixtures/tracks/fake/{two → exercises/two}/two_test.ext +0 -0
- data/lib/trackler/implementation.rb +29 -35
- data/lib/trackler/implementations.rb +7 -1
- data/lib/trackler/track.rb +4 -3
- data/lib/trackler/version.rb +1 -1
- data/lib/trackler.rb +1 -1
- data/tracks/ecmascript/.github/stale.yml +6 -0
- data/tracks/ecmascript/README.md +17 -9
- data/tracks/go/README.md +7 -4
- data/tracks/go/config.json +5 -2
- data/tracks/go/exercises/atbash-cipher/.meta/gen.go +0 -2
- data/tracks/go/exercises/bob/.meta/gen.go +0 -2
- data/tracks/go/exercises/bowling/.meta/gen.go +0 -2
- data/tracks/go/exercises/bracket-push/.meta/gen.go +0 -2
- data/tracks/go/exercises/change/.meta/gen.go +0 -2
- data/tracks/go/exercises/clock/.meta/gen.go +0 -2
- data/tracks/go/exercises/clock/example_clock_test.go +34 -20
- data/tracks/go/exercises/connect/.meta/gen.go +0 -2
- data/tracks/go/exercises/custom-set/.meta/gen.go +0 -2
- data/tracks/go/exercises/forth/.meta/gen.go +0 -2
- data/tracks/go/exercises/gigasecond/.meta/gen.go +0 -2
- data/tracks/go/exercises/hamming/.meta/gen.go +0 -2
- data/tracks/go/exercises/largest-series-product/.meta/gen.go +0 -2
- data/tracks/go/exercises/leap/.meta/gen.go +0 -2
- data/tracks/go/exercises/luhn/.meta/gen.go +0 -2
- data/tracks/go/exercises/meetup/.meta/gen.go +0 -2
- data/tracks/go/exercises/phone-number/.meta/gen.go +0 -2
- data/tracks/go/exercises/raindrops/.meta/gen.go +0 -2
- data/tracks/go/exercises/rna-transcription/.meta/gen.go +0 -2
- data/tracks/go/exercises/roman-numerals/.meta/gen.go +0 -2
- data/tracks/go/exercises/scrabble-score/.meta/gen.go +0 -2
- data/tracks/go/exercises/transpose/.meta/gen.go +0 -2
- data/tracks/go/exercises/variable-length-quantity/.meta/gen.go +113 -0
- data/tracks/go/exercises/variable-length-quantity/cases_test.go +161 -0
- data/tracks/go/exercises/variable-length-quantity/example.go +54 -11
- data/tracks/go/exercises/variable-length-quantity/variable_length_quantity_test.go +19 -31
- data/tracks/go/exercises/word-count/.meta/gen.go +0 -2
- data/tracks/java/exercises/acronym/src/test/java/AcronymTest.java +3 -16
- data/tracks/java/exercises/diamond/src/test/java/DiamondPrinterTest.java +1 -1
- data/tracks/java/exercises/hello-world/HINT.md +7 -0
- data/tracks/java/exercises/largest-series-product/src/test/java/LargestSeriesProductCalculatorTest.java +1 -1
- data/tracks/java/exercises/linked-list/src/test/java/DoublyLinkedListTest.java +48 -38
- data/tracks/java/exercises/luhn/src/main/java/LuhnValidator.java +7 -0
- data/tracks/java/exercises/minesweeper/src/test/java/MinesweeperBoardTest.java +1 -1
- data/tracks/java/exercises/perfect-numbers/src/test/java/NaturalNumberTest.java +1 -1
- data/tracks/java/exercises/queen-attack/src/test/java/QueenAttackCalculatorTest.java +1 -1
- data/tracks/java/exercises/rectangles/src/test/java/RectangleCounterTest.java +1 -1
- data/tracks/java/exercises/secret-handshake/src/main/java/HandshakeCalculator.java +5 -1
- data/tracks/java/exercises/sum-of-multiples/src/main/java/SumOfMultiples.java +10 -2
- data/tracks/java/exercises/triangle/src/example/java/Triangle.java +5 -5
- data/tracks/java/exercises/triangle/src/example/java/TriangleException.java +1 -3
- data/tracks/java/exercises/triangle/src/main/java/Triangle.java +11 -0
- data/tracks/java/exercises/triangle/src/main/java/TriangleException.java +1 -3
- data/tracks/javascript/.github/stale.yml +6 -0
- data/tracks/javascript/config.json +14 -0
- data/tracks/kotlin/docs/INSTALLATION.md +1 -1
- data/tracks/lisp/docs/INSTALLATION.md +1 -0
- data/tracks/perl6/README.md +9 -4
- data/tracks/perl6/config.json +5 -0
- data/tracks/perl6/exercises/luhn/Example.pm6 +15 -0
- data/tracks/perl6/exercises/luhn/Luhn.pm6 +4 -0
- data/tracks/perl6/exercises/luhn/example.yaml +6 -0
- data/tracks/perl6/exercises/luhn/luhn.t +122 -0
- data/tracks/python/exercises/acronym/acronym_test.py +1 -4
- data/tracks/r/exercises/hamming/test_hamming.R +15 -14
- data/tracks/ruby/lib/generator/command_line/generator_optparser.rb +3 -1
- data/tracks/ruby/lib/generator/exercise_case/assertion.rb +33 -5
- data/tracks/ruby/lib/generator/exercise_case/case_helpers.rb +39 -0
- data/tracks/ruby/lib/generator/exercise_case.rb +3 -37
- data/tracks/ruby/lib/generator/template_values.rb +2 -0
- data/tracks/ruby/test/generator/command_line/generator_optparser_test.rb +11 -2
- data/tracks/ruby/test/generator/exercise_case/case_helpers_test.rb +43 -0
- data/tracks/ruby/test/generator/underscore_test.rb +4 -0
- data/tracks/scala/config.json +10 -0
- data/tracks/scala/exercises/beer-song/build.sbt +3 -0
- data/tracks/scala/exercises/beer-song/example.scala +11 -0
- data/tracks/{java/exercises/luhn/src/main/java → scala/exercises/beer-song/src/main/scala}/.keep +0 -0
- data/tracks/scala/exercises/beer-song/src/test/scala/BeerSongTest.scala +52 -0
- data/tracks/vimscript/.travis.yml +13 -2
- data/tracks/vimscript/TRACK_HINTS.md +67 -0
- data/tracks/vimscript/bin/ci +21 -0
- data/tracks/vimscript/config.json +22 -8
- data/tracks/vimscript/docs/ABOUT.md +44 -0
- data/tracks/vimscript/docs/INSTALLATION.md +55 -0
- data/tracks/vimscript/docs/LEARNING.md +16 -0
- data/tracks/vimscript/docs/RESOURCES.md +24 -0
- data/tracks/vimscript/docs/TESTS.md +67 -0
- data/tracks/vimscript/exercises/bob/bob.vader +63 -0
- data/tracks/vimscript/exercises/bob/bob.vim +8 -0
- data/tracks/vimscript/exercises/bob/example.vim +23 -0
- data/tracks/vimscript/exercises/hamming/example.vim +18 -0
- data/tracks/vimscript/exercises/hamming/hamming.vader +20 -0
- data/tracks/vimscript/exercises/hamming/hamming.vim +13 -0
- data/tracks/vimscript/exercises/hello-world/example.vim +4 -0
- data/tracks/vimscript/exercises/hello-world/hello_world.vader +8 -0
- data/tracks/vimscript/exercises/hello-world/hello_world.vim +20 -0
- data/tracks/vimscript/exercises/leap/example.vim +3 -0
- data/tracks/vimscript/exercises/leap/leap.vader +11 -0
- data/tracks/vimscript/exercises/leap/leap.vim +9 -0
- metadata +47 -18
- 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
|
-
|
3
|
+
import "errors"
|
4
4
|
|
5
|
-
|
6
|
-
|
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
|
-
//
|
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
|
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]
|
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) &
|
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 =
|
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
|
36
|
-
o, size := DecodeVarint(tc.input)
|
37
|
-
if
|
38
|
-
|
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
|
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
|
49
|
-
if encoded := EncodeVarint(tc.
|
50
|
-
t.Fatalf("FAIL: case %d
|
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
|
}
|
@@ -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
|
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
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
assertThat(
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
assertThat(
|
65
|
-
|
66
|
-
|
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
|
}
|
@@ -9,7 +9,7 @@ import java.util.List;
|
|
9
9
|
|
10
10
|
import static org.junit.Assert.assertEquals;
|
11
11
|
|
12
|
-
public
|
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
|
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
|
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
|
@@ -1,3 +1,11 @@
|
|
1
|
-
|
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
|
-
|
4
|
+
class Triangle {
|
5
5
|
|
6
6
|
private double side1;
|
7
7
|
private double side2;
|
8
8
|
private double side3;
|
9
9
|
|
10
|
-
|
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
|
-
|
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
|
}
|
@@ -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
|
+
}
|