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.
- checksums.yaml +4 -4
- data/fixtures/tracks/fruit/docs/something.md +0 -0
- data/lib/trackler/version.rb +1 -1
- data/problem-specifications/README.md +8 -4
- data/problem-specifications/exercises/acronym/canonical-data.json +19 -7
- data/problem-specifications/exercises/all-your-base/canonical-data.json +106 -64
- data/problem-specifications/exercises/allergies/canonical-data.json +37 -13
- data/tracks/c/config.json +176 -176
- data/tracks/clojure/config.json +17 -1
- data/tracks/clojure/exercises/isbn-verifier/README.md +43 -0
- data/tracks/clojure/exercises/isbn-verifier/project.clj +4 -0
- data/tracks/clojure/exercises/isbn-verifier/src/example.clj +17 -0
- data/tracks/clojure/exercises/isbn-verifier/src/isbn_verifier.clj +3 -0
- data/tracks/clojure/exercises/isbn-verifier/test/isbn_verifier_test.clj +42 -0
- data/tracks/clojure/exercises/proverb/README.md +15 -0
- data/tracks/clojure/exercises/proverb/project.clj +4 -0
- data/tracks/clojure/exercises/proverb/src/example.clj +15 -0
- data/tracks/clojure/exercises/proverb/src/proverb.clj +3 -0
- data/tracks/clojure/exercises/proverb/test/proverb_test.clj +14 -0
- data/tracks/common-lisp/docs/LEARNING.md +4 -3
- data/tracks/common-lisp/docs/RESOURCES.md +11 -0
- data/tracks/delphi/.gitignore +1 -0
- data/tracks/delphi/config.json +24 -0
- data/tracks/delphi/docs/INSTALLATION.md +1 -1
- data/tracks/delphi/exercises/isbn-verifier/ISBNVerifier.dpr +60 -0
- data/tracks/delphi/exercises/isbn-verifier/README.md +68 -0
- data/tracks/delphi/exercises/isbn-verifier/uISBNVerifierExample.pas +46 -0
- data/tracks/delphi/exercises/isbn-verifier/uTestISBNVerifier.pas +136 -0
- data/tracks/delphi/exercises/secret-handshake/README.md +56 -0
- data/tracks/delphi/exercises/secret-handshake/SecretHandshake.dpr +60 -0
- data/tracks/delphi/exercises/secret-handshake/uSecretHandshakeExample.pas +56 -0
- data/tracks/delphi/exercises/secret-handshake/uTestSecretHandshake.pas +215 -0
- data/tracks/ecmascript/docs/ABOUT.md +13 -9
- data/tracks/factor/exercises/two-fer/README.md +1 -1
- data/tracks/fsharp/docs/RESOURCES.md +1 -1
- data/tracks/fsharp/generators/{Input.fs → CanonicalData.fs} +5 -10
- data/tracks/fsharp/generators/Exercise.fs +11 -10
- data/tracks/fsharp/generators/{Output.fs → Formatting.fs} +2 -56
- data/tracks/fsharp/generators/Generators.fs +93 -93
- data/tracks/fsharp/generators/Generators.fsproj +9 -4
- data/tracks/fsharp/generators/Options.fs +1 -1
- data/tracks/fsharp/generators/Program.fs +3 -3
- data/tracks/fsharp/generators/Rendering.fs +57 -0
- data/tracks/go/exercises/all-your-base/.meta/gen.go +80 -0
- data/tracks/go/exercises/all-your-base/.meta/hints.md +13 -0
- data/tracks/go/exercises/all-your-base/README.md +16 -1
- data/tracks/go/exercises/all-your-base/all_your_base_test.go +12 -163
- data/tracks/go/exercises/all-your-base/cases_test.go +183 -0
- data/tracks/go/exercises/all-your-base/example.go +25 -29
- data/tracks/java/CONTRIBUTING.md +1 -1
- data/tracks/java/POLICIES.md +15 -1
- data/tracks/java/exercises/flatten-array/.meta/hints.md +58 -0
- data/tracks/java/exercises/flatten-array/README.md +62 -0
- data/tracks/java/exercises/hamming/src/main/java/Hamming.java +1 -1
- data/tracks/java/exercises/matrix/.meta/src/reference/java/Matrix.java +6 -6
- data/tracks/java/exercises/meetup/.meta/src/reference/java/Meetup.java +2 -2
- data/tracks/java/exercises/meetup/.meta/src/reference/java/MeetupSchedule.java +1 -1
- data/tracks/java/exercises/meetup/src/main/java/MeetupSchedule.java +1 -1
- data/tracks/java/exercises/pig-latin/.meta/hints.md +58 -0
- data/tracks/java/exercises/pig-latin/README.md +61 -0
- data/tracks/java/exercises/reverse-string/src/main/java/ReverseString.java +2 -2
- data/tracks/java/exercises/secret-handshake/README.md +1 -1
- data/tracks/javascript/.eslintignore +0 -3
- data/tracks/javascript/exercises/food-chain/example.js +50 -37
- data/tracks/javascript/exercises/octal/example.js +1 -1
- data/tracks/javascript/exercises/robot-name/robot-name.spec.js +7 -7
- data/tracks/javascript/package-lock.json +1846 -0
- data/tracks/python/docs/EXERCISE_README_INSERT.md +15 -0
- data/tracks/python/exercises/accumulate/README.md +15 -0
- data/tracks/python/exercises/acronym/README.md +15 -0
- data/tracks/python/exercises/all-your-base/README.md +15 -0
- data/tracks/python/exercises/all-your-base/all_your_base_test.py +19 -9
- data/tracks/python/exercises/allergies/README.md +15 -0
- data/tracks/python/exercises/alphametics/README.md +15 -0
- data/tracks/python/exercises/anagram/README.md +15 -0
- data/tracks/python/exercises/atbash-cipher/README.md +15 -0
- data/tracks/python/exercises/beer-song/README.md +16 -1
- data/tracks/python/exercises/binary-search-tree/README.md +16 -2
- data/tracks/python/exercises/binary-search/README.md +15 -0
- data/tracks/python/exercises/binary-search/binary_search_test.py +14 -4
- data/tracks/python/exercises/binary/README.md +15 -0
- data/tracks/python/exercises/binary/binary_test.py +14 -4
- data/tracks/python/exercises/bob/README.md +15 -0
- data/tracks/python/exercises/book-store/README.md +15 -0
- data/tracks/python/exercises/bracket-push/README.md +15 -0
- data/tracks/python/exercises/change/README.md +15 -0
- data/tracks/python/exercises/circular-buffer/README.md +15 -0
- data/tracks/python/exercises/circular-buffer/circular_buffer_test.py +15 -5
- data/tracks/python/exercises/circular-buffer/example.py +2 -2
- data/tracks/python/exercises/clock/README.md +15 -0
- data/tracks/python/exercises/collatz-conjecture/.meta/hints.md +1 -1
- data/tracks/python/exercises/collatz-conjecture/README.md +15 -0
- data/tracks/python/exercises/complex-numbers/README.md +15 -0
- data/tracks/python/exercises/connect/README.md +18 -3
- data/tracks/python/exercises/crypto-square/README.md +15 -0
- data/tracks/python/exercises/diamond/README.md +15 -0
- data/tracks/python/exercises/difference-of-squares/README.md +15 -0
- data/tracks/python/exercises/diffie-hellman/README.md +14 -0
- data/tracks/python/exercises/dominoes/README.md +16 -1
- data/tracks/python/exercises/error-handling/README.md +17 -0
- data/tracks/python/exercises/error-handling/error_handling_test.py +13 -3
- data/tracks/python/exercises/error-handling/example.py +1 -1
- data/tracks/python/exercises/etl/README.md +16 -1
- data/tracks/python/exercises/flatten-array/README.md +15 -0
- data/tracks/python/exercises/food-chain/README.md +15 -0
- data/tracks/python/exercises/forth/README.md +15 -0
- data/tracks/python/exercises/forth/example.py +7 -9
- data/tracks/python/exercises/forth/forth_test.py +107 -17
- data/tracks/python/exercises/gigasecond/README.md +15 -0
- data/tracks/python/exercises/go-counting/README.md +21 -3
- data/tracks/python/exercises/grade-school/README.md +15 -0
- data/tracks/python/exercises/grains/README.md +15 -0
- data/tracks/python/exercises/grains/grains_test.py +16 -6
- data/tracks/python/exercises/grep/README.md +15 -0
- data/tracks/python/exercises/hamming/README.md +15 -0
- data/tracks/python/exercises/hamming/hamming_test.py +12 -2
- data/tracks/python/exercises/hello-world/README.md +15 -0
- data/tracks/python/exercises/hexadecimal/README.md +15 -0
- data/tracks/python/exercises/hexadecimal/hexadecimal_test.py +11 -1
- data/tracks/python/exercises/house/README.md +16 -1
- data/tracks/python/exercises/isogram/README.md +15 -0
- data/tracks/python/exercises/kindergarten-garden/README.md +18 -3
- data/tracks/python/exercises/largest-series-product/README.md +15 -0
- data/tracks/python/exercises/largest-series-product/largest_series_product_test.py +14 -4
- data/tracks/python/exercises/leap/README.md +15 -0
- data/tracks/python/exercises/linked-list/README.md +15 -0
- data/tracks/python/exercises/list-ops/README.md +15 -0
- data/tracks/python/exercises/luhn/README.md +15 -0
- data/tracks/python/exercises/markdown/README.md +18 -0
- data/tracks/python/exercises/matrix/README.md +15 -0
- data/tracks/python/exercises/meetup/README.md +31 -12
- data/tracks/python/exercises/meetup/meetup_test.py +11 -1
- data/tracks/python/exercises/minesweeper/README.md +15 -0
- data/tracks/python/exercises/minesweeper/minesweeper_test.py +12 -2
- data/tracks/python/exercises/nth-prime/README.md +15 -0
- data/tracks/python/exercises/nth-prime/nth_prime_test.py +11 -1
- data/tracks/python/exercises/nucleotide-count/README.md +17 -2
- data/tracks/python/exercises/nucleotide-count/nucleotide_count_test.py +11 -1
- data/tracks/python/exercises/ocr-numbers/README.md +16 -1
- data/tracks/python/exercises/ocr-numbers/ocr_numbers_test.py +12 -2
- data/tracks/python/exercises/octal/README.md +15 -0
- data/tracks/python/exercises/octal/octal_test.py +16 -3
- data/tracks/python/exercises/palindrome-products/README.md +16 -1
- data/tracks/python/exercises/pangram/README.md +15 -0
- data/tracks/python/exercises/pascals-triangle/README.md +16 -1
- data/tracks/python/exercises/perfect-numbers/README.md +15 -0
- data/tracks/python/exercises/perfect-numbers/perfect_numbers_test.py +13 -3
- data/tracks/python/exercises/phone-number/README.md +16 -2
- data/tracks/python/exercises/phone-number/example.py +1 -1
- data/tracks/python/exercises/phone-number/phone_number_test.py +17 -7
- data/tracks/python/exercises/pig-latin/README.md +15 -0
- data/tracks/python/exercises/point-mutations/README.md +15 -0
- data/tracks/python/exercises/poker/README.md +15 -0
- data/tracks/python/exercises/pov/README.md +20 -2
- data/tracks/python/exercises/pov/example.py +2 -2
- data/tracks/python/exercises/pov/pov_test.py +15 -5
- data/tracks/python/exercises/prime-factors/README.md +15 -0
- data/tracks/python/exercises/protein-translation/README.md +15 -0
- data/tracks/python/exercises/protein-translation/protein_translation_test.py +10 -0
- data/tracks/python/exercises/proverb/README.md +14 -0
- data/tracks/python/exercises/pythagorean-triplet/README.md +15 -0
- data/tracks/python/exercises/pythagorean-triplet/pythagorean_triplet_test.py +11 -1
- data/tracks/python/exercises/queen-attack/README.md +15 -0
- data/tracks/python/exercises/queen-attack/queen_attack_test.py +17 -7
- data/tracks/python/exercises/rail-fence-cipher/README.md +15 -0
- data/tracks/python/exercises/raindrops/README.md +15 -0
- data/tracks/python/exercises/react/README.md +15 -1
- data/tracks/python/exercises/rectangles/README.md +24 -9
- data/tracks/python/exercises/rna-transcription/.meta/hints.md +1 -0
- data/tracks/python/exercises/rna-transcription/README.md +18 -5
- data/tracks/python/exercises/rna-transcription/rna_transcription_test.py +13 -3
- data/tracks/python/exercises/robot-name/README.md +15 -0
- data/tracks/python/exercises/robot-simulator/README.md +15 -0
- data/tracks/python/exercises/roman-numerals/README.md +15 -0
- data/tracks/python/exercises/rotational-cipher/README.md +15 -0
- data/tracks/python/exercises/run-length-encoding/README.md +15 -0
- data/tracks/python/exercises/saddle-points/README.md +15 -0
- data/tracks/python/exercises/saddle-points/saddle_points_test.py +11 -1
- data/tracks/python/exercises/say/README.md +15 -0
- data/tracks/python/exercises/say/say_test.py +12 -2
- data/tracks/python/exercises/scale-generator/README.md +15 -0
- data/tracks/python/exercises/scale-generator/example.py +3 -3
- data/tracks/python/exercises/scale-generator/scale_generator_test.py +11 -1
- data/tracks/python/exercises/scrabble-score/README.md +15 -0
- data/tracks/python/exercises/secret-handshake/README.md +16 -1
- data/tracks/python/exercises/series/README.md +15 -0
- data/tracks/python/exercises/series/series_test.py +12 -2
- data/tracks/python/exercises/sieve/README.md +15 -0
- data/tracks/python/exercises/simple-cipher/.meta/hints.md +6 -6
- data/tracks/python/exercises/simple-cipher/README.md +17 -1
- data/tracks/python/exercises/simple-cipher/simple_cipher_test.py +12 -2
- data/tracks/python/exercises/simple-linked-list/{hints.md → .meta/hints.md} +10 -10
- data/tracks/python/exercises/simple-linked-list/README.md +16 -0
- data/tracks/python/exercises/simple-linked-list/example.py +2 -2
- data/tracks/python/exercises/simple-linked-list/simple_linked_list_test.py +13 -3
- data/tracks/python/exercises/space-age/README.md +15 -0
- data/tracks/python/exercises/strain/README.md +16 -3
- data/tracks/python/exercises/sublist/README.md +15 -0
- data/tracks/python/exercises/sum-of-multiples/README.md +18 -3
- data/tracks/python/exercises/tournament/README.md +15 -0
- data/tracks/python/exercises/transpose/README.md +15 -0
- data/tracks/python/exercises/tree-building/README.md +30 -0
- data/tracks/python/exercises/tree-building/example.py +3 -5
- data/tracks/python/exercises/tree-building/tree_building_test.py +16 -6
- data/tracks/python/exercises/triangle/README.md +15 -0
- data/tracks/python/exercises/triangle/example.py +1 -1
- data/tracks/python/exercises/triangle/triangle_test.py +15 -5
- data/tracks/python/exercises/trinary/README.md +15 -0
- data/tracks/python/exercises/twelve-days/README.md +15 -0
- data/tracks/python/exercises/two-bucket/README.md +22 -7
- data/tracks/python/exercises/two-fer/README.md +16 -0
- data/tracks/python/exercises/variable-length-quantity/README.md +15 -0
- data/tracks/python/exercises/variable-length-quantity/variable_length_quantity_test.py +12 -2
- data/tracks/python/exercises/word-count/README.md +15 -0
- data/tracks/python/exercises/word-search/README.md +15 -0
- data/tracks/python/exercises/wordy/README.md +15 -0
- data/tracks/python/exercises/wordy/wordy_test.py +14 -4
- data/tracks/python/exercises/zebra-puzzle/README.md +15 -0
- data/tracks/python/exercises/zipper/README.md +16 -3
- data/tracks/rust/config.json +11 -0
- data/tracks/rust/exercises/saddle-points/.gitignore +8 -0
- data/tracks/rust/exercises/saddle-points/Cargo.toml +5 -0
- data/tracks/rust/exercises/saddle-points/README.md +66 -0
- data/tracks/rust/exercises/saddle-points/example.rs +24 -0
- data/tracks/rust/exercises/saddle-points/src/lib.rs +3 -0
- data/tracks/rust/exercises/saddle-points/tests/saddle-points.rs +60 -0
- metadata +38 -5
|
@@ -38,9 +38,19 @@ class SaddlePointTest(unittest.TestCase):
|
|
|
38
38
|
|
|
39
39
|
def test_irregular_matrix(self):
|
|
40
40
|
inp = [[3, 2, 1], [0, 1], [2, 1, 0]]
|
|
41
|
-
with self.
|
|
41
|
+
with self.assertRaisesWithMessage(ValueError):
|
|
42
42
|
saddle_points(inp)
|
|
43
43
|
|
|
44
|
+
# Utility functions
|
|
45
|
+
def setUp(self):
|
|
46
|
+
try:
|
|
47
|
+
self.assertRaisesRegex = self.assertRaisesRegexp
|
|
48
|
+
except AttributeError:
|
|
49
|
+
pass
|
|
50
|
+
|
|
51
|
+
def assertRaisesWithMessage(self, exception):
|
|
52
|
+
return self.assertRaisesRegex(exception, r".+")
|
|
53
|
+
|
|
44
54
|
|
|
45
55
|
if __name__ == '__main__':
|
|
46
56
|
unittest.main()
|
|
@@ -62,6 +62,21 @@ Use _and_ (correctly) when spelling out the number in English:
|
|
|
62
62
|
- 1002 becomes "one thousand and two".
|
|
63
63
|
- 1323 becomes "one thousand three hundred and twenty-three".
|
|
64
64
|
|
|
65
|
+
## Exception messages
|
|
66
|
+
|
|
67
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
|
68
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
|
69
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
|
70
|
+
a message.
|
|
71
|
+
|
|
72
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
|
73
|
+
`raise Exception`, you shold write:
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
raise Exception("Meaningful message indicating the source of the error")
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
|
|
65
80
|
## Submitting Exercises
|
|
66
81
|
|
|
67
82
|
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|
|
@@ -64,13 +64,23 @@ class SayTest(unittest.TestCase):
|
|
|
64
64
|
"one hundred and twenty-three"))
|
|
65
65
|
|
|
66
66
|
def test_number_to_large(self):
|
|
67
|
-
with self.
|
|
67
|
+
with self.assertRaisesWithMessage(ValueError):
|
|
68
68
|
say(1e12)
|
|
69
69
|
|
|
70
70
|
def test_number_negative(self):
|
|
71
|
-
with self.
|
|
71
|
+
with self.assertRaisesWithMessage(ValueError):
|
|
72
72
|
say(-1)
|
|
73
73
|
|
|
74
|
+
# Utility functions
|
|
75
|
+
def setUp(self):
|
|
76
|
+
try:
|
|
77
|
+
self.assertRaisesRegex = self.assertRaisesRegexp
|
|
78
|
+
except AttributeError:
|
|
79
|
+
pass
|
|
80
|
+
|
|
81
|
+
def assertRaisesWithMessage(self, exception):
|
|
82
|
+
return self.assertRaisesRegex(exception, r".+")
|
|
83
|
+
|
|
74
84
|
|
|
75
85
|
if __name__ == '__main__':
|
|
76
86
|
unittest.main()
|
|
@@ -55,6 +55,21 @@ Here is a table of pitches with the names of their interval distance from the to
|
|
|
55
55
|
| | | Dim 3rd | Aug 2nd | Dim 4th | | Aug 4th | Dim 5th | Aug 5th | Dim 7th | Aug 6th | Dim 8ve | |
|
|
56
56
|
| | | | | | | Dim 5th | | | | | | |
|
|
57
57
|
|
|
58
|
+
## Exception messages
|
|
59
|
+
|
|
60
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
|
61
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
|
62
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
|
63
|
+
a message.
|
|
64
|
+
|
|
65
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
|
66
|
+
`raise Exception`, you shold write:
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
raise Exception("Meaningful message indicating the source of the error")
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
|
|
58
73
|
## Submitting Exercises
|
|
59
74
|
|
|
60
75
|
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|
|
@@ -13,8 +13,8 @@ class Scale(object):
|
|
|
13
13
|
self.name = self.tonic + ' ' + scale_name
|
|
14
14
|
self.pattern = pattern
|
|
15
15
|
self.chromatic_scale = (self.FLAT_CHROMATIC_SCALE
|
|
16
|
-
if tonic in self.FLAT_KEYS
|
|
17
|
-
self.CHROMATIC_SCALE)
|
|
16
|
+
if tonic in self.FLAT_KEYS
|
|
17
|
+
else self.CHROMATIC_SCALE)
|
|
18
18
|
self.pitches = self._assign_pitches()
|
|
19
19
|
|
|
20
20
|
def _assign_pitches(self):
|
|
@@ -27,7 +27,7 @@ class Scale(object):
|
|
|
27
27
|
pitches.append(scale[last_index])
|
|
28
28
|
last_index += self.ASCENDING_INTERVALS.index(interval) + 1
|
|
29
29
|
if pitches[0] != scale[last_index % len(scale)]:
|
|
30
|
-
raise ValueError()
|
|
30
|
+
raise ValueError("Interval is broken")
|
|
31
31
|
return pitches
|
|
32
32
|
|
|
33
33
|
def _reorder_chromatic_scale(self):
|
|
@@ -116,9 +116,19 @@ class ScaleGeneratorTest(unittest.TestCase):
|
|
|
116
116
|
self.assertEqual(expected, actual)
|
|
117
117
|
|
|
118
118
|
def test_brokeninterval(self):
|
|
119
|
-
with self.
|
|
119
|
+
with self.assertRaisesWithMessage(ValueError):
|
|
120
120
|
Scale('G', 'enigmatic', 'mAMMMmM')
|
|
121
121
|
|
|
122
|
+
# Utility functions
|
|
123
|
+
def setUp(self):
|
|
124
|
+
try:
|
|
125
|
+
self.assertRaisesRegex = self.assertRaisesRegexp
|
|
126
|
+
except AttributeError:
|
|
127
|
+
pass
|
|
128
|
+
|
|
129
|
+
def assertRaisesWithMessage(self, exception):
|
|
130
|
+
return self.assertRaisesRegex(exception, r".+")
|
|
131
|
+
|
|
122
132
|
|
|
123
133
|
if __name__ == '__main__':
|
|
124
134
|
unittest.main()
|
|
@@ -39,6 +39,21 @@ And to total:
|
|
|
39
39
|
- You can play a double or a triple letter.
|
|
40
40
|
- You can play a double or a triple word.
|
|
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.
|
|
@@ -28,6 +28,21 @@ Given the input 19, the function would return the array
|
|
|
28
28
|
Notice that the addition of 16 (10000 in binary)
|
|
29
29
|
has caused the array to be reversed.
|
|
30
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
|
+
|
|
31
46
|
## Submitting Exercises
|
|
32
47
|
|
|
33
48
|
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|
|
@@ -39,7 +54,7 @@ please see the [help page](http://exercism.io/languages/python).
|
|
|
39
54
|
|
|
40
55
|
## Source
|
|
41
56
|
|
|
42
|
-
Bert, in Mary Poppins
|
|
57
|
+
Bert, in Mary Poppins http://www.imdb.com/title/tt0058331/quotes/qt0437047
|
|
43
58
|
|
|
44
59
|
## Submitting Incomplete Solutions
|
|
45
60
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
|
@@ -20,6 +20,21 @@ whatever you get.
|
|
|
20
20
|
Note that these series are only required to occupy *adjacent positions*
|
|
21
21
|
in the input; the digits need not be *numerically consecutive*.
|
|
22
22
|
|
|
23
|
+
## Exception messages
|
|
24
|
+
|
|
25
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
|
26
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
|
27
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
|
28
|
+
a message.
|
|
29
|
+
|
|
30
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
|
31
|
+
`raise Exception`, you shold write:
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
raise Exception("Meaningful message indicating the source of the error")
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
|
|
23
38
|
## Submitting Exercises
|
|
24
39
|
|
|
25
40
|
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|
|
@@ -37,13 +37,23 @@ class SeriesTest(unittest.TestCase):
|
|
|
37
37
|
[[0, 1, 2, 3, 4]], )
|
|
38
38
|
|
|
39
39
|
def test_overly_long_slice(self):
|
|
40
|
-
with self.
|
|
40
|
+
with self.assertRaisesWithMessage(ValueError):
|
|
41
41
|
slices("012", 4)
|
|
42
42
|
|
|
43
43
|
def test_overly_short_slice(self):
|
|
44
|
-
with self.
|
|
44
|
+
with self.assertRaisesWithMessage(ValueError):
|
|
45
45
|
slices("01234", 0)
|
|
46
46
|
|
|
47
|
+
# Utility functions
|
|
48
|
+
def setUp(self):
|
|
49
|
+
try:
|
|
50
|
+
self.assertRaisesRegex = self.assertRaisesRegexp
|
|
51
|
+
except AttributeError:
|
|
52
|
+
pass
|
|
53
|
+
|
|
54
|
+
def assertRaisesWithMessage(self, exception):
|
|
55
|
+
return self.assertRaisesRegex(exception, r".+")
|
|
56
|
+
|
|
47
57
|
|
|
48
58
|
if __name__ == '__main__':
|
|
49
59
|
unittest.main()
|
|
@@ -27,6 +27,21 @@ 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
28
|
correct list of primes.
|
|
29
29
|
|
|
30
|
+
## Exception messages
|
|
31
|
+
|
|
32
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
|
33
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
|
34
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
|
35
|
+
a message.
|
|
36
|
+
|
|
37
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
|
38
|
+
`raise Exception`, you shold write:
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
raise Exception("Meaningful message indicating the source of the error")
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
|
|
30
45
|
## Submitting Exercises
|
|
31
46
|
|
|
32
47
|
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
Python, as of version 3.6, includes two different random modules.
|
|
4
4
|
|
|
5
5
|
The module called `random` is pseudo-random, meaning it does not generate
|
|
6
|
-
true randomness, but follows an algorithm that simulates randomness.
|
|
7
|
-
Since random numbers are generated through a known algorithm, they are not truly random.
|
|
6
|
+
true randomness, but follows an algorithm that simulates randomness.
|
|
7
|
+
Since random numbers are generated through a known algorithm, they are not truly random.
|
|
8
8
|
|
|
9
|
-
The `random` module is not correctly suited for cryptography and should not be used,
|
|
10
|
-
precisely because it is pseudo-random.
|
|
9
|
+
The `random` module is not correctly suited for cryptography and should not be used,
|
|
10
|
+
precisely because it is pseudo-random.
|
|
11
11
|
|
|
12
12
|
For this reason, in version 3.6, Python introduced the `secrets` module, which generates
|
|
13
|
-
cryptographically strong random numbers that provide the greater security required for cryptography.
|
|
13
|
+
cryptographically strong random numbers that provide the greater security required for cryptography.
|
|
14
14
|
|
|
15
|
-
Since this is only an exercise, `random` is fine to use, but note that **it would be
|
|
15
|
+
Since this is only an exercise, `random` is fine to use, but note that **it would be
|
|
16
16
|
very insecure if actually used for cryptography.**
|
|
@@ -65,7 +65,7 @@ If someone doesn't submit a key at all, generate a truly random key of
|
|
|
65
65
|
at least 100 characters in length, accessible via Cipher#key (the #
|
|
66
66
|
syntax means instance variable)
|
|
67
67
|
|
|
68
|
-
If the key submitted has capital letters or numbers,
|
|
68
|
+
If the key submitted has capital letters or numbers, raise a
|
|
69
69
|
ValueError with a message to that effect.
|
|
70
70
|
|
|
71
71
|
## Extensions
|
|
@@ -100,6 +100,22 @@ cryptographically strong random numbers that provide the greater security requir
|
|
|
100
100
|
Since this is only an exercise, `random` is fine to use, but note that **it would be
|
|
101
101
|
very insecure if actually used for cryptography.**
|
|
102
102
|
|
|
103
|
+
|
|
104
|
+
## Exception messages
|
|
105
|
+
|
|
106
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
|
107
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
|
108
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
|
109
|
+
a message.
|
|
110
|
+
|
|
111
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
|
112
|
+
`raise Exception`, you shold write:
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
raise Exception("Meaningful message indicating the source of the error")
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
|
|
103
119
|
## Submitting Exercises
|
|
104
120
|
|
|
105
121
|
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|
|
@@ -68,11 +68,21 @@ class CipherTest(unittest.TestCase):
|
|
|
68
68
|
'All items in the key must be chars and lowercase!')
|
|
69
69
|
|
|
70
70
|
def test_cipher_wrong_key(self):
|
|
71
|
-
with self.
|
|
71
|
+
with self.assertRaisesWithMessage(ValueError):
|
|
72
72
|
Cipher('a1cde')
|
|
73
|
-
with self.
|
|
73
|
+
with self.assertRaisesWithMessage(ValueError):
|
|
74
74
|
Cipher('aBcde')
|
|
75
75
|
|
|
76
|
+
# Utility functions
|
|
77
|
+
def setUp(self):
|
|
78
|
+
try:
|
|
79
|
+
self.assertRaisesRegex = self.assertRaisesRegexp
|
|
80
|
+
except AttributeError:
|
|
81
|
+
pass
|
|
82
|
+
|
|
83
|
+
def assertRaisesWithMessage(self, exception):
|
|
84
|
+
return self.assertRaisesRegex(exception, r".+")
|
|
85
|
+
|
|
76
86
|
|
|
77
87
|
if __name__ == '__main__':
|
|
78
88
|
unittest.main()
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
## Hints
|
|
2
|
-
|
|
3
|
-
To support `list()`, see [implementing an iterator for a class.](https://docs.python.org/3/tutorial/classes.html#iterators)
|
|
4
|
-
|
|
5
|
-
Additionally, note that Python2's `next()` has been replaced by `__next__()` in Python3. For dual compatibility, `next()` can be implemented as:
|
|
6
|
-
|
|
7
|
-
```Python
|
|
8
|
-
def next(self):
|
|
9
|
-
return self.__next__()
|
|
10
|
-
```
|
|
1
|
+
## Hints
|
|
2
|
+
|
|
3
|
+
To support `list()`, see [implementing an iterator for a class.](https://docs.python.org/3/tutorial/classes.html#iterators)
|
|
4
|
+
|
|
5
|
+
Additionally, note that Python2's `next()` has been replaced by `__next__()` in Python3. For dual compatibility, `next()` can be implemented as:
|
|
6
|
+
|
|
7
|
+
```Python
|
|
8
|
+
def next(self):
|
|
9
|
+
return self.__next__()
|
|
10
|
+
```
|
|
@@ -32,6 +32,22 @@ def next(self):
|
|
|
32
32
|
return self.__next__()
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
+
|
|
36
|
+
## Exception messages
|
|
37
|
+
|
|
38
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
|
39
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
|
40
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
|
41
|
+
a message.
|
|
42
|
+
|
|
43
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
|
44
|
+
`raise Exception`, you shold write:
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
raise Exception("Meaningful message indicating the source of the error")
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
|
|
35
51
|
## Submitting Exercises
|
|
36
52
|
|
|
37
53
|
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|
|
@@ -42,7 +42,7 @@ class LinkedList(object):
|
|
|
42
42
|
|
|
43
43
|
def head(self):
|
|
44
44
|
if self._head is None:
|
|
45
|
-
raise EmptyListException()
|
|
45
|
+
raise EmptyListException("The list is empty")
|
|
46
46
|
return self._head
|
|
47
47
|
|
|
48
48
|
def push(self, value):
|
|
@@ -53,7 +53,7 @@ class LinkedList(object):
|
|
|
53
53
|
|
|
54
54
|
def pop(self):
|
|
55
55
|
if self._head is None:
|
|
56
|
-
raise EmptyListException()
|
|
56
|
+
raise EmptyListException("The list is empty")
|
|
57
57
|
self._len -= 1
|
|
58
58
|
ret = self._head.value()
|
|
59
59
|
self._head = self._head.next()
|
|
@@ -20,7 +20,7 @@ class LinkedListTest(unittest.TestCase):
|
|
|
20
20
|
|
|
21
21
|
def test_error_on_empty_list_head(self):
|
|
22
22
|
sut = LinkedList()
|
|
23
|
-
with self.
|
|
23
|
+
with self.assertRaisesWithMessage(EmptyListException):
|
|
24
24
|
sut.head()
|
|
25
25
|
|
|
26
26
|
def test_singleton_list_has_head(self):
|
|
@@ -51,12 +51,12 @@ class LinkedListTest(unittest.TestCase):
|
|
|
51
51
|
def test_pop_from_singleton_list_removes_head(self):
|
|
52
52
|
sut = LinkedList([1])
|
|
53
53
|
self.assertEqual(sut.pop(), 1)
|
|
54
|
-
with self.
|
|
54
|
+
with self.assertRaisesWithMessage(EmptyListException):
|
|
55
55
|
sut.head()
|
|
56
56
|
|
|
57
57
|
def test_error_on_empty_list_pop(self):
|
|
58
58
|
sut = LinkedList()
|
|
59
|
-
with self.
|
|
59
|
+
with self.assertRaisesWithMessage(EmptyListException):
|
|
60
60
|
sut.pop()
|
|
61
61
|
|
|
62
62
|
def test_push_and_pop(self):
|
|
@@ -107,6 +107,16 @@ class LinkedListTest(unittest.TestCase):
|
|
|
107
107
|
sut = LinkedList([1, 2, 3])
|
|
108
108
|
self.assertEqual(list(sut.reversed()), [1, 2, 3])
|
|
109
109
|
|
|
110
|
+
# Utility functions
|
|
111
|
+
def setUp(self):
|
|
112
|
+
try:
|
|
113
|
+
self.assertRaisesRegex = self.assertRaisesRegexp
|
|
114
|
+
except AttributeError:
|
|
115
|
+
pass
|
|
116
|
+
|
|
117
|
+
def assertRaisesWithMessage(self, exception):
|
|
118
|
+
return self.assertRaisesRegex(exception, r".+")
|
|
119
|
+
|
|
110
120
|
|
|
111
121
|
if __name__ == '__main__':
|
|
112
122
|
unittest.main()
|
|
@@ -17,6 +17,21 @@ be able to say that they're 31.69 Earth-years old.
|
|
|
17
17
|
If you're wondering why Pluto didn't make the cut, go watch [this
|
|
18
18
|
youtube video](http://www.youtube.com/watch?v=Z_2gbGXzFbs).
|
|
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.
|