trackler 2.2.1.74 → 2.2.1.75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,4 +1,4 @@
1
- # Pascals Triangle
1
+ # Pascal's Triangle
2
2
 
3
3
  Compute Pascal's triangle up to a given number of rows.
4
4
 
@@ -14,6 +14,21 @@ the right and left of the current position in the previous row.
14
14
  # ... etc
15
15
  ```
16
16
 
17
+ ## Exception messages
18
+
19
+ Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
20
+ indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
21
+ every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
22
+ a message.
23
+
24
+ To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
25
+ `raise Exception`, you shold write:
26
+
27
+ ```python
28
+ raise Exception("Meaningful message indicating the source of the error")
29
+ ```
30
+
31
+
17
32
  ## Submitting Exercises
18
33
 
19
34
  Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
@@ -17,6 +17,21 @@ The Greek mathematician [Nicomachus](https://en.wikipedia.org/wiki/Nicomachus) d
17
17
 
18
18
  Implement a way to determine whether a given number is **perfect**. Depending on your language track, you may also need to implement a way to determine whether a given number is **abundant** or **deficient**.
19
19
 
20
+ ## Exception messages
21
+
22
+ Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
23
+ indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
24
+ every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
25
+ a message.
26
+
27
+ To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
28
+ `raise Exception`, you shold write:
29
+
30
+ ```python
31
+ raise Exception("Meaningful message indicating the source of the error")
32
+ ```
33
+
34
+
20
35
  ## Submitting Exercises
21
36
 
22
37
  Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
@@ -2,8 +2,8 @@ import unittest
2
2
 
3
3
  from perfect_numbers import classify
4
4
 
5
- # Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.1
6
5
 
6
+ # Tests adapted from `problem-specifications//canonical-data.json` @ v1.0.1
7
7
 
8
8
  class PerfectNumbersTest(unittest.TestCase):
9
9
  def test_smallest_perfect_number(self):
@@ -69,13 +69,23 @@ class DeficientNumbersTest(unittest.TestCase):
69
69
 
70
70
  class InvalidInputsTest(unittest.TestCase):
71
71
  def test_zero(self):
72
- with self.assertRaises(ValueError):
72
+ with self.assertRaisesWithMessage(ValueError):
73
73
  classify(0)
74
74
 
75
75
  def test_negative(self):
76
- with self.assertRaises(ValueError):
76
+ with self.assertRaisesWithMessage(ValueError):
77
77
  classify(-1)
78
78
 
79
+ # Utility functions
80
+ def setUp(self):
81
+ try:
82
+ self.assertRaisesRegex = self.assertRaisesRegexp
83
+ except AttributeError:
84
+ pass
85
+
86
+ def assertRaisesWithMessage(self, exception):
87
+ return self.assertRaisesRegex(exception, r".+")
88
+
79
89
 
80
90
  if __name__ == '__main__':
81
91
  unittest.main()
@@ -14,8 +14,7 @@ The format is usually represented as
14
14
 
15
15
  where `N` is any digit from 2 through 9 and `X` is any digit from 0 through 9.
16
16
 
17
- Your task is to clean up differently formatted telephone numbers by removing punctuation and the
18
- country code (1) if present.
17
+ Your task is to clean up differently formatted telephone numbers by removing punctuation and the country code (1) if present.
19
18
 
20
19
  For example, the inputs
21
20
  - `+1 (613)-995-0253`
@@ -29,6 +28,21 @@ should all produce the output
29
28
 
30
29
  **Note:** As this exercise only deals with telephone numbers used in NANP-countries, only 1 is considered a valid country code.
31
30
 
31
+ ## Exception messages
32
+
33
+ Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
34
+ indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
35
+ every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
36
+ a message.
37
+
38
+ To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
39
+ `raise Exception`, you shold write:
40
+
41
+ ```python
42
+ raise Exception("Meaningful message indicating the source of the error")
43
+ ```
44
+
45
+
32
46
  ## Submitting Exercises
