trackler 2.2.1.135 → 2.2.1.136

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/lib/trackler/version.rb +1 -1
  3. data/problem-specifications/exercises/pov/canonical-data.json +33 -1
  4. data/tracks/c/exercises/acronym/test/test_acronym.c +25 -17
  5. data/tracks/csharp/exercises/binary-search-tree/BinarySearchTreeTest.cs +37 -28
  6. data/tracks/csharp/generators/Exercises/BinarySearchTree.cs +69 -0
  7. data/tracks/haskell/config.json +1 -0
  8. data/tracks/haskell/exercises/accumulate/package.yaml +1 -1
  9. data/tracks/haskell/exercises/acronym/package.yaml +1 -1
  10. data/tracks/haskell/exercises/all-your-base/package.yaml +1 -1
  11. data/tracks/haskell/exercises/allergies/package.yaml +1 -1
  12. data/tracks/haskell/exercises/alphametics/package.yaml +1 -1
  13. data/tracks/haskell/exercises/anagram/package.yaml +1 -1
  14. data/tracks/haskell/exercises/atbash-cipher/package.yaml +1 -1
  15. data/tracks/haskell/exercises/bank-account/package.yaml +1 -1
  16. data/tracks/haskell/exercises/beer-song/package.yaml +1 -1
  17. data/tracks/haskell/exercises/binary-search-tree/package.yaml +1 -1
  18. data/tracks/haskell/exercises/binary/package.yaml +1 -1
  19. data/tracks/haskell/exercises/bob/package.yaml +1 -1
  20. data/tracks/haskell/exercises/bowling/package.yaml +1 -1
  21. data/tracks/haskell/exercises/bracket-push/package.yaml +1 -1
  22. data/tracks/haskell/exercises/change/package.yaml +1 -1
  23. data/tracks/haskell/exercises/clock/package.yaml +1 -1
  24. data/tracks/haskell/exercises/collatz-conjecture/package.yaml +1 -1
  25. data/tracks/haskell/exercises/complex-numbers/package.yaml +1 -1
  26. data/tracks/haskell/exercises/connect/package.yaml +1 -1
  27. data/tracks/haskell/exercises/crypto-square/package.yaml +1 -1
  28. data/tracks/haskell/exercises/custom-set/package.yaml +1 -1
  29. data/tracks/haskell/exercises/diamond/package.yaml +1 -1
  30. data/tracks/haskell/exercises/difference-of-squares/package.yaml +1 -1
  31. data/tracks/haskell/exercises/dominoes/package.yaml +1 -1
  32. data/tracks/haskell/exercises/etl/package.yaml +1 -1
  33. data/tracks/haskell/exercises/food-chain/package.yaml +1 -1
  34. data/tracks/haskell/exercises/forth/package.yaml +1 -1
  35. data/tracks/haskell/exercises/gigasecond/package.yaml +1 -1
  36. data/tracks/haskell/exercises/go-counting/package.yaml +1 -1
  37. data/tracks/haskell/exercises/grade-school/package.yaml +1 -1
  38. data/tracks/haskell/exercises/grains/package.yaml +1 -1
  39. data/tracks/haskell/exercises/hamming/package.yaml +1 -1
  40. data/tracks/haskell/exercises/hello-world/package.yaml +1 -1
  41. data/tracks/haskell/exercises/hexadecimal/package.yaml +1 -1
  42. data/tracks/haskell/exercises/house/package.yaml +1 -1
  43. data/tracks/haskell/exercises/isbn-verifier/package.yaml +1 -1
  44. data/tracks/haskell/exercises/isogram/package.yaml +1 -1
  45. data/tracks/haskell/exercises/kindergarten-garden/examples/success-standard/src/Garden.hs +1 -10
  46. data/tracks/haskell/exercises/kindergarten-garden/package.yaml +2 -3
  47. data/tracks/haskell/exercises/kindergarten-garden/src/Garden.hs +3 -7
  48. data/tracks/haskell/exercises/kindergarten-garden/test/Tests.hs +10 -16
  49. data/tracks/haskell/exercises/largest-series-product/package.yaml +1 -1
  50. data/tracks/haskell/exercises/leap/package.yaml +1 -1
  51. data/tracks/haskell/exercises/lens-person/examples/success-standard/package.yaml +0 -1
  52. data/tracks/haskell/exercises/lens-person/package.yaml +1 -1
  53. data/tracks/haskell/exercises/linked-list/package.yaml +1 -1
  54. data/tracks/haskell/exercises/list-ops/package.yaml +1 -1
  55. data/tracks/haskell/exercises/luhn/package.yaml +1 -1
  56. data/tracks/haskell/exercises/matrix/package.yaml +1 -1
  57. data/tracks/haskell/exercises/meetup/package.yaml +1 -1
  58. data/tracks/haskell/exercises/minesweeper/package.yaml +1 -1
  59. data/tracks/haskell/exercises/nth-prime/package.yaml +1 -1
  60. data/tracks/haskell/exercises/nucleotide-count/package.yaml +1 -1
  61. data/tracks/haskell/exercises/ocr-numbers/package.yaml +1 -1
  62. data/tracks/haskell/exercises/octal/package.yaml +1 -1
  63. data/tracks/haskell/exercises/palindrome-products/package.yaml +1 -1
  64. data/tracks/haskell/exercises/pangram/package.yaml +1 -1
  65. data/tracks/haskell/exercises/parallel-letter-frequency/package.yaml +1 -1
  66. data/tracks/haskell/exercises/pascals-triangle/package.yaml +1 -1
  67. data/tracks/haskell/exercises/perfect-numbers/package.yaml +1 -1
  68. data/tracks/haskell/exercises/phone-number/package.yaml +1 -1
  69. data/tracks/haskell/exercises/pig-latin/package.yaml +1 -1
  70. data/tracks/haskell/exercises/poker/package.yaml +1 -1
  71. data/tracks/haskell/exercises/pov/package.yaml +2 -2
  72. data/tracks/haskell/exercises/pov/test/Tests.hs +15 -0
  73. data/tracks/haskell/exercises/prime-factors/package.yaml +1 -1
  74. data/tracks/haskell/exercises/protein-translation/package.yaml +1 -1
  75. data/tracks/haskell/exercises/pythagorean-triplet/package.yaml +1 -1
  76. data/tracks/haskell/exercises/queen-attack/package.yaml +1 -1
  77. data/tracks/haskell/exercises/rail-fence-cipher/package.yaml +1 -1
  78. data/tracks/haskell/exercises/raindrops/package.yaml +1 -1
  79. data/tracks/haskell/exercises/rna-transcription/package.yaml +1 -1
  80. data/tracks/haskell/exercises/robot-name/package.yaml +1 -1
  81. data/tracks/haskell/exercises/robot-simulator/package.yaml +1 -1
  82. data/tracks/haskell/exercises/roman-numerals/package.yaml +1 -1
  83. data/tracks/haskell/exercises/rotational-cipher/package.yaml +1 -1
  84. data/tracks/haskell/exercises/run-length-encoding/package.yaml +1 -1
  85. data/tracks/haskell/exercises/saddle-points/package.yaml +1 -1
  86. data/tracks/haskell/exercises/say/package.yaml +1 -1
  87. data/tracks/haskell/exercises/scrabble-score/package.yaml +1 -1
  88. data/tracks/haskell/exercises/secret-handshake/package.yaml +1 -1
  89. data/tracks/haskell/exercises/series/package.yaml +1 -1
  90. data/tracks/haskell/exercises/sgf-parsing/package.yaml +1 -1
  91. data/tracks/haskell/exercises/sieve/package.yaml +1 -1
  92. data/tracks/haskell/exercises/simple-cipher/package.yaml +1 -1
  93. data/tracks/haskell/exercises/simple-linked-list/package.yaml +1 -1
  94. data/tracks/haskell/exercises/space-age/package.yaml +1 -1
  95. data/tracks/haskell/exercises/spiral-matrix/package.yaml +1 -1
  96. data/tracks/haskell/exercises/strain/package.yaml +1 -1
  97. data/tracks/haskell/exercises/sublist/package.yaml +1 -1
  98. data/tracks/haskell/exercises/sum-of-multiples/package.yaml +1 -1
  99. data/tracks/haskell/exercises/transpose/package.yaml +1 -1
  100. data/tracks/haskell/exercises/triangle/package.yaml +1 -1
  101. data/tracks/haskell/exercises/trinary/package.yaml +1 -1
  102. data/tracks/haskell/exercises/twelve-days/package.yaml +1 -1
  103. data/tracks/haskell/exercises/word-count/package.yaml +1 -1
  104. data/tracks/haskell/exercises/wordy/package.yaml +1 -1
  105. data/tracks/haskell/exercises/zebra-puzzle/package.yaml +1 -1
  106. data/tracks/haskell/exercises/zipper/package.yaml +1 -1
  107. data/tracks/java/CONTRIBUTING.md +39 -3
  108. data/tracks/java/POLICIES.md +68 -3
  109. data/tracks/java/exercises/crypto-square/README.md +4 -5
  110. data/tracks/java/exercises/error-handling/README.md +38 -0
  111. data/tracks/java/exercises/series/README.md +6 -6
  112. data/tracks/java/exercises/sieve/README.md +5 -3
  113. data/tracks/java/scripts/canonical_data_check.sh +1 -1
  114. data/tracks/python/exercises/react/example.py +54 -63
  115. data/tracks/python/exercises/react/react.py +10 -10
  116. data/tracks/python/exercises/react/react_test.py +197 -131
  117. data/tracks/python/exercises/sieve/README.md +5 -3
  118. data/tracks/rust/exercises/react/example.rs +103 -64
  119. data/tracks/rust/exercises/react/src/lib.rs +31 -17
  120. data/tracks/rust/exercises/react/tests/react.rs +52 -61
  121. data/tracks/swift/config.json +11 -0
  122. data/tracks/swift/exercises/circular-buffer/Sources/CircularBufferExample.swift +12 -12
  123. data/tracks/swift/exercises/circular-buffer/Tests/CircularBufferTests/CircularBufferTests.swift +1 -1
  124. data/tracks/swift/exercises/proverb/Package.swift +5 -0
  125. data/tracks/swift/exercises/proverb/README.md +25 -0
  126. data/tracks/swift/exercises/proverb/Sources/Proverb.swift +1 -0
  127. data/tracks/swift/exercises/proverb/Sources/ProverbExample.swift +28 -0
  128. data/tracks/swift/exercises/proverb/Tests/LinuxMain.swift +6 -0
  129. data/tracks/swift/exercises/proverb/Tests/ProverbTests/ProverbTests.swift +61 -0
  130. data/tracks/typescript/config.json +14 -0
  131. data/tracks/typescript/exercises/palindrome-products/README.md +65 -0
  132. data/tracks/typescript/exercises/palindrome-products/package.json +36 -0
  133. data/tracks/typescript/exercises/palindrome-products/palindrome-products.example.ts +38 -0
  134. data/tracks/typescript/exercises/palindrome-products/palindrome-products.test.ts +69 -0
  135. data/tracks/typescript/exercises/palindrome-products/palindrome-products.ts +0 -0
  136. data/tracks/typescript/exercises/palindrome-products/tsconfig.json +22 -0
  137. data/tracks/typescript/exercises/palindrome-products/tslint.json +127 -0
  138. data/tracks/typescript/exercises/palindrome-products/yarn.lock +2624 -0
  139. metadata +17 -2
