trackler 2.2.1.74 → 2.2.1.75

Sign up to get free protection for your applications and to get access to all the features.
Files changed (227) hide show
  1. checksums.yaml +4 -4
  2. data/fixtures/tracks/fruit/docs/something.md +0 -0
  3. data/lib/trackler/version.rb +1 -1
  4. data/problem-specifications/README.md +8 -4
  5. data/problem-specifications/exercises/acronym/canonical-data.json +19 -7
  6. data/problem-specifications/exercises/all-your-base/canonical-data.json +106 -64
  7. data/problem-specifications/exercises/allergies/canonical-data.json +37 -13
  8. data/tracks/c/config.json +176 -176
  9. data/tracks/clojure/config.json +17 -1
  10. data/tracks/clojure/exercises/isbn-verifier/README.md +43 -0
  11. data/tracks/clojure/exercises/isbn-verifier/project.clj +4 -0
  12. data/tracks/clojure/exercises/isbn-verifier/src/example.clj +17 -0
  13. data/tracks/clojure/exercises/isbn-verifier/src/isbn_verifier.clj +3 -0
  14. data/tracks/clojure/exercises/isbn-verifier/test/isbn_verifier_test.clj +42 -0
  15. data/tracks/clojure/exercises/proverb/README.md +15 -0
  16. data/tracks/clojure/exercises/proverb/project.clj +4 -0
  17. data/tracks/clojure/exercises/proverb/src/example.clj +15 -0
  18. data/tracks/clojure/exercises/proverb/src/proverb.clj +3 -0
  19. data/tracks/clojure/exercises/proverb/test/proverb_test.clj +14 -0
  20. data/tracks/common-lisp/docs/LEARNING.md +4 -3
  21. data/tracks/common-lisp/docs/RESOURCES.md +11 -0
  22. data/tracks/delphi/.gitignore +1 -0
  23. data/tracks/delphi/config.json +24 -0
  24. data/tracks/delphi/docs/INSTALLATION.md +1 -1
  25. data/tracks/delphi/exercises/isbn-verifier/ISBNVerifier.dpr +60 -0
  26. data/tracks/delphi/exercises/isbn-verifier/README.md +68 -0
  27. data/tracks/delphi/exercises/isbn-verifier/uISBNVerifierExample.pas +46 -0
  28. data/tracks/delphi/exercises/isbn-verifier/uTestISBNVerifier.pas +136 -0
  29. data/tracks/delphi/exercises/secret-handshake/README.md +56 -0
  30. data/tracks/delphi/exercises/secret-handshake/SecretHandshake.dpr +60 -0
  31. data/tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas +56 -0
  32. data/tracks/delphi/exercises/secret-handshake/uTestSecretHandshake.pas +215 -0
  33. data/tracks/ecmascript/docs/ABOUT.md +13 -9
  34. data/tracks/factor/exercises/two-fer/README.md +1 -1
  35. data/tracks/fsharp/docs/RESOURCES.md +1 -1
  36. data/tracks/fsharp/generators/{Input.fs → CanonicalData.fs} +5 -10
  37. data/tracks/fsharp/generators/Exercise.fs +11 -10
  38. data/tracks/fsharp/generators/{Output.fs → Formatting.fs} +2 -56
  39. data/tracks/fsharp/generators/Generators.fs +93 -93
  40. data/tracks/fsharp/generators/Generators.fsproj +9 -4
  41. data/tracks/fsharp/generators/Options.fs +1 -1
  42. data/tracks/fsharp/generators/Program.fs +3 -3
  43. data/tracks/fsharp/generators/Rendering.fs +57 -0
  44. data/tracks/go/exercises/all-your-base/.meta/gen.go +80 -0
  45. data/tracks/go/exercises/all-your-base/.meta/hints.md +13 -0
  46. data/tracks/go/exercises/all-your-base/README.md +16 -1
  47. data/tracks/go/exercises/all-your-base/all_your_base_test.go +12 -163
  48. data/tracks/go/exercises/all-your-base/cases_test.go +183 -0
  49. data/tracks/go/exercises/all-your-base/example.go +25 -29
  50. data/tracks/java/CONTRIBUTING.md +1 -1
  51. data/tracks/java/POLICIES.md +15 -1
  52. data/tracks/java/exercises/flatten-array/.meta/hints.md +58 -0
  53. data/tracks/java/exercises/flatten-array/README.md +62 -0
  54. data/tracks/java/exercises/hamming/src/main/java/Hamming.java +1 -1
  55. data/tracks/java/exercises/matrix/.meta/src/reference/java/Matrix.java +6 -6
  56. data/tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java +2 -2
  57. data/tracks/java/exercises/meetup/.meta/src/reference/java/MeetupSchedule.java +1 -1
  58. data/tracks/java/exercises/meetup/src/main/java/MeetupSchedule.java +1 -1
  59. data/tracks/java/exercises/pig-latin/.meta/hints.md +58 -0
  60. data/tracks/java/exercises/pig-latin/README.md +61 -0
  61. data/tracks/java/exercises/reverse-string/src/main/java/ReverseString.java +2 -2
  62. data/tracks/java/exercises/secret-handshake/README.md +1 -1
  63. data/tracks/javascript/.eslintignore +0 -3
  64. data/tracks/javascript/exercises/food-chain/example.js +50 -37
  65. data/tracks/javascript/exercises/octal/example.js +1 -1
  66. data/tracks/javascript/exercises/robot-name/robot-name.spec.js +7 -7
  67. data/tracks/javascript/package-lock.json +1846 -0
  68. data/tracks/python/docs/EXERCISE_README_INSERT.md +15 -0
  69. data/tracks/python/exercises/accumulate/README.md +15 -0
  70. data/tracks/python/exercises/acronym/README.md +15 -0
  71. data/tracks/python/exercises/all-your-base/README.md +15 -0
  72. data/tracks/python/exercises/all-your-base/all_your_base_test.py +19 -9
  73. data/tracks/python/exercises/allergies/README.md +15 -0
  74. data/tracks/python/exercises/alphametics/README.md +15 -0
  75. data/tracks/python/exercises/anagram/README.md +15 -0
  76. data/tracks/python/exercises/atbash-cipher/README.md +15 -0
  77. data/tracks/python/exercises/beer-song/README.md +16 -1
  78. data/tracks/python/exercises/binary-search-tree/README.md +16 -2
  79. data/tracks/python/exercises/binary-search/README.md +15 -0
  80. data/tracks/python/exercises/binary-search/binary_search_test.py +14 -4
  81. data/tracks/python/exercises/binary/README.md +15 -0
  82. data/tracks/python/exercises/binary/binary_test.py +14 -4
  83. data/tracks/python/exercises/bob/README.md +15 -0
  84. data/tracks/python/exercises/book-store/README.md +15 -0
  85. data/tracks/python/exercises/bracket-push/README.md +15 -0
  86. data/tracks/python/exercises/change/README.md +15 -0
  87. data/tracks/python/exercises/circular-buffer/README.md +15 -0
  88. data/tracks/python/exercises/circular-buffer/circular_buffer_test.py +15 -5
  89. data/tracks/python/exercises/circular-buffer/example.py +2 -2
  90. data/tracks/python/exercises/clock/README.md +15 -0
  91. data/tracks/python/exercises/collatz-conjecture/.meta/hints.md +1 -1
  92. data/tracks/python/exercises/collatz-conjecture/README.md +15 -0
  93. data/tracks/python/exercises/complex-numbers/README.md +15 -0
  94. data/tracks/python/exercises/connect/README.md +18 -3
  95. data/tracks/python/exercises/crypto-square/README.md +15 -0
  96. data/tracks/python/exercises/diamond/README.md +15 -0
  97. data/tracks/python/exercises/difference-of-squares/README.md +15 -0
  98. data/tracks/python/exercises/diffie-hellman/README.md +14 -0
  99. data/tracks/python/exercises/dominoes/README.md +16 -1
  100. data/tracks/python/exercises/error-handling/README.md +17 -0
  101. data/tracks/python/exercises/error-handling/error_handling_test.py +13 -3
  102. data/tracks/python/exercises/error-handling/example.py +1 -1
  103. data/tracks/python/exercises/etl/README.md +16 -1
  104. data/tracks/python/exercises/flatten-array/README.md +15 -0
  105. data/tracks/python/exercises/food-chain/README.md +15 -0
  106. data/tracks/python/exercises/forth/README.md +15 -0
  107. data/tracks/python/exercises/forth/example.py +7 -9
  108. data/tracks/python/exercises/forth/forth_test.py +107 -17
  109. data/tracks/python/exercises/gigasecond/README.md +15 -0
  110. data/tracks/python/exercises/go-counting/README.md +21 -3
  111. data/tracks/python/exercises/grade-school/README.md +15 -0
  112. data/tracks/python/exercises/grains/README.md +15 -0
  113. data/tracks/python/exercises/grains/grains_test.py +16 -6
  114. data/tracks/python/exercises/grep/README.md +15 -0
  115. data/tracks/python/exercises/hamming/README.md +15 -0
  116. data/tracks/python/exercises/hamming/hamming_test.py +12 -2
  117. data/tracks/python/exercises/hello-world/README.md +15 -0
  118. data/tracks/python/exercises/hexadecimal/README.md +15 -0
  119. data/tracks/python/exercises/hexadecimal/hexadecimal_test.py +11 -1
  120. data/tracks/python/exercises/house/README.md +16 -1
  121. data/tracks/python/exercises/isogram/README.md +15 -0
  122. data/tracks/python/exercises/kindergarten-garden/README.md +18 -3
  123. data/tracks/python/exercises/largest-series-product/README.md +15 -0
  124. data/tracks/python/exercises/largest-series-product/largest_series_product_test.py +14 -4
  125. data/tracks/python/exercises/leap/README.md +15 -0
  126. data/tracks/python/exercises/linked-list/README.md +15 -0
  127. data/tracks/python/exercises/list-ops/README.md +15 -0
  128. data/tracks/python/exercises/luhn/README.md +15 -0
  129. data/tracks/python/exercises/markdown/README.md +18 -0
  130. data/tracks/python/exercises/matrix/README.md +15 -0
  131. data/tracks/python/exercises/meetup/README.md +31 -12
  132. data/tracks/python/exercises/meetup/meetup_test.py +11 -1
  133. data/tracks/python/exercises/minesweeper/README.md +15 -0
  134. data/tracks/python/exercises/minesweeper/minesweeper_test.py +12 -2
  135. data/tracks/python/exercises/nth-prime/README.md +15 -0
  136. data/tracks/python/exercises/nth-prime/nth_prime_test.py +11 -1
  137. data/tracks/python/exercises/nucleotide-count/README.md +17 -2
  138. data/tracks/python/exercises/nucleotide-count/nucleotide_count_test.py +11 -1
  139. data/tracks/python/exercises/ocr-numbers/README.md +16 -1
  140. data/tracks/python/exercises/ocr-numbers/ocr_numbers_test.py +12 -2
  141. data/tracks/python/exercises/octal/README.md +15 -0
  142. data/tracks/python/exercises/octal/octal_test.py +16 -3
  143. data/tracks/python/exercises/palindrome-products/README.md +16 -1
  144. data/tracks/python/exercises/pangram/README.md +15 -0
  145. data/tracks/python/exercises/pascals-triangle/README.md +16 -1
  146. data/tracks/python/exercises/perfect-numbers/README.md +15 -0
  147. data/tracks/python/exercises/perfect-numbers/perfect_numbers_test.py +13 -3
  148. data/tracks/python/exercises/phone-number/README.md +16 -2
  149. data/tracks/python/exercises/phone-number/example.py +1 -1
  150. data/tracks/python/exercises/phone-number/phone_number_test.py +17 -7
  151. data/tracks/python/exercises/pig-latin/README.md +15 -0
  152. data/tracks/python/exercises/point-mutations/README.md +15 -0
  153. data/tracks/python/exercises/poker/README.md +15 -0
  154. data/tracks/python/exercises/pov/README.md +20 -2
  155. data/tracks/python/exercises/pov/example.py +2 -2
  156. data/tracks/python/exercises/pov/pov_test.py +15 -5
  157. data/tracks/python/exercises/prime-factors/README.md +15 -0
  158. data/tracks/python/exercises/protein-translation/README.md +15 -0
  159. data/tracks/python/exercises/protein-translation/protein_translation_test.py +10 -0
  160. data/tracks/python/exercises/proverb/README.md +14 -0
  161. data/tracks/python/exercises/pythagorean-triplet/README.md +15 -0
  162. data/tracks/python/exercises/pythagorean-triplet/pythagorean_triplet_test.py +11 -1
  163. data/tracks/python/exercises/queen-attack/README.md +15 -0
  164. data/tracks/python/exercises/queen-attack/queen_attack_test.py +17 -7
  165. data/tracks/python/exercises/rail-fence-cipher/README.md +15 -0
  166. data/tracks/python/exercises/raindrops/README.md +15 -0
  167. data/tracks/python/exercises/react/README.md +15 -1
  168. data/tracks/python/exercises/rectangles/README.md +24 -9
  169. data/tracks/python/exercises/rna-transcription/.meta/hints.md +1 -0
  170. data/tracks/python/exercises/rna-transcription/README.md +18 -5
  171. data/tracks/python/exercises/rna-transcription/rna_transcription_test.py +13 -3
  172. data/tracks/python/exercises/robot-name/README.md +15 -0
  173. data/tracks/python/exercises/robot-simulator/README.md +15 -0
  174. data/tracks/python/exercises/roman-numerals/README.md +15 -0
  175. data/tracks/python/exercises/rotational-cipher/README.md +15 -0
  176. data/tracks/python/exercises/run-length-encoding/README.md +15 -0
  177. data/tracks/python/exercises/saddle-points/README.md +15 -0
  178. data/tracks/python/exercises/saddle-points/saddle_points_test.py +11 -1
  179. data/tracks/python/exercises/say/README.md +15 -0
  180. data/tracks/python/exercises/say/say_test.py +12 -2
  181. data/tracks/python/exercises/scale-generator/README.md +15 -0
  182. data/tracks/python/exercises/scale-generator/example.py +3 -3
  183. data/tracks/python/exercises/scale-generator/scale_generator_test.py +11 -1
  184. data/tracks/python/exercises/scrabble-score/README.md +15 -0
  185. data/tracks/python/exercises/secret-handshake/README.md +16 -1
  186. data/tracks/python/exercises/series/README.md +15 -0
  187. data/tracks/python/exercises/series/series_test.py +12 -2
  188. data/tracks/python/exercises/sieve/README.md +15 -0
  189. data/tracks/python/exercises/simple-cipher/.meta/hints.md +6 -6
  190. data/tracks/python/exercises/simple-cipher/README.md +17 -1
  191. data/tracks/python/exercises/simple-cipher/simple_cipher_test.py +12 -2
  192. data/tracks/python/exercises/simple-linked-list/{hints.md → .meta/hints.md} +10 -10
  193. data/tracks/python/exercises/simple-linked-list/README.md +16 -0
  194. data/tracks/python/exercises/simple-linked-list/example.py +2 -2
  195. data/tracks/python/exercises/simple-linked-list/simple_linked_list_test.py +13 -3
  196. data/tracks/python/exercises/space-age/README.md +15 -0
  197. data/tracks/python/exercises/strain/README.md +16 -3
  198. data/tracks/python/exercises/sublist/README.md +15 -0
  199. data/tracks/python/exercises/sum-of-multiples/README.md +18 -3
  200. data/tracks/python/exercises/tournament/README.md +15 -0
  201. data/tracks/python/exercises/transpose/README.md +15 -0
  202. data/tracks/python/exercises/tree-building/README.md +30 -0
  203. data/tracks/python/exercises/tree-building/example.py +3 -5
  204. data/tracks/python/exercises/tree-building/tree_building_test.py +16 -6
  205. data/tracks/python/exercises/triangle/README.md +15 -0
  206. data/tracks/python/exercises/triangle/example.py +1 -1
  207. data/tracks/python/exercises/triangle/triangle_test.py +15 -5
  208. data/tracks/python/exercises/trinary/README.md +15 -0
  209. data/tracks/python/exercises/twelve-days/README.md +15 -0
  210. data/tracks/python/exercises/two-bucket/README.md +22 -7
  211. data/tracks/python/exercises/two-fer/README.md +16 -0
  212. data/tracks/python/exercises/variable-length-quantity/README.md +15 -0
  213. data/tracks/python/exercises/variable-length-quantity/variable_length_quantity_test.py +12 -2
  214. data/tracks/python/exercises/word-count/README.md +15 -0
  215. data/tracks/python/exercises/word-search/README.md +15 -0
  216. data/tracks/python/exercises/wordy/README.md +15 -0
  217. data/tracks/python/exercises/wordy/wordy_test.py +14 -4
  218. data/tracks/python/exercises/zebra-puzzle/README.md +15 -0
  219. data/tracks/python/exercises/zipper/README.md +16 -3
  220. data/tracks/rust/config.json +11 -0
  221. data/tracks/rust/exercises/saddle-points/.gitignore +8 -0
  222. data/tracks/rust/exercises/saddle-points/Cargo.toml +5 -0
  223. data/tracks/rust/exercises/saddle-points/README.md +66 -0
  224. data/tracks/rust/exercises/saddle-points/example.rs +24 -0
  225. data/tracks/rust/exercises/saddle-points/src/lib.rs +3 -0
  226. data/tracks/rust/exercises/saddle-points/tests/saddle-points.rs +60 -0
  227. metadata +38 -5