33
47
 
34
48
  Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
@@ -29,4 +29,4 @@ class Phone(object):
29
29
  if valid:
30
30
  return number[-10:]
31
31
  else:
32
- raise ValueError()
32
+ raise ValueError("{} is not a valid phone number".format(number))
@@ -19,11 +19,11 @@ class PhoneTest(unittest.TestCase):
19
19
  self.assertEqual(number, "2234567890")
20
20
 
21
21
  def test_invalid_when_9_digits(self):
22
- with self.assertRaises(ValueError):
22
+ with self.assertRaisesWithMessage(ValueError):
23
23
  Phone("123456789")
24
24
 
25
25
  def test_invalid_when_11_digits_and_first_not_1(self):
26
- with self.assertRaises(ValueError):
26
+ with self.assertRaisesWithMessage(ValueError):
27
27
  Phone("22234567890")
28
28
 
29
29
  def test_valid_when_11_digits_and_first_is_1(self):
@@ -35,23 +35,23 @@ class PhoneTest(unittest.TestCase):
35
35
  self.assertEqual(number, "2234567890")
36
36
 
37
37
  def test_invalid_when_more_than_11_digits(self):
38
- with self.assertRaises(ValueError):
38
+ with self.assertRaisesWithMessage(ValueError):
39
39
  Phone("321234567890")
40
40
 
41
41
  def test_invalid_with_letters(self):
42
- with self.assertRaises(ValueError):
42
+ with self.assertRaisesWithMessage(ValueError):
43
43
  Phone("123-abc-7890")
44
44
 
45
45
  def test_invalid_with_punctuation(self):
46
- with self.assertRaises(ValueError):
46
+ with self.assertRaisesWithMessage(ValueError):
47
47
  Phone("123-@:!-7890")
48
48
 
49
49
  def test_invalid_area_code(self):
50
- with self.assertRaises(ValueError):
50
+ with self.assertRaisesWithMessage(ValueError):
51
51
  Phone("(123) 456-7890")
52
52
 
53
53
  def test_invalid_exchange_code(self):
54
- with self.assertRaises(ValueError):
54
+ with self.assertRaisesWithMessage(ValueError):
55
55
  Phone("(223) 056-7890")
56
56
 
57
57
  # Track specific tests
@@ -67,6 +67,16 @@ class PhoneTest(unittest.TestCase):
67
67
  number = Phone("12234567890")
68
68
  self.assertEqual(number.pretty(), "(223) 456-7890")
69
69
 
70
+ # Utility functions
71
+ def setUp(self):
72
+ try:
73
+ self.assertRaisesRegex = self.assertRaisesRegexp
74
+ except AttributeError:
75
+ pass
76
+
77
+ def assertRaisesWithMessage(self, exception):
78
+ return self.assertRaisesRegex(exception, r".+")
79
+
70
80
 
71
81
  if __name__ == '__main__':
72
82
  unittest.main()
@@ -17,6 +17,21 @@ variants too.
17
17
 
18
18
  See <http://en.wikipedia.org/wiki/Pig_latin> for more details.
19
19
 
20
+ ## Exception messages
21
+
22
+ Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
23
+ indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
24
+ every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
25
+ a message.
26
+
27
+ To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
28
+ `raise Exception`, you shold write:
29
+
30
+ ```python
31
+ raise Exception("Meaningful message indicating the source of the error")
32
+ ```
33
+
34
+
20
35
  ## Submitting Exercises
21
36
 
22
37
  Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
@@ -34,6 +34,21 @@ distance function.
34
34
 
35
35
  **Note: This problem is deprecated, replaced by the one called `hamming`.**
36
36
 
37
+ ## Exception messages
38
+
39
+ Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
40
+ indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
41
+ every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
42
+ a message.
43
+
44
+ To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
45
+ `raise Exception`, you shold write:
46
+
47
+ ```python
48
+ raise Exception("Meaningful message indicating the source of the error")
49
+ ```
50
+
51
+
37
52
  ## Submitting Exercises