@@ -7,7 +7,7 @@ dependencies:
7
7
  library:
8
8
  exposed-modules: SumOfMultiples
9
9
  source-dirs: src
10
- dependencies:
10
+ # dependencies:
11
11
  # - foo # List here the packages you
12
12
  # - bar # want to use in your solution.
13
13
 
@@ -7,7 +7,7 @@ dependencies:
7
7
  library:
8
8
  exposed-modules: Transpose
9
9
  source-dirs: src
10
- dependencies:
10
+ # dependencies:
11
11
  # - foo # List here the packages you
12
12
  # - bar # want to use in your solution.
13
13
 
@@ -7,7 +7,7 @@ dependencies:
7
7
  library:
8
8
  exposed-modules: Triangle
9
9
  source-dirs: src
10
- dependencies:
10
+ # dependencies:
11
11
  # - foo # List here the packages you
12
12
  # - bar # want to use in your solution.
13
13
 
@@ -7,7 +7,7 @@ dependencies:
7
7
  library:
8
8
  exposed-modules: Trinary
9
9
  source-dirs: src
10
- dependencies:
10
+ # dependencies:
11
11
  # - foo # List here the packages you
12
12
  # - bar # want to use in your solution.
13
13
 
@@ -7,7 +7,7 @@ dependencies:
7
7
  library:
