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,52 @@
|
|
1
|
+
import org.scalatest._
|
2
|
+
|
3
|
+
class BeerSongTest extends FunSuite {
|
4
|
+
|
5
|
+
test("first generic verse") {
|
6
|
+
val expected = "99 bottles of beer on the wall, 99 bottles of beer.\nTake one down and pass it around, 98 bottles of beer on the wall.\n"
|
7
|
+
assert(expected == BeerSong.verse(99))
|
8
|
+
}
|
9
|
+
|
10
|
+
test("last generic verse") {
|
11
|
+
pending // remove to run test
|
12
|
+
val expected = "3 bottles of beer on the wall, 3 bottles of beer.\nTake one down and pass it around, 2 bottles of beer on the wall.\n"
|
13
|
+
assert(expected == BeerSong.verse(3))
|
14
|
+
}
|
15
|
+
|
16
|
+
test("verse 2") {
|
17
|
+
pending // remove to run test
|
18
|
+
val expected = "2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.\n"
|
19
|
+
assert(expected == BeerSong.verse(2))
|
20
|
+
}
|
21
|
+
|
22
|
+
test("verse 1") {
|
23
|
+
pending // remove to run test
|
24
|
+
val expected = "1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.\n"
|
25
|
+
assert(expected == BeerSong.verse(1))
|
26
|
+
}
|
27
|
+
|
28
|
+
test("verse 0") {
|
29
|
+
pending // remove to run test
|
30
|
+
val expected = "No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n"
|
31
|
+
assert(expected == BeerSong.verse(0))
|
32
|
+
}
|
33
|
+
|
34
|
+
test("first two verses") {
|
35
|
+
pending // remove to run test
|
36
|
+
val expected = "99 bottles of beer on the wall, 99 bottles of beer.\nTake one down and pass it around, 98 bottles of beer on the wall.\n\n98 bottles of beer on the wall, 98 bottles of beer.\nTake one down and pass it around, 97 bottles of beer on the wall.\n"
|
37
|
+
assert(expected == BeerSong.verses(99, 98))
|
38
|
+
}
|
39
|
+
|
40
|
+
test("last three verses") {
|
41
|
+
pending // remove to run test
|
42
|
+
val expected = "2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.\n\n1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.\n\nNo more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n"
|
43
|
+
assert(expected == BeerSong.verses(2, 0))
|
44
|
+
}
|
45
|
+
|
46
|
+
test("all verses") {
|
47
|
+
pending // remove to run test
|
48
|
+
val expected = "99 bottles of beer on the wall, 99 bottles of beer.\nTake one down and pass it around, 98 bottles of beer on the wall.\n\n98 bottles of beer on the wall, 98 bottles of beer.\nTake one down and pass it around, 97 bottles of beer on the wall.\n\n97 bottles of beer on the wall, 97 bottles of beer.\nTake one down and pass it around, 96 bottles of beer on the wall.\n\n96 bottles of beer on the wall, 96 bottles of beer.\nTake one down and pass it around, 95 bottles of beer on the wall.\n\n95 bottles of beer on the wall, 95 bottles of beer.\nTake one down and pass it around, 94 bottles of beer on the wall.\n\n94 bottles of beer on the wall, 94 bottles of beer.\nTake one down and pass it around, 93 bottles of beer on the wall.\n\n93 bottles of beer on the wall, 93 bottles of beer.\nTake one down and pass it around, 92 bottles of beer on the wall.\n\n92 bottles of beer on the wall, 92 bottles of beer.\nTake one down and pass it around, 91 bottles of beer on the wall.\n\n91 bottles of beer on the wall, 91 bottles of beer.\nTake one down and pass it around, 90 bottles of beer on the wall.\n\n90 bottles of beer on the wall, 90 bottles of beer.\nTake one down and pass it around, 89 bottles of beer on the wall.\n\n89 bottles of beer on the wall, 89 bottles of beer.\nTake one down and pass it around, 88 bottles of beer on the wall.\n\n88 bottles of beer on the wall, 88 bottles of beer.\nTake one down and pass it around, 87 bottles of beer on the wall.\n\n87 bottles of beer on the wall, 87 bottles of beer.\nTake one down and pass it around, 86 bottles of beer on the wall.\n\n86 bottles of beer on the wall, 86 bottles of beer.\nTake one down and pass it around, 85 bottles of beer on the wall.\n\n85 bottles of beer on the wall, 85 bottles of beer.\nTake one down and pass it around, 84 bottles of beer on the wall.\n\n84 bottles of beer on the wall, 84 bottles of beer.\nTake one down and pass it around, 83 bottles of beer on the wall.\n\n83 bottles of beer on the wall, 83 bottles of beer.\nTake one down and pass it around, 82 bottles of beer on the wall.\n\n82 bottles of beer on the wall, 82 bottles of beer.\nTake one down and pass it around, 81 bottles of beer on the wall.\n\n81 bottles of beer on the wall, 81 bottles of beer.\nTake one down and pass it around, 80 bottles of beer on the wall.\n\n80 bottles of beer on the wall, 80 bottles of beer.\nTake one down and pass it around, 79 bottles of beer on the wall.\n\n79 bottles of beer on the wall, 79 bottles of beer.\nTake one down and pass it around, 78 bottles of beer on the wall.\n\n78 bottles of beer on the wall, 78 bottles of beer.\nTake one down and pass it around, 77 bottles of beer on the wall.\n\n77 bottles of beer on the wall, 77 bottles of beer.\nTake one down and pass it around, 76 bottles of beer on the wall.\n\n76 bottles of beer on the wall, 76 bottles of beer.\nTake one down and pass it around, 75 bottles of beer on the wall.\n\n75 bottles of beer on the wall, 75 bottles of beer.\nTake one down and pass it around, 74 bottles of beer on the wall.\n\n74 bottles of beer on the wall, 74 bottles of beer.\nTake one down and pass it around, 73 bottles of beer on the wall.\n\n73 bottles of beer on the wall, 73 bottles of beer.\nTake one down and pass it around, 72 bottles of beer on the wall.\n\n72 bottles of beer on the wall, 72 bottles of beer.\nTake one down and pass it around, 71 bottles of beer on the wall.\n\n71 bottles of beer on the wall, 71 bottles of beer.\nTake one down and pass it around, 70 bottles of beer on the wall.\n\n70 bottles of beer on the wall, 70 bottles of beer.\nTake one down and pass it around, 69 bottles of beer on the wall.\n\n69 bottles of beer on the wall, 69 bottles of beer.\nTake one down and pass it around, 68 bottles of beer on the wall.\n\n68 bottles of beer on the wall, 68 bottles of beer.\nTake one down and pass it around, 67 bottles of beer on the wall.\n\n67 bottles of beer on the wall, 67 bottles of beer.\nTake one down and pass it around, 66 bottles of beer on the wall.\n\n66 bottles of beer on the wall, 66 bottles of beer.\nTake one down and pass it around, 65 bottles of beer on the wall.\n\n65 bottles of beer on the wall, 65 bottles of beer.\nTake one down and pass it around, 64 bottles of beer on the wall.\n\n64 bottles of beer on the wall, 64 bottles of beer.\nTake one down and pass it around, 63 bottles of beer on the wall.\n\n63 bottles of beer on the wall, 63 bottles of beer.\nTake one down and pass it around, 62 bottles of beer on the wall.\n\n62 bottles of beer on the wall, 62 bottles of beer.\nTake one down and pass it around, 61 bottles of beer on the wall.\n\n61 bottles of beer on the wall, 61 bottles of beer.\nTake one down and pass it around, 60 bottles of beer on the wall.\n\n60 bottles of beer on the wall, 60 bottles of beer.\nTake one down and pass it around, 59 bottles of beer on the wall.\n\n59 bottles of beer on the wall, 59 bottles of beer.\nTake one down and pass it around, 58 bottles of beer on the wall.\n\n58 bottles of beer on the wall, 58 bottles of beer.\nTake one down and pass it around, 57 bottles of beer on the wall.\n\n57 bottles of beer on the wall, 57 bottles of beer.\nTake one down and pass it around, 56 bottles of beer on the wall.\n\n56 bottles of beer on the wall, 56 bottles of beer.\nTake one down and pass it around, 55 bottles of beer on the wall.\n\n55 bottles of beer on the wall, 55 bottles of beer.\nTake one down and pass it around, 54 bottles of beer on the wall.\n\n54 bottles of beer on the wall, 54 bottles of beer.\nTake one down and pass it around, 53 bottles of beer on the wall.\n\n53 bottles of beer on the wall, 53 bottles of beer.\nTake one down and pass it around, 52 bottles of beer on the wall.\n\n52 bottles of beer on the wall, 52 bottles of beer.\nTake one down and pass it around, 51 bottles of beer on the wall.\n\n51 bottles of beer on the wall, 51 bottles of beer.\nTake one down and pass it around, 50 bottles of beer on the wall.\n\n50 bottles of beer on the wall, 50 bottles of beer.\nTake one down and pass it around, 49 bottles of beer on the wall.\n\n49 bottles of beer on the wall, 49 bottles of beer.\nTake one down and pass it around, 48 bottles of beer on the wall.\n\n48 bottles of beer on the wall, 48 bottles of beer.\nTake one down and pass it around, 47 bottles of beer on the wall.\n\n47 bottles of beer on the wall, 47 bottles of beer.\nTake one down and pass it around, 46 bottles of beer on the wall.\n\n46 bottles of beer on the wall, 46 bottles of beer.\nTake one down and pass it around, 45 bottles of beer on the wall.\n\n45 bottles of beer on the wall, 45 bottles of beer.\nTake one down and pass it around, 44 bottles of beer on the wall.\n\n44 bottles of beer on the wall, 44 bottles of beer.\nTake one down and pass it around, 43 bottles of beer on the wall.\n\n43 bottles of beer on the wall, 43 bottles of beer.\nTake one down and pass it around, 42 bottles of beer on the wall.\n\n42 bottles of beer on the wall, 42 bottles of beer.\nTake one down and pass it around, 41 bottles of beer on the wall.\n\n41 bottles of beer on the wall, 41 bottles of beer.\nTake one down and pass it around, 40 bottles of beer on the wall.\n\n40 bottles of beer on the wall, 40 bottles of beer.\nTake one down and pass it around, 39 bottles of beer on the wall.\n\n39 bottles of beer on the wall, 39 bottles of beer.\nTake one down and pass it around, 38 bottles of beer on the wall.\n\n38 bottles of beer on the wall, 38 bottles of beer.\nTake one down and pass it around, 37 bottles of beer on the wall.\n\n37 bottles of beer on the wall, 37 bottles of beer.\nTake one down and pass it around, 36 bottles of beer on the wall.\n\n36 bottles of beer on the wall, 36 bottles of beer.\nTake one down and pass it around, 35 bottles of beer on the wall.\n\n35 bottles of beer on the wall, 35 bottles of beer.\nTake one down and pass it around, 34 bottles of beer on the wall.\n\n34 bottles of beer on the wall, 34 bottles of beer.\nTake one down and pass it around, 33 bottles of beer on the wall.\n\n33 bottles of beer on the wall, 33 bottles of beer.\nTake one down and pass it around, 32 bottles of beer on the wall.\n\n32 bottles of beer on the wall, 32 bottles of beer.\nTake one down and pass it around, 31 bottles of beer on the wall.\n\n31 bottles of beer on the wall, 31 bottles of beer.\nTake one down and pass it around, 30 bottles of beer on the wall.\n\n30 bottles of beer on the wall, 30 bottles of beer.\nTake one down and pass it around, 29 bottles of beer on the wall.\n\n29 bottles of beer on the wall, 29 bottles of beer.\nTake one down and pass it around, 28 bottles of beer on the wall.\n\n28 bottles of beer on the wall, 28 bottles of beer.\nTake one down and pass it around, 27 bottles of beer on the wall.\n\n27 bottles of beer on the wall, 27 bottles of beer.\nTake one down and pass it around, 26 bottles of beer on the wall.\n\n26 bottles of beer on the wall, 26 bottles of beer.\nTake one down and pass it around, 25 bottles of beer on the wall.\n\n25 bottles of beer on the wall, 25 bottles of beer.\nTake one down and pass it around, 24 bottles of beer on the wall.\n\n24 bottles of beer on the wall, 24 bottles of beer.\nTake one down and pass it around, 23 bottles of beer on the wall.\n\n23 bottles of beer on the wall, 23 bottles of beer.\nTake one down and pass it around, 22 bottles of beer on the wall.\n\n22 bottles of beer on the wall, 22 bottles of beer.\nTake one down and pass it around, 21 bottles of beer on the wall.\n\n21 bottles of beer on the wall, 21 bottles of beer.\nTake one down and pass it around, 20 bottles of beer on the wall.\n\n20 bottles of beer on the wall, 20 bottles of beer.\nTake one down and pass it around, 19 bottles of beer on the wall.\n\n19 bottles of beer on the wall, 19 bottles of beer.\nTake one down and pass it around, 18 bottles of beer on the wall.\n\n18 bottles of beer on the wall, 18 bottles of beer.\nTake one down and pass it around, 17 bottles of beer on the wall.\n\n17 bottles of beer on the wall, 17 bottles of beer.\nTake one down and pass it around, 16 bottles of beer on the wall.\n\n16 bottles of beer on the wall, 16 bottles of beer.\nTake one down and pass it around, 15 bottles of beer on the wall.\n\n15 bottles of beer on the wall, 15 bottles of beer.\nTake one down and pass it around, 14 bottles of beer on the wall.\n\n14 bottles of beer on the wall, 14 bottles of beer.\nTake one down and pass it around, 13 bottles of beer on the wall.\n\n13 bottles of beer on the wall, 13 bottles of beer.\nTake one down and pass it around, 12 bottles of beer on the wall.\n\n12 bottles of beer on the wall, 12 bottles of beer.\nTake one down and pass it around, 11 bottles of beer on the wall.\n\n11 bottles of beer on the wall, 11 bottles of beer.\nTake one down and pass it around, 10 bottles of beer on the wall.\n\n10 bottles of beer on the wall, 10 bottles of beer.\nTake one down and pass it around, 9 bottles of beer on the wall.\n\n9 bottles of beer on the wall, 9 bottles of beer.\nTake one down and pass it around, 8 bottles of beer on the wall.\n\n8 bottles of beer on the wall, 8 bottles of beer.\nTake one down and pass it around, 7 bottles of beer on the wall.\n\n7 bottles of beer on the wall, 7 bottles of beer.\nTake one down and pass it around, 6 bottles of beer on the wall.\n\n6 bottles of beer on the wall, 6 bottles of beer.\nTake one down and pass it around, 5 bottles of beer on the wall.\n\n5 bottles of beer on the wall, 5 bottles of beer.\nTake one down and pass it around, 4 bottles of beer on the wall.\n\n4 bottles of beer on the wall, 4 bottles of beer.\nTake one down and pass it around, 3 bottles of beer on the wall.\n\n3 bottles of beer on the wall, 3 bottles of beer.\nTake one down and pass it around, 2 bottles of beer on the wall.\n\n2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.\n\n1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.\n\nNo more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.\n"
|
49
|
+
assert(expected == BeerSong.verses(99, 0))
|
50
|
+
}
|
51
|
+
|
52
|
+
}
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# Setup
|
2
|
+
|
3
|
+
This track uses two tools to run the test suite and ensure best practices:
|
4
|
+
|
5
|
+
1. [vader.vim](https://github.com/junegunn/vader.vim)
|
6
|
+
2. [vint](https://github.com/Kuniwak/vint)
|
7
|
+
|
8
|
+
## Running tests
|
9
|
+
|
10
|
+
1. Install [vader.vim](https://github.com/junegunn/vader.vim/#installation).
|
11
|
+
1. Open your solution:
|
12
|
+
```
|
13
|
+
$ vim exercise.vim
|
14
|
+
```
|
15
|
+
1. Source the current file to make its global functions available to Vim:
|
16
|
+
```
|
17
|
+
:source %
|
18
|
+
```
|
19
|
+
1. Run the tests:
|
20
|
+
```
|
21
|
+
:Vader exercise.vader
|
22
|
+
```
|
23
|
+
|
24
|
+
Paths may vary.
|
25
|
+
|
26
|
+
If you want a convenient shortcut to the above steps, put this in your vimrc:
|
27
|
+
|
28
|
+
```vim
|
29
|
+
function! s:exercism_tests()
|
30
|
+
if expand('%:e') == 'vim'
|
31
|
+
let testfile = printf('%s/%s.vader', expand('%:h'),
|
32
|
+
\ tr(expand('%:h:t'), '-', '_'))
|
33
|
+
if !filereadable(testfile)
|
34
|
+
echoerr 'File does not exist: '. testfile
|
35
|
+
return
|
36
|
+
endif
|
37
|
+
source %
|
38
|
+
execute 'Vader' testfile
|
39
|
+
else
|
40
|
+
let sourcefile = printf('%s/%s.vim', expand('%:h'),
|
41
|
+
\ tr(expand('%:h:t'), '-', '_'))
|
42
|
+
if !filereadable(sourcefile)
|
43
|
+
echoerr 'File does not exist: '. sourcefile
|
44
|
+
return
|
45
|
+
endif
|
46
|
+
execute 'source' sourcefile
|
47
|
+
Vader
|
48
|
+
endif
|
49
|
+
endfunction
|
50
|
+
|
51
|
+
autocmd BufRead *.{vader,vim}
|
52
|
+
\ command! -buffer Test call s:exercism_tests()
|
53
|
+
```
|
54
|
+
|
55
|
+
Afterwards open any `.vim` or `.vader` file from an exercise directory and run
|
56
|
+
the `:Test` command.
|
57
|
+
|
58
|
+
## Linting Vim files
|
59
|
+
|
60
|
+
1. Install [vint](https://github.com/Kuniwak/vint#quick-start).
|
61
|
+
1. Recursively lint all Vim files:
|
62
|
+
```
|
63
|
+
$ vint .
|
64
|
+
```
|
65
|
+
|
66
|
+
For more detailed information about the Vim script track, please see the
|
67
|
+
[help page](http://exercism.io/languages/vimscript).
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
set -ex
|
4
|
+
|
5
|
+
mkdir tmp
|
6
|
+
trap '{ rm -rf tmp; }' EXIT
|
7
|
+
|
8
|
+
git clone https://github.com/junegunn/vader.vim.git tmp/vader.vim
|
9
|
+
|
10
|
+
cat >tmp/vimrc <<EOF
|
11
|
+
filetype off
|
12
|
+
set runtimepath+=tmp/vader.vim
|
13
|
+
filetype plugin on
|
14
|
+
syntax enable
|
15
|
+
|
16
|
+
for file in glob('exercises/*/example.vim', 0, 1)
|
17
|
+
execute 'source' file
|
18
|
+
endfor
|
19
|
+
EOF
|
20
|
+
|
21
|
+
TERM=xterm HOME=/dev/null vim -XNu tmp/vimrc -i NONE -c 'Vader! exercises/*/*.vader'
|
@@ -3,19 +3,33 @@
|
|
3
3
|
"language": "Vim script",
|
4
4
|
"repository": "https://github.com/exercism/xvimscript",
|
5
5
|
"active": false,
|
6
|
-
"test_pattern": "TODO",
|
7
6
|
"exercises": [
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
{
|
8
|
+
"slug": "hello-world",
|
9
|
+
"difficulty": 1,
|
10
|
+
"topics": []
|
11
|
+
},
|
12
|
+
{
|
13
|
+
"slug": "leap",
|
14
|
+
"difficulty": 1,
|
15
|
+
"topics": []
|
16
|
+
},
|
17
|
+
{
|
18
|
+
"slug": "hamming",
|
19
|
+
"difficulty": 1,
|
20
|
+
"topics": []
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"slug": "bob",
|
24
|
+
"difficulty": 1,
|
25
|
+
"topics": []
|
26
|
+
}
|
12
27
|
],
|
28
|
+
"deprecated": [],
|
13
29
|
"ignored": [
|
14
30
|
"bin",
|
15
31
|
"img",
|
16
32
|
"docs"
|
17
33
|
],
|
18
|
-
"foregone": [
|
19
|
-
|
20
|
-
]
|
34
|
+
"foregone": []
|
21
35
|
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
## ABOUT
|
2
|
+
|
3
|
+
[Vim](http://www.vim.org) is a decades old text editor that is still wildly
|
4
|
+
popular among programmers and people who like working in terminal emulators.
|
5
|
+
|
6
|
+
In Vim, keys don't always do the same things. It depends in which mode you're
|
7
|
+
in. You constantly switch between modes, there is a mode for navigation, a mode
|
8
|
+
for insertion, a mode for selecting regions of text, a mode for entering
|
9
|
+
commands, and so on. This sounds complicated, but you quickly get used to it.
|
10
|
+
|
11
|
+
The biggest difference to other editors is Vim's modal interface. If you use
|
12
|
+
Vim, you don't use complicated shortcuts, you speak a language.
|
13
|
+
|
14
|
+
E.g. when you hit `d` in normal mode, you initiate a delete action. Then you
|
15
|
+
have to choose the region to act upon. E.g. `dw` deletes until the end of the
|
16
|
+
current word. `dd` deletes the current line. If the cursor is anywhere in a
|
17
|
+
double quote, you can use `ci"` to change this quote.
|
18
|
+
|
19
|
+
You reduce the risk of
|
20
|
+
[carpal tunnel syndrome](https://en.wikipedia.org/wiki/Carpal_tunnel_syndrome)
|
21
|
+
by not hitting several keys at once, but but pressing single keys in sequence.
|
22
|
+
|
23
|
+
For convenience, often used keys at put on the homerow or near it, so you don't
|
24
|
+
have to move your hands back and forth all the time.
|
25
|
+
|
26
|
+
Yes, there's a lot to learn at first, but when you get it, you can edit text
|
27
|
+
faster and more precisely than with most other editors. There is a reason people
|
28
|
+
are still using Vim!
|
29
|
+
|
30
|
+
Vim has its own scripting language built in. It's called `Vimscript`, or `Vim
|
31
|
+
script`, or `VimL`, depending on who you ask. It's a real programming language
|
32
|
+
and you also use it to configure Vim. The configuration file, called `vimrc`, is
|
33
|
+
merely a sequence of Vim commands, functions, and expressions.
|
34
|
+
|
35
|
+
This means Vim's configuration is
|
36
|
+
[Turing complete](https://en.wikipedia.org/wiki/Turing_completeness). You can
|
37
|
+
start small, add a few lines to it, then add more, and you'll end up with entire
|
38
|
+
plugins. There's nothing you can't do.
|
39
|
+
|
40
|
+
#### Bonus
|
41
|
+
|
42
|
+
Take it with a grain of salt, but there is an
|
43
|
+
[editor war](https://en.wikipedia.org/wiki/Editor_war) going on between Vim
|
44
|
+
and Emacs for a long time already. :-)
|
@@ -0,0 +1,55 @@
|
|
1
|
+
## Installation
|
2
|
+
|
3
|
+
You need [Vim](http://www.vim.org) to do the exercises:
|
4
|
+
|
5
|
+
- [macOS](#macos)
|
6
|
+
- [Ubuntu / Debian](#ubuntu--debian)
|
7
|
+
- [Windows](#windows)
|
8
|
+
- [Source](#source)
|
9
|
+
|
10
|
+
#### macOS
|
11
|
+
|
12
|
+
The OS ships with Vim by default, but it's a hopelessly outdated version.
|
13
|
+
|
14
|
+
Chances are you're either using [MacPorts](https://www.macports.org) or
|
15
|
+
[Homebrew](https://brew.sh) to install software.
|
16
|
+
|
17
|
+
Homebrew:
|
18
|
+
|
19
|
+
```
|
20
|
+
$ brew update
|
21
|
+
$ brew install vim
|
22
|
+
```
|
23
|
+
|
24
|
+
MacPorts:
|
25
|
+
|
26
|
+
```
|
27
|
+
$ sudo port install vim +huge
|
28
|
+
```
|
29
|
+
|
30
|
+
If you want a GUI, have a look at [MacVim](https://macvim-dev.github.io/macvim)
|
31
|
+
instead.
|
32
|
+
|
33
|
+
#### Ubuntu / Debian
|
34
|
+
|
35
|
+
Install a full-fledged Vim with GUI support (`gvim`):
|
36
|
+
|
37
|
+
```
|
38
|
+
$ sudo apt-get update
|
39
|
+
$ sudo apt-get install vim-gtk
|
40
|
+
```
|
41
|
+
|
42
|
+
#### Windows
|
43
|
+
|
44
|
+
Using [Chocolatey](https://chocolatey.org):
|
45
|
+
|
46
|
+
```
|
47
|
+
C:\> choco install vim
|
48
|
+
```
|
49
|
+
|
50
|
+
Or download and install directly from [here](http://www.vim.org/download.php#pc).
|
51
|
+
|
52
|
+
#### Source
|
53
|
+
|
54
|
+
If you want to compile the latest Vim yourself, check out the [official
|
55
|
+
repository on GitHub](https://github.com/vim/vim).
|
@@ -0,0 +1,16 @@
|
|
1
|
+
## LEARNING
|
2
|
+
|
3
|
+
Vim comes with great documentation built in already. The interface to the
|
4
|
+
documentation is the `:help` command.
|
5
|
+
|
6
|
+
For an introduction, see `:h user-manual`.
|
7
|
+
|
8
|
+
Almost all Vim installations also come with an interactive tutorial:
|
9
|
+
|
10
|
+
```
|
11
|
+
$ vimtutor
|
12
|
+
```
|
13
|
+
|
14
|
+
Vim is decades old and still popular. You will find a lot of resources about it
|
15
|
+
on the web, some better than others. The good ones are listed
|
16
|
+
[here](RESOURCES.md).
|
@@ -0,0 +1,24 @@
|
|
1
|
+
## RESOURCES
|
2
|
+
|
3
|
+
#### General resources
|
4
|
+
|
5
|
+
- [vim-galore](https://github.com/mhinz/vim-galore) is a huge guide about all
|
6
|
+
things Vim.
|
7
|
+
- [Why, oh WHY, do those #?@! nutheads use vi?](http://www.viemu.com/a-why-vi-vim.html) explains common misconceptions about vi and Vim.
|
8
|
+
- [Your problem with Vim is that you don't grok vi](http://stackoverflow.com/a/1220118) is a pure gem. Read it every once in a while.
|
9
|
+
|
10
|
+
#### Vim scripting
|
11
|
+
|
12
|
+
- [Learn Vimscript the Hard Way](http://learnvimscriptthehardway.stevelosh.com)
|
13
|
+
- [IBM DeveloperWorks: Scripting the Vim
|
14
|
+
editor](http://www.ibm.com/developerworks/views/linux/libraryview.jsp?sort_order=asc&sort_by=Title&search_by=scripting+the+vim+editor)
|
15
|
+
|
16
|
+
#### Boooks
|
17
|
+
|
18
|
+
There is only one good book about Vim out there: [Practical
|
19
|
+
Vim](https://pragprog.com/book/dnvim2/practical-vim-second-edition).
|
20
|
+
|
21
|
+
#### Screencasts
|
22
|
+
|
23
|
+
- [vimcasts.org](http://vimcasts.org/episodes/archive)
|
24
|
+
- [wincent on YouTube](https://www.youtube.com/channel/UCXPHFM88IlFn68OmLwtPmZA)
|
@@ -0,0 +1,67 @@
|
|
1
|
+
## SETUP
|
2
|
+
|
3
|
+
This track uses two tools to run the test suite and ensure best practices:
|
4
|
+
|
5
|
+
1. [vader.vim](https://github.com/junegunn/vader.vim)
|
6
|
+
2. [vint](https://github.com/Kuniwak/vint)
|
7
|
+
|
8
|
+
#### Running tests
|
9
|
+
|
10
|
+
1. Install [vader.vim](https://github.com/junegunn/vader.vim/#installation).
|
11
|
+
1. Open your solution:
|
12
|
+
```
|
13
|
+
$ vim exercise.vim
|
14
|
+
```
|
15
|
+
1. Source the current file to make its global functions available to Vim:
|
16
|
+
```
|
17
|
+
:source %
|
18
|
+
```
|
19
|
+
1. Run the tests:
|
20
|
+
```
|
21
|
+
:Vader exercise.vader
|
22
|
+
```
|
23
|
+
|
24
|
+
Paths may vary.
|
25
|
+
|
26
|
+
If you want a convenient shortcut to the above steps, put this in your vimrc:
|
27
|
+
|
28
|
+
```vim
|
29
|
+
function! s:exercism_tests()
|
30
|
+
if expand('%:e') == 'vim'
|
31
|
+
let testfile = printf('%s/%s.vader', expand('%:h'),
|
32
|
+
\ tr(expand('%:h:t'), '-', '_'))
|
33
|
+
if !filereadable(testfile)
|
34
|
+
echoerr 'File does not exist: '. testfile
|
35
|
+
return
|
36
|
+
endif
|
37
|
+
source %
|
38
|
+
execute 'Vader' testfile
|
39
|
+
else
|
40
|
+
let sourcefile = printf('%s/%s.vim', expand('%:h'),
|
41
|
+
\ tr(expand('%:h:t'), '-', '_'))
|
42
|
+
if !filereadable(sourcefile)
|
43
|
+
echoerr 'File does not exist: '. sourcefile
|
44
|
+
return
|
45
|
+
endif
|
46
|
+
execute 'source' sourcefile
|
47
|
+
Vader
|
48
|
+
endif
|
49
|
+
endfunction
|
50
|
+
|
51
|
+
autocmd BufRead *.{vader,vim}
|
52
|
+
\ command! -buffer Test call s:exercism_tests()
|
53
|
+
```
|
54
|
+
|
55
|
+
Afterwards open any `.vim` or `.vader` file from an exercise directory and run
|
56
|
+
the `:Test` command.
|
57
|
+
|
58
|
+
#### Linting Vim files
|
59
|
+
|
60
|
+
1. Install [vint](https://github.com/Kuniwak/vint#quick-start).
|
61
|
+
1. Recursively lint all Vim files:
|
62
|
+
```
|
63
|
+
$ vint .
|
64
|
+
```
|
65
|
+
|
66
|
+
For more detailed information about the Vim script track, please see the
|
67
|
+
[help page](http://exercism.io/languages/vimscript).
|
@@ -0,0 +1,63 @@
|
|
1
|
+
Execute (stating something):
|
2
|
+
let drivel = 'Tom-ay-to, tom-aaah-to.'
|
3
|
+
AssertEqual 'Whatever.', Answer(drivel)
|
4
|
+
|
5
|
+
Execute (shouting):
|
6
|
+
let drivel = 'WATCH OUT!'
|
7
|
+
AssertEqual 'Whoa, chill out!', Answer(drivel)
|
8
|
+
|
9
|
+
Execute (asking question):
|
10
|
+
let drivel = 'Does this cryogenic chamber make me look fat?'
|
11
|
+
AssertEqual 'Sure.', Answer(drivel)
|
12
|
+
|
13
|
+
Execute (asking numeric question):
|
14
|
+
let drivel = 'You are, what, like 15?'
|
15
|
+
AssertEqual 'Sure.', Answer(drivel)
|
16
|
+
|
17
|
+
Execute (talkig forcefully):
|
18
|
+
let drivel = "Let's go make out behind the gym!"
|
19
|
+
AssertEqual 'Whatever.', Answer(drivel)
|
20
|
+
|
21
|
+
Execute (using acronyms in regular speech):
|
22
|
+
let drivel = "It's okay if you don't want to go to the DMV."
|
23
|
+
AssertEqual 'Whatever.', Answer(drivel)
|
24
|
+
|
25
|
+
Execute (forceful questions):
|
26
|
+
let drivel = 'WHAT THE HELL WERE YOU THINKING?'
|
27
|
+
AssertEqual 'Whoa, chill out!', Answer(drivel)
|
28
|
+
|
29
|
+
Execute (shouting numbers):
|
30
|
+
let drivel = '1, 2, 3 GO!'
|
31
|
+
AssertEqual 'Whoa, chill out!', Answer(drivel)
|
32
|
+
|
33
|
+
Execute (only numbers):
|
34
|
+
let drivel = '1, 2, 3'
|
35
|
+
AssertEqual 'Whatever.', Answer(drivel)
|
36
|
+
|
37
|
+
Execute (question with only numbers):
|
38
|
+
let drivel = '4?'
|
39
|
+
AssertEqual 'Sure.', Answer(drivel)
|
40
|
+
|
41
|
+
Execute (shouting with special characters):
|
42
|
+
let drivel = 'ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!'
|
43
|
+
AssertEqual 'Whoa, chill out!', Answer(drivel)
|
44
|
+
|
45
|
+
Execute (shouting with no exclamation mark):
|
46
|
+
let drivel = 'I HATE YOU'
|
47
|
+
AssertEqual 'Whoa, chill out!', Answer(drivel)
|
48
|
+
|
49
|
+
Execute (statement containing question mark):
|
50
|
+
let drivel = 'Ending with ? means a question.'
|
51
|
+
AssertEqual 'Whatever.', Answer(drivel)
|
52
|
+
|
53
|
+
Execute (prattling on):
|
54
|
+
let drivel = 'Wait! Hang on. Are you going to be OK?'
|
55
|
+
AssertEqual 'Sure.', Answer(drivel)
|
56
|
+
|
57
|
+
Execute (silence):
|
58
|
+
let drivel = ''
|
59
|
+
AssertEqual 'Fine. Be that way!', Answer(drivel)
|
60
|
+
|
61
|
+
Execute (prolonged silence):
|
62
|
+
let drivel = ' '
|
63
|
+
AssertEqual 'Fine. Be that way!', Answer(drivel)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
function! Answer(drivel) abort
|
2
|
+
if s:is_silent(a:drivel)
|
3
|
+
return 'Fine. Be that way!'
|
4
|
+
elseif s:is_loud(a:drivel)
|
5
|
+
return 'Whoa, chill out!'
|
6
|
+
elseif s:is_quizzical(a:drivel)
|
7
|
+
return 'Sure.'
|
8
|
+
else
|
9
|
+
return 'Whatever.'
|
10
|
+
endif
|
11
|
+
endfunction
|
12
|
+
|
13
|
+
function! s:is_silent(phrase) abort
|
14
|
+
return a:phrase =~? '^\s*$'
|
15
|
+
endfunction
|
16
|
+
|
17
|
+
function! s:is_loud(phrase) abort
|
18
|
+
return a:phrase =~# '[A-Z]' && a:phrase ==# toupper(a:phrase)
|
19
|
+
endfunction
|
20
|
+
|
21
|
+
function! s:is_quizzical(phrase) abort
|
22
|
+
return a:phrase =~? '?$'
|
23
|
+
endfunction
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"
|
2
|
+
" This function takes two strings which represent strands and returns
|
3
|
+
" their Hamming distance.
|
4
|
+
"
|
5
|
+
" If the lengths of the strands don't match, throw this exception:
|
6
|
+
"
|
7
|
+
" 'The two strands must have the same length.'
|
8
|
+
"
|
9
|
+
function! Hamming(strand1, strand2)
|
10
|
+
if len(a:strand1) != len(a:strand2)
|
11
|
+
throw 'The two strands must have the same length.'
|
12
|
+
endif
|
13
|
+
let hamming = 0
|
14
|
+
for i in range(len(a:strand1))
|
15
|
+
let hamming += (a:strand1[i] != a:strand2[i])
|
16
|
+
endfor
|
17
|
+
return hamming
|
18
|
+
endfunction
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Execute ("empty strands"):
|
2
|
+
AssertEqual 0, Hamming('', '')
|
3
|
+
|
4
|
+
Execute (identical strands):
|
5
|
+
AssertEqual 0, Hamming('AGT', 'AGT')
|
6
|
+
|
7
|
+
Execute (one difference):
|
8
|
+
AssertEqual 1, Hamming('AGT', 'AGG')
|
9
|
+
|
10
|
+
Execute (reversed strand):
|
11
|
+
AssertEqual 2, Hamming('AGT', 'TGA')
|
12
|
+
|
13
|
+
Execute (strands are off by one):
|
14
|
+
AssertEqual 9, Hamming('GGACGGATTCTG', 'AGGACGGATTCT')
|
15
|
+
|
16
|
+
Execute (strands of different length throw exception):
|
17
|
+
AssertThrows call Hamming('A', 'AA')
|
18
|
+
AssertEqual 'The two strands must have the same length.', g:vader_exception
|
19
|
+
AssertThrows call Hamming('AA', 'A')
|
20
|
+
AssertEqual 'The two strands must have the same length.', g:vader_exception
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"
|
2
|
+
" This function takes two strings which represent strands and returns
|
3
|
+
" their Hamming distance.
|
4
|
+
"
|
5
|
+
" If the lengths of the strands don't match, throw this exception:
|
6
|
+
"
|
7
|
+
" 'The two strands must have the same length.'
|
8
|
+
"
|
9
|
+
function! Hamming(strand1, strand2)
|
10
|
+
|
11
|
+
" your solution goes here
|
12
|
+
|
13
|
+
endfunction
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Execute (says hello using default argument):
|
2
|
+
AssertEqual "Hello, World!", Hello()
|
3
|
+
|
4
|
+
Execute (says hello using name "Bram"):
|
5
|
+
AssertEqual "Hello, Bram!", Hello('Bram')
|
6
|
+
|
7
|
+
Execute (says hello using name "Bill Joy"):
|
8
|
+
AssertEqual "Hello, Bill Joy!", Hello('Bill Joy')
|
@@ -0,0 +1,20 @@
|
|
1
|
+
"
|
2
|
+
" Greet someone or something!
|
3
|
+
"
|
4
|
+
" If no argument is given, return 'Hello, World!'.
|
5
|
+
" If the optional argument is given, greet that name instead.
|
6
|
+
"
|
7
|
+
" Hint: If you're confused by the first line in the function,
|
8
|
+
" read `:help a:0`.
|
9
|
+
"
|
10
|
+
" It also uses the short if-then-else syntax which is
|
11
|
+
" called ternary operator in other languages:
|
12
|
+
"
|
13
|
+
" condition ? true : false
|
14
|
+
"
|
15
|
+
function! Hello(...) abort
|
16
|
+
let name = (a:0 == 1 ? a:1 : 'World')
|
17
|
+
|
18
|
+
" your implementation goes here
|
19
|
+
|
20
|
+
endfunction
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Execute (2000 is a leap year):
|
2
|
+
AssertEqual 1, IsLeap(2000)
|
3
|
+
|
4
|
+
Execute (2015 is not a leap year):
|
5
|
+
AssertEqual 0, IsLeap(2015)
|
6
|
+
|
7
|
+
Execute (2016 is a leap year):
|
8
|
+
AssertEqual 1, IsLeap(2016)
|
9
|
+
|
10
|
+
Execute (2100 is not a leap year):
|
11
|
+
AssertEqual 0, IsLeap(2100)
|