38
53
 
39
54
  Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
@@ -5,6 +5,21 @@ Pick the best hand(s) from a list of poker hands.
5
5
  See [wikipedia](https://en.wikipedia.org/wiki/List_of_poker_hands) for an
6
6
  overview of poker hands.
7
7
 
8
+ ## Exception messages
9
+
10
+ Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
11
+ indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
12
+ every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
13
+ a message.
14
+
15
+ To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
16
+ `raise Exception`, you shold write:
17
+
18
+ ```python
19
+ raise Exception("Meaningful message indicating the source of the error")
20
+ ```
21
+
22
+
8
23
  ## Submitting Exercises
9
24
 
10
25
  Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Reparent a graph on a selected node.
4
4
 
5
- ### Tree Reparenting
5
+ # Tree Reparenting
6
6
 
7
7
  This exercise is all about re-orientating a graph to see things from a different
8
8
  point of view. For example family trees are usually presented from the
@@ -39,15 +39,33 @@ a different leaf node) can be seen to follow the path 6-2-0-3-9
39
39
  This exercise involves taking an input graph and re-orientating it from the point
40
40
  of view of one of the nodes.
41
41
 
42
+ ## Exception messages
43
+
44
+ Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
45
+ indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
46
+ every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
47
+ a message.
48
+
49
+ To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
50
+ `raise Exception`, you shold write:
51
+
52
+ ```python
53
+ raise Exception("Meaningful message indicating the source of the error")
54
+ ```
55
+
56
+
42
57
  ## Submitting Exercises
43
58
 
44
59
  Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
45
60
 
46
61
  For example, if you're submitting `bob.py` for the Bob exercise, the submit command would be something like `exercism submit <path_to_exercism_dir>/python/bob/bob.py`.
47
62
 
48
-
49
63
  For more detailed information about running tests, code style and linting,
50
64
  please see the [help page](http://exercism.io/languages/python).
51
65
 
66
+ ## Source
67
+
68
+ Adaptation of exercise from 4clojure [https://www.4clojure.com/](https://www.4clojure.com/)
69
+
52
70
  ## Submitting Incomplete Solutions
53
71
  It's possible to submit an incomplete solution so you can see how others have completed the exercise.
@@ -53,7 +53,7 @@ class Tree(object):
53
53
  return tree
54
54
  for child in tree.children:
55
55
  stack.append(child.add(tree.remove(child.label)))
56
- raise ValueError()
56
+ raise ValueError("Tree could not be reoriented")
57
57
 
58
58
  def pathTo(self, from_node, to_node):
59
59
  reordered = self.fromPov(from_node)
@@ -63,7 +63,7 @@ class Tree(object):
63
63
  try:
64
64
  tree = stack.pop()
65
65
  except IndexError:
66
- raise ValueError()
66
+ raise ValueError("No path found")
67
67
  if to_node in tree:
68
68
  path.append(tree.label)
69
69
  stack = tree.children
@@ -2,8 +2,8 @@ import unittest
2
2
 
3
3
  from pov import Tree
4
4
 
5
- # Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.1
6
5
 
6
+ # Tests adapted from `problem-specifications//canonical-data.json` @ v1.1.1
7
7
 
8
8
  class PovTest(unittest.TestCase):
9
9
  def assertTreeEquals(self, result, expected):
@@ -110,7 +110,7 @@ class PovTest(unittest.TestCase):
110
110
 
111
111
  def test_errors_if_target_does_not_exist_in_singleton_tree(self):
112
112
  tree = Tree('x')
113
- with self.assertRaises(ValueError):
113
+ with self.assertRaisesWithMessage(ValueError):
114
114
  tree.fromPov('nonexistent')
115
115
 
116
116
  def test_errors_if_target_does_not_exist_in_large_tree(self):
@@ -122,7 +122,7 @@ class PovTest(unittest.TestCase):
122
122
  Tree('sibling-0'),
123
123
  Tree('sibling-1')
124
124
  ])