8
8
  exposed-modules: TwelveDays
9
9
  source-dirs: src
10
- dependencies:
10
+ # dependencies:
11
11
  # - foo # List here the packages you
12
12
  # - bar # want to use in your solution.
13
13
 
@@ -7,7 +7,7 @@ dependencies:
7
7
  library:
8
8
  exposed-modules: WordCount
9
9
  source-dirs: src
10
- dependencies:
10
+ # dependencies:
11
11
  # - foo # List here the packages you
12
12
  # - bar # want to use in your solution.
13
13
 
@@ -7,7 +7,7 @@ dependencies:
7
7
  library:
8
8
  exposed-modules: WordProblem
9
9
  source-dirs: src
10
- dependencies:
10
+ # dependencies:
11
11
  # - foo # List here the packages you
12
12
  # - bar # want to use in your solution.
13
13
 
@@ -7,7 +7,7 @@ dependencies:
7
7
  library:
8
8
  exposed-modules: ZebraPuzzle
9
9
  source-dirs: src
10
- dependencies:
10
+ # dependencies:
11
11
  # - foo # List here the packages you
12
12
  # - bar # want to use in your solution.
13
13
 
@@ -7,7 +7,7 @@ dependencies:
7
7
  library:
8
8
  exposed-modules: Zipper