@@ -0,0 +1,136 @@
1
+ unit uTestISBNVerifier;
2
+
3
+ interface
4
+ uses
5
+ DUnitX.TestFramework;
6
+
7
+ type
8
+ [TestFixture]
9
+ ISBNVerifierTest = class(TObject)
10
+ public
11
+ [Test]
12
+ // [Ignore('Comment the "[Ignore]" statement to run the test')]
13
+ procedure valid_isbn_number;
14
+
15
+ [Test]
16
+ [Ignore]
17
+ procedure invalid_isbn_check_digit;
18
+
19
+ [Test]
20
+ [Ignore]
21
+ procedure valid_isbn_number_with_a_check_digit_of_10;
22
+
23
+ [Test]
24
+ [Ignore]
25
+ procedure check_digit_is_a_character_other_than_X;
26
+
27
+ [Test]
28
+ [Ignore]
29
+ procedure invalid_character_in_isbn;
30
+
31
+ [Test]
32
+ [Ignore]
33
+ procedure X_is_only_valid_as_a_check_digit;
34
+
35
+ [Test]
36
+ [Ignore]
37
+ procedure valid_isbn_without_separating_dashes;
38
+
39
+ [Test]
40
+ [Ignore]
41
+ procedure isbn_without_separating_dashes_and_X_as_check_digit;
42
+
43
+ [Test]
44
+ [Ignore]
45
+ procedure isbn_without_check_digit_and_dashes;
46
+
47
+ [Test]
48
+ [Ignore]
49
+ procedure too_long_isbn_and_no_dashes;
50
+
51
+ [Test]
52
+ [Ignore]
53
+ procedure isbn_without_check_digit;
54
+
55
+ [Test]
56
+ [Ignore]
57
+ procedure too_long_isbn;
58
+
59
+ [Test]
60
+ [Ignore]
61
+ procedure check_digit_of_X_should_not_be_used_for_0;
62
+ end;
63
+
64
+ implementation
65
+ uses uISBNVerifier;
66
+
67
+ { ISBNVerifierTest }
68
+
69
+ procedure ISBNVerifierTest.check_digit_is_a_character_other_than_X;
70
+ begin
71
+ Assert.IsFalse(TIsbn.isValid('3-598-21507-A'));
72
+ end;
73
+
74
+ procedure ISBNVerifierTest.check_digit_of_X_should_not_be_used_for_0;
75
+ begin
76
+ Assert.IsFalse(TIsbn.isValid('3-598-21515-X'));
77
+ end;
78
+
79
+ procedure ISBNVerifierTest.invalid_character_in_isbn;
80
+ begin
81
+ Assert.IsFalse(TIsbn.isValid('3-598-2K507-0'))
82
+ end;
83
+
84
+ procedure ISBNVerifierTest.invalid_isbn_check_digit;
85
+ begin
86
+ Assert.IsFalse(TIsbn.isValid('3-598-21508-9'));
87
+ end;
88
+
89
+ procedure ISBNVerifierTest.isbn_without_check_digit;
90
+ begin
91
+ Assert.IsFalse(TIsbn.isValid('3-598-21507'));
92
+ end;
93
+
94
+ procedure ISBNVerifierTest.isbn_without_check_digit_and_dashes;
95
+ begin
96
+ Assert.IsFalse(TIsbn.isValid('359821507'));
97
+ end;
98
+
99
+ procedure ISBNVerifierTest.isbn_without_separating_dashes_and_X_as_check_digit;
100
+ begin
101
+ Assert.IsTrue(TIsbn.isValid('359821507X'));
102
+ end;
103
+
104
+ procedure ISBNVerifierTest.too_long_isbn;
105
+ begin
106
+ Assert.IsFalse(TIsbn.isValid('3-598-21507-XX'));
107
+ end;
108
+
109
+ procedure ISBNVerifierTest.too_long_isbn_and_no_dashes;
110
+ begin
111
+ Assert.IsFalse(TIsbn.isValid('3598215078X'));
112
+ end;
113
+
114
+ procedure ISBNVerifierTest.valid_isbn_number;
115
+ begin
116
+ Assert.IsTrue(TIsbn.isValid('3-598-21508-8'));
117
+ end;
118
+
119
+ procedure ISBNVerifierTest.valid_isbn_number_with_a_check_digit_of_10;
120
+ begin
121
+ Assert.IsTrue(TIsbn.isValid('3-598-21507-X'));
122
+ end;
123
+
124
+ procedure ISBNVerifierTest.valid_isbn_without_separating_dashes;
125
+ begin
126
+ Assert.IsTrue(TIsbn.isValid('3598215088'));
127
+ end;
128
+
129
+ procedure ISBNVerifierTest.X_is_only_valid_as_a_check_digit;
130
+ begin
131
+ Assert.IsFalse(TIsbn.isValid('3-598-2X507-9'));
132
+ end;
133
+
134
+ initialization
135
+ TDUnitX.RegisterTestFixture(ISBNVerifierTest);
136
+ end.
@@ -0,0 +1,56 @@
1
+ # Secret Handshake
2
+
3
+ > There are 10 types of people in the world: Those who understand
4
+ > binary, and those who don't.
5
+
6
+ You and your fellow cohort of those in the "know" when it comes to
7
+ binary decide to come up with a secret "handshake".
8
+
9
+ ```text
10
+ 1 = wink
11
+ 10 = double blink
12
+ 100 = close your eyes
13
+ 1000 = jump
14
+
15
+
16
+ 10000 = Reverse the order of the operations in the secret handshake.
17
+ ```
18
+
19
+ Given a decimal number, convert it to the appropriate sequence of events for a secret handshake.
20
+
21
+ Here's a couple of examples:
22
+
23
+ Given the input 3, the function would return the array
24
+ ["wink", "double blink"] because 3 is 11 in binary.
25
+
26
+ Given the input 19, the function would return the array
27
+ ["double blink", "wink"] because 19 is 10011 in binary.
28
+ Notice that the addition of 16 (10000 in binary)
29
+ has caused the array to be reversed.
30
+
31
+ ## Testing
32
+
33
+ In order to run the tests for this track, you will need to install
34
+ DUnitX. Please see the [installation](http://www.exercism.io/languages/delphi/installation) instructions for more information.
35
+
36
+ ### Loading Exercises into Delphi
37
+
38
+ If Delphi is properly installed, and `*.dpr` file types have been associated with Delphi, then double clicking the supplied `*.dpr` file will start Delphi and load the exercise/project. `control + F9` is the keyboard shortcut to compile the project or pressing `F9` will compile and run the project.
39
+
40
+ Alternatively you may opt to start Delphi and load your project via. the `File` drop down menu.
41
+
42
+ ### When Questions Come Up
43
+ We monitor the [Pascal-Delphi](https://gitter.im/exercism/Pascal-Delphi) support room on [gitter.im](https://gitter.im) to help you with any questions that might arise.
44
+
45
+ ### Submitting Exercises
46
+
47
+ Note that, when trying to submit an exercise, make sure the exercise file you're submitting is in the `exercism/delphi/<exerciseName>` directory.
48
+
49
+ For example, if you're submitting `ubob.pas` for the Bob exercise, the submit command would be something like `exercism submit <path_to_exercism_dir>/delphi/bob/ubob.pas`.
50
+
51
+ ## Source
52
+
53
+ Bert, in Mary Poppins [http://www.imdb.com/title/tt0058331/quotes/qt0437047](http://www.imdb.com/title/tt0058331/quotes/qt0437047)
54
+
55
+ ## Submitting Incomplete Solutions
56
+ It's possible to submit an incomplete solution so you can see how others have completed the exercise.
@@ -0,0 +1,60 @@
1
+ program SecretHandshake;
2
+
3
+ {$IFNDEF TESTINSIGHT}
4
+ {$APPTYPE CONSOLE}
5
+ {$ENDIF}{$STRONGLINKTYPES ON}
6
+ uses
7
+ System.SysUtils,
8
+ {$IFDEF TESTINSIGHT}
9
+ TestInsight.DUnitX,
10
+ {$ENDIF }
11
+ DUnitX.Loggers.Console,
12
+ DUnitX.Loggers.Xml.NUnit,
13
+ DUnitX.TestFramework,
14
+ uSecretHandshake in 'uSecretHandshake.pas',
15
+ uTestSecretHandshake in 'uTestSecretHandshake.pas';
16
+
17
+ var
18
+ runner : ITestRunner;
19
+ results : IRunResults;
20
+ logger : ITestLogger;
21
+ nunitLogger : ITestLogger;
22
+ begin
23
+ {$IFDEF TESTINSIGHT}
24
+ TestInsight.DUnitX.RunRegisteredTests;
25
+ exit;
26
+ {$ENDIF}
27
+ try
28
+ //Check command line options, will exit if invalid
29
+ TDUnitX.CheckCommandLine;
30
+ //Create the test runner
31
+ runner := TDUnitX.CreateRunner;
32
+ //Tell the runner to use RTTI to find Fixtures
33
+ runner.UseRTTI := True;
34
+ //tell the runner how we will log things
35
+ //Log to the console window
36
+ logger := TDUnitXConsoleLogger.Create(true);
37
+ runner.AddLogger(logger);
38
+ //Generate an NUnit compatible XML File
39
+ nunitLogger := TDUnitXXMLNUnitFileLogger.Create(TDUnitX.Options.XMLOutputFile);
40
+ runner.AddLogger(nunitLogger);
41
+ runner.FailsOnNoAsserts := False; //When true, Assertions must be made during tests;
42
+
43
+ //Run tests
44
+ results := runner.Execute;
45
+ if not results.AllPassed then
46
+ System.ExitCode := EXIT_ERRORS;
47
+
48
+ {$IFNDEF CI}
49
+ //We don't want this happening when running under CI.
50
+ if TDUnitX.Options.ExitBehavior = TDUnitXExitBehavior.Pause then
51
+ begin
52
+ System.Write('Done.. press <Enter> key to quit.');
53
+ System.Readln;
54
+ end;
55
+ {$ENDIF}
56
+ except
57
+ on E: Exception do
58
+ System.Writeln(E.ClassName, ': ', E.Message);
59
+ end;
60
+ end.
@@ -0,0 +1,56 @@
1
+ unit uSecretHandshake;
2
+
3
+ interface
4
+ uses Generics.Collections;
5
+
6
+ type
7
+ TSecretHandshake = class
8
+ private
9
+ class var CommandValues: TList<TPair<integer, string>>;
10
+ class procedure BuildCommandValues;
11
+ class function ShouldReverse(aCommandValue: integer): Boolean;
12
+ public
13
+ class function commands(aInput: integer): TArray<string>;
14
+ end;
15
+
16
+ implementation
17
+ uses SysUtils;
18
+
19
+ { TSecretHandshake }
20
+
21
+ class procedure TSecretHandshake.BuildCommandValues;
22
+ begin
23
+ if not assigned(CommandValues) then
24
+ begin
25
+ CommandValues := TList<TPair<integer, string>>.Create;
26
+ CommandValues.Add(TPair<integer,string>.Create(1, 'wink'));
27
+ CommandValues.Add(TPair<integer,string>.Create(2, 'double blink'));
28
+ CommandValues.Add(TPair<integer,string>.Create(4, 'close your eyes'));
29
+ CommandValues.Add(TPair<integer,string>.Create(8, 'jump'));
30
+ end;
31
+ end;
32
+
33
+ class function TSecretHandshake.commands(aInput: integer): TArray<string>;
34
+ var lCommands: TList<string>;
35
+ lKeyValue: TPair<integer,string>;
36
+ begin
37
+ BuildCommandValues;
38
+ lCommands := TList<string>.Create;
39
+
40
+ for lKeyValue in CommandValues do
41
+ begin
42
+ if aInput and lKeyValue.Key <> 0 then
43
+ lCommands.Add(lKeyValue.Value);
44
+ end;
45
+
46
+ if ShouldReverse(aInput) then
47
+ lCommands.Reverse;
48
+ result := lCommands.ToArray;
49
+ end;
50
+
51
+ class function TSecretHandshake.ShouldReverse(aCommandValue: integer): Boolean;
52
+ begin
53
+ result := (aCommandValue and 16) <> 0;
54
+ end;
55
+
56
+ end.
@@ -0,0 +1,215 @@
1
+ unit uTestSecretHandshake;
2
+
3
+ interface
4
+ uses
5
+ DUnitX.TestFramework;
6
+
7
+ const
8
+ CanonicalVersion = '1.1.0';
9
+
10
+ type
11
+ [TestFixture]
12
+ SecretHandshakeTest = class(TObject)
13
+ private
14
+ procedure CompareArrays(aExpected, aActual: TArray<string>);
15
+ public
16
+ [Test]
17
+ // [Ignore('Comment the "[Ignore]" statement to run the test')]
18
+ procedure wink_for_1;
19
+
20
+ [Test]
21
+ [Ignore]
22
+ procedure double_blink_for_10;
23
+
24
+ [Test]
25
+ [Ignore]
26
+ procedure close_your_eyes_for_100;
27
+
28
+ [Test]
29
+ [Ignore]
30
+ procedure jump_for_1000;
31
+
32
+ [Test]
33
+ [Ignore]
34
+ procedure combine_two_actions;
35
+
36
+ [Test]
37
+ [Ignore]
38
+ procedure reverse_two_actions;
39
+
40
+ [Test]
41
+ [Ignore]
42
+ procedure reversing_one_action_gives_the_same_action;
43
+
44
+ [Test]
45
+ [Ignore]
46
+ procedure reversing_no_actions_still_gives_no_actions;
47
+
48
+ [Test]
49
+ [Ignore]
50
+ procedure all_possible_actions;
51
+
52
+ [Test]
53
+ [Ignore]
54
+ procedure reverse_all_possible_actions;
55
+
56
+ [Test]
57
+ [Ignore]
58
+ procedure do_nothing_for_zero;
59
+ end;
60
+
61
+ implementation
62
+ uses uSecretHandshake;
63
+
64
+
65
+ { SecretHandshakeTest }
66
+
67
+ procedure SecretHandshakeTest.all_possible_actions;
68
+ var Expected,
69
+ Actual: TArray<string>;
70
+ begin
71
+ SetLength(Expected, 4);
72
+ Expected[0] := 'wink';
73
+ Expected[1] := 'double blink';
74
+ Expected[2] := 'close your eyes';
75
+ Expected[3] := 'jump';
76
+
77
+ Actual := TSecretHandshake.commands(15);
78
+
79
+ CompareArrays(Expected, Actual);
80
+ end;
81
+
82
+ procedure SecretHandshakeTest.close_your_eyes_for_100;
83
+ var Expected,
84
+ Actual: TArray<string>;
85
+ begin
86
+ SetLength(Expected, 1);
87
+ Expected[0] := 'close your eyes';
88
+
89
+ Actual := TSecretHandshake.commands(4);
90
+
91
+ CompareArrays(Expected, Actual);
92
+ end;
93
+
94
+ procedure SecretHandshakeTest.combine_two_actions;
95
+ var Expected,
96
+ Actual: TArray<string>;
97
+ begin
98
+ SetLength(Expected, 2);
99
+ Expected[0] := 'wink';
100
+ Expected[1] := 'double blink';
101
+
102
+ Actual := TSecretHandshake.commands(3);
103
+
104
+ CompareArrays(Expected, Actual);
105
+ end;
106
+
107
+ procedure SecretHandshakeTest.double_blink_for_10;
108
+ var Expected,
109
+ Actual: TArray<string>;
110
+ begin
111
+ SetLength(Expected, 1);
112
+ Expected[0] := 'double blink';
113
+
114
+ Actual := TSecretHandshake.commands(2);
115
+
116
+ CompareArrays(Expected, Actual);
117
+ end;
118
+
119
+ procedure SecretHandshakeTest.do_nothing_for_zero;
120
+ var Expected,
121
+ Actual: TArray<string>;
122
+ begin
123
+ SetLength(Expected, 0);
124
+
125
+ Actual := TSecretHandshake.commands(0);
126
+
127
+ CompareArrays(Expected, Actual);
128
+ end;
129
+
130
+ procedure SecretHandshakeTest.jump_for_1000;
131
+ var Expected,
132
+ Actual: TArray<string>;
133
+ begin
134
+ SetLength(Expected, 1);
135
+ Expected[0] := 'jump';
136
+
137
+ Actual := TSecretHandshake.commands(8);
138
+
139
+ CompareArrays(Expected, Actual);
140
+ end;
141
+
142
+ procedure SecretHandshakeTest.reverse_all_possible_actions;
143
+ var Expected,
144
+ Actual: TArray<string>;
145
+ begin
146
+ SetLength(Expected, 4);
147
+ Expected[0] := 'jump';
148
+ Expected[1] := 'close your eyes';
149
+ Expected[2] := 'double blink';
150
+ Expected[3] := 'wink';
151
+
152
+ Actual := TSecretHandshake.commands(31);
153
+
154
+ CompareArrays(Expected, Actual);
155
+ end;
156
+
157
+ procedure SecretHandshakeTest.reverse_two_actions;
158
+ var Expected,
159
+ Actual: TArray<string>;
160
+ begin
161
+ SetLength(Expected, 2);
162
+ Expected[0] := 'double blink';
163
+ Expected[1] := 'wink';
164
+
165
+ Actual := TSecretHandshake.commands(19);
166
+
167
+ CompareArrays(Expected, Actual);
168
+ end;
169
+
170
+ procedure SecretHandshakeTest.reversing_no_actions_still_gives_no_actions;
171
+ var Expected,
172
+ Actual: TArray<string>;
173
+ begin
174
+ SetLength(Expected, 0);
175
+
176
+ Actual := TSecretHandshake.commands(16);
177
+
178
+ CompareArrays(Expected, Actual);
179
+ end;
180
+
181
+ procedure SecretHandshakeTest.reversing_one_action_gives_the_same_action;
182
+ var Expected,
183
+ Actual: TArray<string>;
184
+ begin
185
+ SetLength(Expected, 1);
186
+ Expected[0] := 'jump';
187
+
188
+ Actual := TSecretHandshake.commands(24);
189
+
190
+ CompareArrays(Expected, Actual);
191
+ end;
192
+
193
+ procedure SecretHandshakeTest.wink_for_1;
194
+ var Expected,
195
+ Actual: TArray<string>;
196
+ begin
197
+ SetLength(Expected, 1);
198
+ Expected[0] := 'wink';
199
+
200
+ Actual := TSecretHandshake.commands(1);
201
+
202
+ CompareArrays(Expected, Actual);
203
+ end;
204
+
205
+ procedure SecretHandshakeTest.CompareArrays(aExpected, aActual: TArray<string>);
206
+ var i: integer;
207
+ begin
208
+ Assert.AreEqual(length(aExpected), length(aActual));
209
+ for i := Low(aExpected) to High(aExpected) do
210
+ Assert.AreEqual(aExpected[i], aActual[i]);
211
+ end;
212
+
213
+ initialization
214
+ TDUnitX.RegisterTestFixture(SecretHandshakeTest);
215
+ end.