125
- with self.assertRaises(ValueError):
125
+ with self.assertRaisesWithMessage(ValueError):
126
126
  tree.fromPov('nonexistent')
127
127
 
128
128
  def test_find_path_between_two_nodes(self):
@@ -180,7 +180,7 @@ class PovTest(unittest.TestCase):
180
180
  Tree('sibling-0'),
181
181
  Tree('sibling-1')
182
182
  ])
183
- with self.assertRaises(ValueError):
183
+ with self.assertRaisesWithMessage(ValueError):
184
184
  tree.pathTo('x', 'nonexistent')
185
185
 
186
186
  def test_errors_if_source_does_not_exist(self):
@@ -192,9 +192,19 @@ class PovTest(unittest.TestCase):
192
192
  Tree('sibling-0'),
193
193
  Tree('sibling-1')
194
194
  ])
195
- with self.assertRaises(ValueError):
195
+ with self.assertRaisesWithMessage(ValueError):
196
196
  tree.pathTo('nonexistent', 'x')
197
197
 
198
+ # Utility functions
199
+ def setUp(self):
200
+ try:
201
+ self.assertRaisesRegex = self.assertRaisesRegexp
202
+ except AttributeError:
203
+ pass
204
+
205
+ def assertRaisesWithMessage(self, exception):
206
+ return self.assertRaisesRegex(exception, r".+")
207
+
198
208
 
199
209
  if __name__ == '__main__':
200
210
  unittest.main()
@@ -29,6 +29,21 @@ You can check this yourself:
29
29
  - = 60
30
30
  - Success!
31
31
 
32
+ ## Exception messages
33
+
34
+ Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
35
+ indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
36
+ every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
37
+ a message.
38
+
39
+ To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
40
+ `raise Exception`, you shold write:
41
+
42
+ ```python
43
+ raise Exception("Meaningful message indicating the source of the error")
44
+ ```
45
+
46
+
32
47
  ## Submitting Exercises
33
48
 
34
49
  Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
@@ -41,6 +41,21 @@ UAA, UAG, UGA | STOP
41
41
 
42
42
  Learn more about [protein translation on Wikipedia](http://en.wikipedia.org/wiki/Translation_(biology))
43
43
 
44
+ ## Exception messages
45
+
46
+ Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
47
+ indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
48
+ every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
49
+ a message.
50
+
51
+ To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
52
+ `raise Exception`, you shold write:
53
+
54
+ ```python
55
+ raise Exception("Meaningful message indicating the source of the error")
56
+ ```
57
+
58
+
44
59
  ## Submitting Exercises
45
60
 
46
61
  Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
@@ -65,6 +65,16 @@ class ProteinTranslationTests(unittest.TestCase):
65
65
  expected = ['Tryptophan', 'Cysteine', 'Tyrosine']
66
66
  self.assertEqual(expected, proteins(strand))
67
67
 
68
+ # Utility functions
69
+ def setUp(self):
70
+ try:
71
+ self.assertRaisesRegex = self.assertRaisesRegexp
72
+ except AttributeError:
73
+ pass
74
+
75
+ def assertRaisesWithMessage(self, exception):
76
+ return self.assertRaisesRegex(exception, r".+")
77
+
68
78
 
69
79
  if __name__ == '__main__':
70
80
  unittest.main()
@@ -16,6 +16,20 @@ And all for the want of a nail.
16
16
 
17
17
  Note that the list of inputs may vary; your solution should be able to handle lists of arbitrary length and content. No line of the output text should be a static, unchanging string; all should vary according to the input given.
18
18
 
19
+ ## Exception messages
20
+
21
+ Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
22
+ indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
23
+ every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
24
+ a message.
25
+
26
+ To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
27
+ `raise Exception`, you shold write:
28
+
29
+ ```python
30
+ raise Exception("Meaningful message indicating the source of the error")
31
+ ```
32
+
19
33
  ## Submitting Exercises
20
34
 
21
35
  Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.