9
9
  source-dirs: src
10
- dependencies:
10
+ # dependencies:
11
11
  # - foo # List here the packages you
12
12
  # - bar # want to use in your solution.
13
13
 
@@ -9,6 +9,8 @@
9
9
  * [Advanced: Complete Local Setup](#advanced-complete-local-setup)
10
10
  * [Tip: `gradle clean` before `exercism fetch`](#tip-gradle-clean-before-exercism-fetch)
11
11
  * [Adding a New Exercise](#adding-a-new-exercise)
12
+ * [Updating the READMEs](#updating-the-readmes)
13
+ * [Checking tests are up to date](#checking-tests-are-up-to-date)
12
14
 
13
15
  ## Overview
14
16
 
@@ -145,10 +147,12 @@ Any completely new exercise needs to be added and accepted there before it can b
145
147
 
146
148
  There is a [general Exercism guide for porting an exercise to a new language](https://github.com/exercism/docs/blob/master/you-can-help/implement-an-exercise-from-specification.md).
147
149
  Please review this before porting an exercise to the Java track.
148
-
150
+
149
151
  See [here](http://exercism.io/languages/java/todo) for a list of exercises that have yet to be implemented on the Java track and can therefore be ported to this track.
150
152
  Please make sure no one else has a pull request open to implement your chosen exercise before you start.
151
- Also please make a [dibs pull request](https://github.com/exercism/docs/blob/master/you-can-help/implement-an-exercise-from-specification.md#avoiding-duplicate-work) to make it clear to others that you are working on this exercise.
153
+
154
+ It might also be a good idea to open a WIP pull request to make it clear to others that you are working on this exercise.
155
+ This can just be a pull request with an empty commit that states which new exercise you're working on, with WIP (work in progress) in the title so that the maintainers know that it's not ready for review yet.
152
156
 
153
157
  The Java specific details you need to know about adding an exercise are:
154
158
 
@@ -166,7 +170,7 @@ The `build.gradle` file can just be copied from any other exercise submodule.
166
170
  The `README.md` file can be generated using [configlet](https://github.com/exercism/configlet/releases).
167
171
  You can do this by:
168
172
 
169
- 1. Download configlet and put it somewhere in your PATH
173
+ 1. Download configlet and put it somewhere in your [PATH](https://en.wikipedia.org/wiki/PATH_(variable))
170
174
 
171
175
  2. Clone [the problem-specifications repository](https://github.com/exercism/problem-specifications).
172
176
 
@@ -180,5 +184,37 @@ If there is canonical data available you also need to create a file at `exercise
180
184
  The canonical data version can be found at the top of the canonical data file for that exercise.
181
185
  See other exercises, e.g. [acronym](https://github.com/exercism/java/tree/master/exercises/acronym/.meta), for an example `version` file.
182
186
 
187
+ * Make sure you've followed the [track policies](https://github.com/exercism/java/blob/master/POLICIES.md), especially the ones for exercise added/updated.
188
+
183
189
  Hopefully that should be enough information to help you port an exercise to the Java track.
184
190
  Feel free to open an issue or post in the [Gitter exercism/java room](https://gitter.im/exercism/java) if you have any questions and we'll try and answer as soon as we can.
191
+
192
+ ## Updating the READMEs
193
+
194
+ The `README.md` files are generated from the exercise descriptions in [problem specifications](https://github.com/exercism/problem-specifications/tree/master/exercises).
195
+ They need to be regenerated regularly so that any changes to the descriptions in problem specifications propagate to our READMEs.
196
+ This can be done using [configlet](https://github.com/exercism/configlet/releases):
197
+
198
+ 1. Download configlet and put it somewhere in your [PATH](https://en.wikipedia.org/wiki/PATH_(variable))
199
+
200
+ 2. Clone [the problem-specifications repository](https://github.com/exercism/problem-specifications).
201
+
202
+ 3. Run `configlet generate . --spec-path path_to_problem_specifications` from the root of this repository.
203
+
204
+ ## Checking tests are up to date
205
+
206
+ The tests for each exercise should follow the canonical data in [problem specifications](https://github.com/exercism/problem-specifications/tree/master/exercises) as closely as possible.
207
+ The canonical data can change quite regularly, in which case the [canonical data version](https://github.com/exercism/problem-specifications#test-data-versioning) for that exercise will be updated.
208
+
209
+ We keep track of which version of the canonical data each exercise implements in a version file, for example: https://github.com/exercism/java/blob/master/exercises/two-fer/.meta/version.
210
+ Not all exercises have canonical data in problem specifications.
211
+ For those that don't we don't add a version file.
212
+
213
+ We have [a script](https://github.com/exercism/java/blob/master/scripts/canonical_data_check.sh) which can check if these version are up to date with the ones in problem specification.
214
+ This script can be used to check if any version files, tests and reference implementations need updating.
215
+
216
+ To run this script:
217
+
218
+ 1. Clone [the problem-specifications repository](https://github.com/exercism/problem-specifications).
219
+
220
+ 2. Run `./scripts/canonical_data_check.sh -t . -s --spec-path path_to_problem_specifications` from the root of this repository.
@@ -17,7 +17,7 @@ Our policies are not set-in-stone. They represent directions chosen at a point i
17
17
 
18
18
  | Track Event | Policies to review |
19
19
  |:------------|:-----------------|
20
- | Exercise added/updated | [Prefer instance methods](#prefer-instance-methods); [Avoid using final](#avoid-using-final); [Adhere to best practices](#adhere-to-best-practices); [Starter implementations](#starter-implementations); [Ignore noninitial tests](#ignore-noninitial-tests); [Multiple file submissions](#multiple-file-submissions); [Name test class after class under test](#name-test-class-after-class-under-test); [Add hint for the first exercises without starter implementation](#add-hint-for-the-first-exercises-without-starter-implementation)
20
+ | Exercise added/updated | [Prefer instance methods](#prefer-instance-methods); [Avoid using final](#avoid-using-final); [Adhere to best practices](#adhere-to-best-practices); [Starter implementations](#starter-implementations); [Ignore noninitial tests](#ignore-noninitial-tests); [Multiple file submissions](#multiple-file-submissions); [Name test class after class under test](#name-test-class-after-class-under-test); [Add hint for the first exercises without starter implementation](#add-hint-for-the-first-exercises-without-starter-implementation); [Reference tutorial in the first exercises](#reference-tutorial-in-the-first-exercises); [Avoid returning null](#avoid-returning-null); [Use ExpectedException](#use-expectedexception)
21
21
  | Track rearranged | [Starter implementations](#starter-implementations); [Multiple file submissions](#multiple-file-submissions) |
22
22
  | New issue observed in track | [Good first patches](#good-first-patches) |
23
23
  | "Good first patch" issue completed | [Good first patches](#good-first-patches) |
@@ -46,7 +46,33 @@ References: [[1](https://github.com/exercism/java/issues/178)], [[2](https://git
46
46
  ### Adhere to best practices
47
47
 
48
48
  > Ensure that all Java code adheres to the best practices listed below:
49
- > - minimize the accessibility of classes and members ([Effective Java, item 13](http://jtechies.blogspot.com/2012/07/item-13-minimize-accessibility-of.html))
49
+ > - Minimize the accessibility of classes and members ([Effective Java, item 13](http://jtechies.blogspot.com/2012/07/item-13-minimize-accessibility-of.html))
50
+ > - Always use curly brackest in if statements. This makes your code easier to maintain and easier to read ([Oracle style guide, item 7.4](http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-142311.html#431))
51
+ ```java
52
+ // Please do this
53
+ if (condition) {
54
+ doSomething();
55
+ }
56
+
57
+ // Please don't do this
58
+ if (condition)
59
+ doSomething();
60
+
61
+ if (condition) doSomething();
62
+ ```
63
+ > - Always put opening curly bracket not on a newline ([Oracle style guide, item 7.2](http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-142311.html#431))
64
+ ```java
65
+ // Please do this
66
+ for (int i = 0; i < 10; i++) {
67
+ ...
68
+ }
69
+
70
+ // Please don't do this
71
+ for (int i = 0; i < 10; i++)
72
+ {
73
+ ...
74
+ }
75
+ ```
50
76
 
51
77
  ### Ignore noninitial tests
52
78
 
@@ -74,7 +100,7 @@ References: [[1](https://github.com/exercism/java/issues/395#issue-215734887)]
74
100
 
75
101
  ### Name test class after class under test
76
102
 
77
- > If you're testing a class called `SomeClassName` then your test class should be called `SomeClassNameTest`.
103
+ > If you're testing a class called `SomeClassName` then your test class should be called `SomeClassNameTest`.
78
104
 
79
105
  > The exception to this is if the tests are split into several test classes where each test class tests different functionality. In that case each class should be named `SomeClassNameFunctionalityTest` where `Functionality` is the name of the functionality to be tested in that class. See the [clock exercise](https://github.com/exercism/java/tree/master/exercises/clock) as an example.
80
106
 
@@ -93,3 +119,42 @@ References: [[1](https://github.com/exercism/java/issues/697)]
93
119
  > We add the file to every exercise with difficulty 5 because the structure of the track means that we don't know which exercise will be the first one without starter implementation that a user will be faced with.
94
120
 
95
121
  References: [[1](https://github.com/exercism/java/issues/1075)]
122
+
123
+ ### Reference tutorial in the first exercises
124
+
125
+ > The hello world exercise has an extensive tutorial on how to solve exercism exercises.
126
+ > This tutorial would probably be useful to have as a reference when solving some of the other earlier exercises as well.
127
+ > Therefore any exercise with difficulty less than 3 should have a hints.md file which references [the hello world tutorial](https://github.com/exercism/java/blob/master/exercises/hello-world/TUTORIAL.md).
128
+
129
+ References: [[1](https://github.com/exercism/java/issues/1389)]
130
+
131
+ ### Avoid returning null
132
+
133
+ > The [canonical data](https://github.com/exercism/problem-specifications/tree/master/exercises) for each exercise intentionally doesn't deal with error handling.
134
+ > When an error has occured or a method can't return anything, the canonical data will just mark that as `"expected": null`.
135
+ > This is because error handling varies from language to language, so the canonical data is leaving it up to each language track to decide how to deal with those situations.
136
+ > It doesn't mean that the method needs to return `null`.
137
+
138
+ > In Java it's considered bad practice to return `null`.
139
+ > If you return `null` then the user of the method has to remember to check for `null` and they have to look at the implementation of the method to find out that this is necessary.
140
+
141
+ > It's considered best practice to deal with errors and unexpected circumstances by throwing exceptions.
142
+ > If you throw an exception then you force the user to deal with the problem.
143
+ > You can either define your own exception (see [the triangle exercise](https://github.com/exercism/java/blob/master/exercises/triangle/.meta/src/reference/java/TriangleException.java) for an example) or use a predefined one (see [the collatz-conjecture exercise](https://github.com/exercism/java/blob/master/exercises/collatz-conjecture/src/test/java/CollatzCalculatorTest.java) for an example).
144
+
145
+ > Another option is to use [Optionals](https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html).
146
+ > This can be more suitable if the case you want to deal with isn't an exceptional occurence, but rather an expected scenario, e.g. a search method not finding what it was searching for.
147
+ > See [the word-search exercise](https://github.com/exercism/java/blob/master/exercises/word-search/src/test/java/WordSearcherTest.java) for an example where `Optional` is used.
148
+
149
+ References: [[1](https://www.codebyamir.com/blog/stop-returning-null-in-java)]
150
+
151
+ ### Use ExceptedException
152
+
153
+ > Some exercises expect exceptions to be thrown in the tests.
154
+ > The exercises on this track are all using JUnit's [`ExpectedException`](http://junit.org/junit4/javadoc/4.12/org/junit/rules/ExpectedException.html) `@Rule` feature to support that instead of `@Test(expected = SomeException.class)`.
155
+ > `ExpectedException` is more powerful than using the `@Test` annotation, since with `ExpectedException` you can also inspect the exception's error message and other properties.
156
+ > To be consistent, please use `ExpectedException` whenever you expect an exception to be thrown.
157
+
158
+ > See [the triangle tests](https://github.com/exercism/java/blob/master/exercises/triangle/src/test/java/TriangleTest.java) for an example of where `ExpectedException` is used.
159
+
160
+ References: [[1](https://github.com/junit-team/junit4/wiki/Exception-testing)]
@@ -45,11 +45,10 @@ The message above is coded as:
45
45
  imtgdvsfearwermayoogoanouuiontnnlvtwttddesaohghnsseoau
46
46
  ```
47
47
 
48
- Output the encoded text in chunks. Phrases that fill perfect rectangles
49
- `(r X c)` should be output `c` chunks of `r` length, separated by spaces.
50
- Phrases that do not fill perfect rectangles will have `n` empty spaces.
51
- Those spaces should be distributed evenly, added to the end of the last
52
- `n` chunks.
48
+ Output the encoded text in chunks that fill perfect rectangles `(r X c)`,
49
+ with `c` chunks of `r` length, separated by spaces. For phrases that are
50
+ `n` characters short of the perfect rectangle, pad each of the last `n`
51
+ chunks with a single trailing space.
53
52
 
54
53
  ```text
55
54
  imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau
@@ -9,6 +9,44 @@ This exercise requires you to handle various errors. Because error handling
9
9
  is rather programming language specific you'll have to refer to the tests
10
10
  for your track to see what's exactly required.
11
11
 
12
+ # Java Tips
13
+
14
+ This exercise requires you to handle exceptions. An [exception](https://docs.oracle.com/javase/tutorial/essential/exceptions/definition.html) is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions.
15
+
16
+ In Java, there are two types of exceptions: checked and unchecked exceptions.
17
+
18
+ - [Checked vs Unchecked Exceptions in Java](https://www.geeksforgeeks.org/checked-vs-unchecked-exceptions-in-java/)
19
+
20
+ - [Unchecked Exceptions — The Controversy](https://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html)
21
+
22
+ ## Checked exceptions
23
+
24
+ Checked exceptions are the exceptions that are checked at [compile time](https://en.wikipedia.org/wiki/Compile_time).
25
+
26
+ ### Practical implications
27
+
28
+ You have to declare them in the [method signature](https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html) of any method that can [throw](https://docs.oracle.com/javase/tutorial/essential/exceptions/throwing.html) a checked exception and handle or rethrow them when calling any method that can throw a checked exception.
29
+
30
+ This is because checked exceptions are meant to be handled at runtime, i.e. they are errors you can recover from.
31
+
32
+ ### Examples of where they are used
33
+
34
+ They're often used when a method can't return any valid result, for example a search method which hasn't found the item it was searching for.
35
+
36
+ It's an alternative to returning null or a error code. A checked exception is better than those alternatives because it forces the user of the method to consider the error case.
37
+
38
+ ## Unchecked exceptions
39
+
40
+ Unchecked exceptions are the exceptions that are not checked at [compile time](https://en.wikipedia.org/wiki/Compile_time).
41
+
42
+ ### Practical implications
43
+
44
+ You don't have to declare them in the [method signature](https://docs.oracle.com/javase/tutorial/java/javaOO/methods.html) of methods that can [throw](https://docs.oracle.com/javase/tutorial/essential/exceptions/throwing.html) an unchecked exception and handle or rethrow them when calling any method that can throw an unchecked exception.
45
+
46
+ ### Examples of where they are used
47
+
48
+ Unchecked exceptions are mean to be used for any error than can't be handled at runtime, e.g. running out of memory.
49
+
12
50
  # Running the tests
13
51
 
14
52
  You can run all the tests for an exercise by entering
@@ -1,18 +1,18 @@
1
1
  # Series
2
2
 
3
3
  Given a string of digits, output all the contiguous substrings of length `n` in
4
- that string.
4
+ that string in the order that they appear.
5
5
 
6
6
  For example, the string "49142" has the following 3-digit series:
7
7
 
8
- - 491
9
- - 914
10
- - 142
8
+ - "491"
9
+ - "914"
10
+ - "142"
11
11
 
12
12
  And the following 4-digit series:
13
13
 
14
- - 4914
15
- - 9142
14
+ - "4914"
15
+ - "9142"
16
16
 
17
17
  And if you ask for a 6-digit series from a 5-digit string, you deserve
18
18
  whatever you get.
@@ -5,8 +5,8 @@ number.
5
5
 
6
6
  The Sieve of Eratosthenes is a simple, ancient algorithm for finding all
7
7
  prime numbers up to any given limit. It does so by iteratively marking as
8
- composite (i.e. not prime) the multiples of each prime,
9
- starting with the multiples of 2.
8
+ composite (i.e. not prime) the multiples of each prime, starting with the
9
+ multiples of 2. It does not use any division or remainder operation.
10
10
 
11
11
  Create your range, starting at two and continuing up to and including the given limit. (i.e. [2, limit])
12
12
 
@@ -25,7 +25,9 @@ https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
25
25
 
26
26
  Notice that this is a very specific algorithm, and the tests don't check
27
27
  that you've implemented the algorithm, only that you've come up with the
28
- correct list of primes.
28
+ correct list of primes. A good first test is to check that you do not use
29
+ division or remainder operations (div, /, mod or % depending on the
30
+ language).
29
31
 
30
32
  # Running the tests
31
33
 
@@ -93,7 +93,7 @@ do
93
93
  continue
94
94
  fi
95
95
 
96
- track_data_version=$(cat $track_exercise_version_file_path)
96
+ track_data_version=$(cat $track_exercise_version_file_path | sed 's/\r$//')
97
97
 
98
98
  if [ "$track_data_version" = "$canonical_data_version" ]
99
99
  then
@@ -1,65 +1,56 @@
1
1
  class Cell(object):
2
- def __init__(self, reactor, value=0, dependencies=set(),
3
- updater=None):
4
- self.reactor = reactor
5
- self.index = len(reactor.cells)
6
- reactor.cells.append(self)
7
- self.value = value
8
- self.dirty = False
9
- self.dependencies = dependencies
10
- self.dependents = set()
11
- self.updater = updater
12
- self.watchers = set()
13
- if updater is not None:
14
- self.update()
15
- self.notify()
16
-
17
- def add_watcher(self, watcher):
18
- self.watchers.add(watcher)
19
-
20
- def remove_watcher(self, watcher):
21
- self.watchers.remove(watcher)
22
-
23
- def set_value(self, value, top=True):
24
- self.value = value
25
- for d in self.dependents:
26
- d.update()
27
- if top:
28
- self.reactor.notify()
29
-
30
- def update(self):
31
- if self.updater is not None:
32
- values = [d.value for d in self.dependencies]
33
- value = self.updater(values)
34
- if self.value != value:
35
- self.set_value(value, False)
36
- self.dirty = True
37
-
38
- def notify(self):
39
- if self.dirty:
40
- for watcher in self.watchers:
41
- watcher(self, self.value)
42
- self.dirty = False
43
-
44
- def __hash__(self):
45
- return self.index
46
-
47
-
48
- class Reactor(object):
49
2
  def __init__(self):
50
- self.cells = []
51
-
52
- def create_input_cell(self, value):
53
- return Cell(self, value=value)
54
-
55
- def create_compute_cell(self, dependencies, updater):
56
- cell = Cell(self,
57
- dependencies=dependencies,
58
- updater=updater)
59
- for d in dependencies:
60
- d.dependents.add(cell)
61
- return cell
62
-
63
- def notify(self):
64
- for cell in self.cells:
65
- cell.notify()
3
+ self._watchers = []
4
+ self._value = None
5
+ self.counter = 0
6
+
7
+ def add_watcher(self, cell):
8
+ self._watchers.append(cell)
9
+
10
+ @property
11
+ def value(self):
12
+ return self._value
13
+
14
+ @value.setter
15
+ def value(self, new_value):
16
+ self._value = new_value
17
+ self.counter += 1
18
+ for cell in self._watchers:
19
+ cell.compute()
20
+
21
+
22
+ class InputCell(Cell):
23
+ def __init__(self, initial_value):
24
+ super(InputCell, self).__init__()
25
+ self._value = initial_value
26
+
27
+
28
+ class ComputeCell(Cell):
29
+ def __init__(self, inputs, compute_function):
30
+ super(ComputeCell, self).__init__()
31
+ self.inputs = inputs
32
+ self.func = compute_function
33
+ self.callbacks = set()
34
+ self.compute()
35
+ self._register_inputs()
36
+
37
+ def _register_inputs(self):
38
+ for inp in self.inputs:
39
+ inp.add_watcher(self)
40
+
41
+ def compute(self):
42
+ # Only compute this cell when all inputs have same counters
43
+ if len(set([inp.counter for inp in self.inputs])) > 1:
44
+ return
45
+ new_val = self.func([inp.value for inp in self.inputs])
46
+ if new_val != self._value:
47
+ self.value = new_val
48
+ for cb in self.callbacks:
49
+ cb(new_val)
50
+
51
+ def add_callback(self, callback):
52
+ self.callbacks.add(callback)
53
+
54
+ def remove_callback(self, callback):
55
+ if callback in self.callbacks:
56
+ self.callbacks.remove(callback)