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
|
@@ -3,6 +3,21 @@
|
|
|
3
3
|
Given a string containing brackets `[]`, braces `{}` and parentheses `()`,
|
|
4
4
|
verify that all the pairs are matched and nested correctly.
|
|
5
5
|
|
|
6
|
+
## Exception messages
|
|
7
|
+
|
|
8
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
|
9
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
|
10
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
|
11
|
+
a message.
|
|
12
|
+
|
|
13
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
|
14
|
+
`raise Exception`, you shold write:
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
raise Exception("Meaningful message indicating the source of the error")
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
|
|
6
21
|
## Submitting Exercises
|
|
7
22
|
|
|
8
23
|
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|
|
@@ -16,6 +16,21 @@ that the sum of the coins' value would equal the correct amount of change.
|
|
|
16
16
|
- Can you ask for negative change?
|
|
17
17
|
- Can you ask for a change value smaller than the smallest coin value?
|
|
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
|
+
|
|
33
|
+
|
|
19
34
|
## Submitting Exercises
|
|
20
35
|
|
|
21
36
|
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|
|
@@ -50,6 +50,21 @@ the buffer is once again full.
|
|
|
50
50
|
|
|
51
51
|
[D][7][8][9][A][B][C]
|
|
52
52
|
|
|
53
|
+
## Exception messages
|
|
54
|
+
|
|
55
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
|
56
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
|
57
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
|
58
|
+
a message.
|
|
59
|
+
|
|
60
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
|
61
|
+
`raise Exception`, you shold write:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
raise Exception("Meaningful message indicating the source of the error")
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
|
|
53
68
|
## Submitting Exercises
|
|
54
69
|
|
|
55
70
|
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|
|
@@ -12,7 +12,7 @@ from circular_buffer import (
|
|
|
12
12
|
class CircularBufferTest(unittest.TestCase):
|
|
13
13
|
def test_read_empty_buffer(self):
|
|
14
14
|
buf = CircularBuffer(1)
|
|
15
|
-
with self.
|
|
15
|
+
with self.assertRaisesWithMessage(BufferEmptyException):
|
|
16
16
|
buf.read()
|
|
17
17
|
|
|
18
18
|
def test_read_just_written_item(self):
|
|
@@ -24,7 +24,7 @@ class CircularBufferTest(unittest.TestCase):
|
|
|
24
24
|
buf = CircularBuffer(1)
|
|
25
25
|
buf.write('1')
|
|
26
26
|
self.assertEqual(buf.read(), '1')
|
|
27
|
-
with self.
|
|
27
|
+
with self.assertRaisesWithMessage(BufferEmptyException):
|
|
28
28
|
buf.read()
|
|
29
29
|
|
|
30
30
|
def test_write_and_read_back_multiple_items_ordered(self):
|
|
@@ -37,7 +37,7 @@ class CircularBufferTest(unittest.TestCase):
|
|
|
37
37
|
def test_full_buffer_cant_written(self):
|
|
38
38
|
buf = CircularBuffer(1)
|
|
39
39
|
buf.write('1')
|
|
40
|
-
with self.
|
|
40
|
+
with self.assertRaisesWithMessage(BufferFullException):
|
|
41
41
|
buf.write('2')
|
|
42
42
|
|
|
43
43
|
def test_alternate_write_and_read(self):
|
|
@@ -60,7 +60,7 @@ class CircularBufferTest(unittest.TestCase):
|
|
|
60
60
|
buf = CircularBuffer(1)
|
|
61
61
|
buf.write('1')
|
|
62
62
|
buf.clear()
|
|
63
|
-
with self.
|
|
63
|
+
with self.assertRaisesWithMessage(BufferEmptyException):
|
|
64
64
|
buf.read()
|
|
65
65
|
|
|
66
66
|
def test_clear_free_buffer_for_write(self):
|
|
@@ -95,7 +95,7 @@ class CircularBufferTest(unittest.TestCase):
|
|
|
95
95
|
buf = CircularBuffer(2)
|
|
96
96
|
buf.write('1')
|
|
97
97
|
buf.write('2')
|
|
98
|
-
with self.
|
|
98
|
+
with self.assertRaisesWithMessage(BufferFullException):
|
|
99
99
|
buf.write('A')
|
|
100
100
|
|
|
101
101
|
def test_over_write_replaces_oldest_remaning_item(self):
|
|
@@ -110,6 +110,16 @@ class CircularBufferTest(unittest.TestCase):
|
|
|
110
110
|
self.assertEqual(buf.read(), '4')
|
|
111
111
|
self.assertEqual(buf.read(), '5')
|
|
112
112
|
|
|
113
|
+
# Utility functions
|
|
114
|
+
def setUp(self):
|
|
115
|
+
try:
|
|
116
|
+
self.assertRaisesRegex = self.assertRaisesRegexp
|
|
117
|
+
except AttributeError:
|
|
118
|
+
pass
|
|
119
|
+
|
|
120
|
+
def assertRaisesWithMessage(self, exception):
|
|
121
|
+
return self.assertRaisesRegex(exception, r".+")
|
|
122
|
+
|
|
113
123
|
|
|
114
124
|
if __name__ == '__main__':
|
|
115
125
|
unittest.main()
|
|
@@ -25,7 +25,7 @@ class CircularBuffer(object):
|
|
|
25
25
|
|
|
26
26
|
def write(self, data):
|
|
27
27
|
if all(self.buffer):
|
|
28
|
-
raise BufferFullException
|
|
28
|
+
raise BufferFullException("Circular buffer is full")
|
|
29
29
|
self._update_buffer(data)
|
|
30
30
|
self.write_point = (self.write_point + 1) % len(self.buffer)
|
|
31
31
|
|
|
@@ -37,7 +37,7 @@ class CircularBuffer(object):
|
|
|
37
37
|
|
|
38
38
|
def read(self):
|
|
39
39
|
if not any(self.buffer):
|
|
40
|
-
raise BufferEmptyException
|
|
40
|
+
raise BufferEmptyException("Circular buffer is empty")
|
|
41
41
|
data = chr(self.buffer[self.read_point])
|
|
42
42
|
self.buffer[self.read_point] = 0
|
|
43
43
|
self.read_point = (self.read_point + 1) % len(self.buffer)
|
|
@@ -6,6 +6,21 @@ You should be able to add and subtract minutes to it.
|
|
|
6
6
|
|
|
7
7
|
Two clocks that represent the same time should be equal to each other.
|
|
8
8
|
|
|
9
|
+
## Exception messages
|
|
10
|
+
|
|
11
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
|
12
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
|
13
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
|
14
|
+
a message.
|
|
15
|
+
|
|
16
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
|
17
|
+
`raise Exception`, you shold write:
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
raise Exception("Meaningful message indicating the source of the error")
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
|
|
9
24
|
## Submitting Exercises
|
|
10
25
|
|
|
11
26
|
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
## Notes
|
|
2
2
|
|
|
3
|
-
The Collatz Conjecture is only concerned with strictly positive integers, so your solution should
|
|
3
|
+
The Collatz Conjecture is only concerned with strictly positive integers, so your solution should raise a `ValueError` with a meaningful message if given 0 or a negative integer.
|
|
@@ -31,6 +31,21 @@ Resulting in 9 steps. So for input n = 12, the return value would be 9.
|
|
|
31
31
|
The Collatz Conjecture is only concerned with strictly positive integers, so your solution should raise a `ValueError` with a meaningful message if given 0 or a negative integer.
|
|
32
32
|
|
|
33
33
|
|
|
34
|
+
## Exception messages
|
|
35
|
+
|
|
36
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
|
37
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
|
38
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
|
39
|
+
a message.
|
|
40
|
+
|
|
41
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
|
42
|
+
`raise Exception`, you shold write:
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
raise Exception("Meaningful message indicating the source of the error")
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
|
|
34
49
|
## Submitting Exercises
|
|
35
50
|
|
|
36
51
|
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|
|
@@ -31,6 +31,21 @@ Implement the following operations:
|
|
|
31
31
|
|
|
32
32
|
Assume the programming language you are using does not have an implementation of complex numbers.
|
|
33
33
|
|
|
34
|
+
## Exception messages
|
|
35
|
+
|
|
36
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
|
37
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
|
38
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
|
39
|
+
a message.
|
|
40
|
+
|
|
41
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
|
42
|
+
`raise Exception`, you shold write:
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
raise Exception("Meaningful message indicating the source of the error")
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
|
|
34
49
|
## Submitting Exercises
|
|
35
50
|
|
|
36
51
|
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|
|
@@ -18,7 +18,7 @@ computes the winner (or lack thereof). Note that all games need not be "fair".
|
|
|
18
18
|
The boards look like this (with spaces added for readability, which won't be in
|
|
19
19
|
the representation passed to your code):
|
|
20
20
|
|
|
21
|
-
```
|
|
21
|
+
```text
|
|
22
22
|
. O . X .
|
|
23
23
|
. X X O .
|
|
24
24
|
O O O X .
|
|
@@ -30,15 +30,30 @@ the representation passed to your code):
|
|
|
30
30
|
the above example `O` has made a connection from left to right but nobody has
|
|
31
31
|
won since `O` didn't connect top and bottom.
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
## Exception messages
|
|
34
|
+
|
|
35
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
|
36
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
|
37
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
|
38
|
+
a message.
|
|
39
|
+
|
|
40
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
|
41
|
+
`raise Exception`, you shold write:
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
raise Exception("Meaningful message indicating the source of the error")
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
## Submitting Exercises
|
|
34
49
|
|
|
35
50
|
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|
|
36
51
|
|
|
37
52
|
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`.
|
|
38
53
|
|
|
39
|
-
|
|
40
54
|
For more detailed information about running tests, code style and linting,
|
|
41
55
|
please see the [help page](http://exercism.io/languages/python).
|
|
42
56
|
|
|
57
|
+
|
|
43
58
|
## Submitting Incomplete Solutions
|
|
44
59
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
|
@@ -69,6 +69,21 @@ aohghn
|
|
|
69
69
|
sseoau
|
|
70
70
|
```
|
|
71
71
|
|
|
72
|
+
## Exception messages
|
|
73
|
+
|
|
74
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
|
75
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
|
76
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
|
77
|
+
a message.
|
|
78
|
+
|
|
79
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
|
80
|
+
`raise Exception`, you shold write:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
raise Exception("Meaningful message indicating the source of the error")
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
|
|
72
87
|
## Submitting Exercises
|
|
73
88
|
|
|
74
89
|
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|
|
@@ -52,6 +52,21 @@ E·······E
|
|
|
52
52
|
····A····
|
|
53
53
|
```
|
|
54
54
|
|
|
55
|
+
## Exception messages
|
|
56
|
+
|
|
57
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
|
58
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
|
59
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
|
60
|
+
a message.
|
|
61
|
+
|
|
62
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
|
63
|
+
`raise Exception`, you shold write:
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
raise Exception("Meaningful message indicating the source of the error")
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
|
|
55
70
|
## Submitting Exercises
|
|
56
71
|
|
|
57
72
|
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|
|
@@ -12,6 +12,21 @@ Hence the difference between the square of the sum of the first
|
|
|
12
12
|
ten natural numbers and the sum of the squares of the first ten
|
|
13
13
|
natural numbers is 3025 - 385 = 2640.
|
|
14
14
|
|
|
15
|
+
## Exception messages
|
|
16
|
+
|
|
17
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
|
18
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
|
19
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
|
20
|
+
a message.
|
|
21
|
+
|
|
22
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
|
23
|
+
`raise Exception`, you shold write:
|
|
24
|
+
|
|
25
|
+
```python
|
|
26
|
+
raise Exception("Meaningful message indicating the source of the error")
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
|
|
15
30
|
## Submitting Exercises
|
|
16
31
|
|
|
17
32
|
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|
|
@@ -54,6 +54,20 @@ cryptographically strong random numbers that provide the greater security requir
|
|
|
54
54
|
Since this is only an exercise, `random` is fine to use, but note that **it would be
|
|
55
55
|
very insecure if actually used for cryptography.**
|
|
56
56
|
|
|
57
|
+
## Exception messages
|
|
58
|
+
|
|
59
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
|
60
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
|
61
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
|
62
|
+
a message.
|
|
63
|
+
|
|
64
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
|
65
|
+
`raise Exception`, you shold write:
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
raise Exception("Meaningful message indicating the source of the error")
|
|
69
|
+
```
|
|
70
|
+
|
|
57
71
|
|
|
58
72
|
## Submitting Exercises
|
|
59
73
|
|
|
@@ -14,15 +14,30 @@ For stones `[1|2]`, `[4|1]` and `[2|3]` the resulting chain is not valid: `[4|1]
|
|
|
14
14
|
|
|
15
15
|
Some test cases may use duplicate stones in a chain solution, assume that multiple Domino sets are being used.
|
|
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.
|
|
20
35
|
|
|
21
36
|
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`.
|
|
22
37
|
|
|
23
|
-
|
|
24
38
|
For more detailed information about running tests, code style and linting,
|
|
25
39
|
please see the [help page](http://exercism.io/languages/python).
|
|
26
40
|
|
|
41
|
+
|
|
27
42
|
## Submitting Incomplete Solutions
|
|
28
43
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
|
@@ -18,6 +18,22 @@ class implements the following methods:
|
|
|
18
18
|
- `__enter__` and `__exit__`, for implicit opening and closing.
|
|
19
19
|
- `do_something`, which may or may not throw an `Exception`.
|
|
20
20
|
|
|
21
|
+
|
|
22
|
+
## Exception messages
|
|
23
|
+
|
|
24
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
|
25
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
|
26
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
|
27
|
+
a message.
|
|
28
|
+
|
|
29
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
|
30
|
+
`raise Exception`, you shold write:
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
raise Exception("Meaningful message indicating the source of the error")
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
|
|
21
37
|
## Submitting Exercises
|
|
22
38
|
|
|
23
39
|
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|
|
@@ -27,5 +43,6 @@ For example, if you're submitting `bob.py` for the Bob exercise, the submit comm
|
|
|
27
43
|
For more detailed information about running tests, code style and linting,
|
|
28
44
|
please see the [help page](http://exercism.io/languages/python).
|
|
29
45
|
|
|
46
|
+
|
|
30
47
|
## Submitting Incomplete Solutions
|
|
31
48
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
|
@@ -28,12 +28,12 @@ class FileLike(object):
|
|
|
28
28
|
def do_something(self):
|
|
29
29
|
self.did_something = True
|
|
30
30
|
if self.fail_something:
|
|
31
|
-
raise Exception()
|
|
31
|
+
raise Exception("Failed while doing something")
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
class ErrorHandlingTest(unittest.TestCase):
|
|
35
35
|
def test_throw_exception(self):
|
|
36
|
-
with self.
|
|
36
|
+
with self.assertRaisesWithMessage(Exception):
|
|
37
37
|
er.handle_error_by_throwing_exception()
|
|
38
38
|
|
|
39
39
|
def test_return_none(self):
|
|
@@ -54,7 +54,7 @@ class ErrorHandlingTest(unittest.TestCase):
|
|
|
54
54
|
|
|
55
55
|
def test_filelike_objects_are_closed_on_exception(self):
|
|
56
56
|
filelike_object = FileLike(fail_something=True)
|
|
57
|
-
with self.
|
|
57
|
+
with self.assertRaisesWithMessage(Exception):
|
|
58
58
|
er.filelike_objects_are_closed_on_exception(filelike_object)
|
|
59
59
|
self.assertIs(filelike_object.is_open, False,
|
|
60
60
|
'filelike_object should be closed')
|
|
@@ -73,6 +73,16 @@ class ErrorHandlingTest(unittest.TestCase):
|
|
|
73
73
|
self.assertIs(filelike_object.did_something, True,
|
|
74
74
|
'filelike_object should call do_something()')
|
|
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()
|