trackler 2.2.1.74 → 2.2.1.75
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,3 +1,18 @@
|
|
1
|
+
## Exception messages
|
2
|
+
|
3
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
4
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
5
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
6
|
+
a message.
|
7
|
+
|
8
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
9
|
+
`raise Exception`, you shold write:
|
10
|
+
|
11
|
+
```python
|
12
|
+
raise Exception("Meaningful message indicating the source of the error")
|
13
|
+
```
|
14
|
+
|
15
|
+
|
1
16
|
## Submitting Exercises
|
2
17
|
|
3
18
|
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|
@@ -25,6 +25,21 @@ Keep your hands off that collect/map/fmap/whatchamacallit functionality
|
|
25
25
|
provided by your standard library!
|
26
26
|
Solve this one yourself using other basic tools instead.
|
27
27
|
|
28
|
+
## Exception messages
|
29
|
+
|
30
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
31
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
32
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
33
|
+
a message.
|
34
|
+
|
35
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
36
|
+
`raise Exception`, you shold write:
|
37
|
+
|
38
|
+
```python
|
39
|
+
raise Exception("Meaningful message indicating the source of the error")
|
40
|
+
```
|
41
|
+
|
42
|
+
|
28
43
|
## Submitting Exercises
|
29
44
|
|
30
45
|
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|
@@ -7,6 +7,21 @@ Techies love their TLA (Three Letter Acronyms)!
|
|
7
7
|
Help generate some jargon by writing a program that converts a long name
|
8
8
|
like Portable Network Graphics to its acronym (PNG).
|
9
9
|
|
10
|
+
## Exception messages
|
11
|
+
|
12
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
13
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
14
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
15
|
+
a message.
|
16
|
+
|
17
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
18
|
+
`raise Exception`, you shold write:
|
19
|
+
|
20
|
+
```python
|
21
|
+
raise Exception("Meaningful message indicating the source of the error")
|
22
|
+
```
|
23
|
+
|
24
|
+
|
10
25
|
## Submitting Exercises
|
11
26
|
|
12
27
|
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|
@@ -31,6 +31,21 @@ I think you got the idea!
|
|
31
31
|
|
32
32
|
*Yes. Those three numbers above are exactly the same. Congratulations!*
|
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.
|
@@ -44,41 +44,51 @@ class AllYourBaseTests(unittest.TestCase):
|
|
44
44
|
self.assertEqual(rebase(7, [0, 6, 0], 10), [4, 2])
|
45
45
|
|
46
46
|
def test_first_base_is_one(self):
|
47
|
-
with self.
|
47
|
+
with self.assertRaisesWithMessage(ValueError):
|
48
48
|
rebase(1, [], 10)
|
49
49
|
|
50
50
|
def test_first_base_is_zero(self):
|
51
|
-
with self.
|
51
|
+
with self.assertRaisesWithMessage(ValueError):
|
52
52
|
rebase(0, [], 10)
|
53
53
|
|
54
54
|
def test_first_base_is_negative(self):
|
55
|
-
with self.
|
55
|
+
with self.assertRaisesWithMessage(ValueError):
|
56
56
|
rebase(-2, [1], 10)
|
57
57
|
|
58
58
|
def test_negative_digit(self):
|
59
|
-
with self.
|
59
|
+
with self.assertRaisesWithMessage(ValueError):
|
60
60
|
rebase(2, [1, -1, 1, 0, 1, 0], 10)
|
61
61
|
|
62
62
|
def test_invalid_positive_digit(self):
|
63
|
-
with self.
|
63
|
+
with self.assertRaisesWithMessage(ValueError):
|
64
64
|
rebase(2, [1, 2, 1, 0, 1, 0], 10)
|
65
65
|
|
66
66
|
def test_second_base_is_one(self):
|
67
|
-
with self.
|
67
|
+
with self.assertRaisesWithMessage(ValueError):
|
68
68
|
rebase(2, [1, 0, 1, 0, 1, 0], 1)
|
69
69
|
|
70
70
|
def test_second_base_is_zero(self):
|
71
|
-
with self.
|
71
|
+
with self.assertRaisesWithMessage(ValueError):
|
72
72
|
rebase(10, [7], 0)
|
73
73
|
|
74
74
|
def test_second_base_is_negative(self):
|
75
|
-
with self.
|
75
|
+
with self.assertRaisesWithMessage(ValueError):
|
76
76
|
rebase(2, [1], -7)
|
77
77
|
|
78
78
|
def test_both_bases_are_negative(self):
|
79
|
-
with self.
|
79
|
+
with self.assertRaisesWithMessage(ValueError):
|
80
80
|
rebase(-2, [1], -7)
|
81
81
|
|
82
|
+
# Utility functions
|
83
|
+
def setUp(self):
|
84
|
+
try:
|
85
|
+
self.assertRaisesRegex = self.assertRaisesRegexp
|
86
|
+
except AttributeError:
|
87
|
+
pass
|
88
|
+
|
89
|
+
def assertRaisesWithMessage(self, exception):
|
90
|
+
return self.assertRaisesRegex(exception, r".+")
|
91
|
+
|
82
92
|
|
83
93
|
if __name__ == '__main__':
|
84
94
|
unittest.main()
|
@@ -29,6 +29,21 @@ allergens that score 256, 512, 1024, etc.). Your program should
|
|
29
29
|
ignore those components of the score. For example, if the allergy
|
30
30
|
score is 257, your program should only report the eggs (1) allergy.
|
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.
|
@@ -31,6 +31,21 @@ a multi-digit number must not be zero.
|
|
31
31
|
|
32
32
|
Write a function to solve alphametics puzzles.
|
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.
|
@@ -6,6 +6,21 @@ Given `"listen"` and a list of candidates like `"enlists" "google"
|
|
6
6
|
"inlets" "banana"` the program should return a list containing
|
7
7
|
`"inlets"`.
|
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.
|
@@ -28,6 +28,21 @@ things based on word boundaries.
|
|
28
28
|
- Decoding `gvhg` gives `test`
|
29
29
|
- Decoding `gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt` gives `thequickbrownfoxjumpsoverthelazydog`
|
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.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# Beer Song
|
2
2
|
|
3
|
-
|
3
|
+
Recite the lyrics to that beloved classic, that field-trip favorite: 99 Bottles of Beer on the Wall.
|
4
4
|
|
5
5
|
Note that not all verses are identical.
|
6
6
|
|
@@ -320,6 +320,21 @@ are some additional things you could try:
|
|
320
320
|
Then please share your thoughts in a comment on the submission. Did this
|
321
321
|
experiment make the code better? Worse? Did you learn anything from it?
|
322
322
|
|
323
|
+
## Exception messages
|
324
|
+
|
325
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
326
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
327
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
328
|
+
a message.
|
329
|
+
|
330
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
331
|
+
`raise Exception`, you shold write:
|
332
|
+
|
333
|
+
```python
|
334
|
+
raise Exception("Meaningful message indicating the source of the error")
|
335
|
+
```
|
336
|
+
|
337
|
+
|
323
338
|
## Submitting Exercises
|
324
339
|
|
325
340
|
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|
@@ -53,6 +53,20 @@ And if we then added 1, 5, and 7, it would look like this
|
|
53
53
|
/ \ / \
|
54
54
|
1 3 5 7
|
55
55
|
|
56
|
+
## Exception messages
|
57
|
+
|
58
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
59
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
60
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
61
|
+
a message.
|
62
|
+
|
63
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
64
|
+
`raise Exception`, you shold write:
|
65
|
+
|
66
|
+
```python
|
67
|
+
raise Exception("Meaningful message indicating the source of the error")
|
68
|
+
```
|
69
|
+
|
56
70
|
|
57
71
|
## Submitting Exercises
|
58
72
|
|
@@ -65,7 +79,7 @@ please see the [help page](http://exercism.io/languages/python).
|
|
65
79
|
|
66
80
|
## Source
|
67
81
|
|
68
|
-
|
82
|
+
Josh Cheek [https://twitter.com/josh_cheek](https://twitter.com/josh_cheek)
|
69
83
|
|
70
84
|
## Submitting Incomplete Solutions
|
71
|
-
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
85
|
+
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
@@ -34,6 +34,21 @@ A binary search halves the number of items to check with each iteration,
|
|
34
34
|
so locating an item (or determining its absence) takes logarithmic time.
|
35
35
|
A binary search is a dichotomic divide and conquer search algorithm.
|
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.
|
@@ -29,21 +29,31 @@ class BinarySearchTests(unittest.TestCase):
|
|
29
29
|
5)
|
30
30
|
|
31
31
|
def test_identifies_value_missing(self):
|
32
|
-
with self.
|
32
|
+
with self.assertRaisesWithMessage(ValueError):
|
33
33
|
binary_search([1, 3, 4, 6, 8, 9, 11], 7)
|
34
34
|
|
35
35
|
def test_value_smaller_than_arrays_minimum(self):
|
36
|
-
with self.
|
36
|
+
with self.assertRaisesWithMessage(ValueError):
|
37
37
|
binary_search([1, 3, 4, 6, 8, 9, 11], 0)
|
38
38
|
|
39
39
|
def test_value_larger_than_arrays_maximum(self):
|
40
|
-
with self.
|
40
|
+
with self.assertRaisesWithMessage(ValueError):
|
41
41
|
binary_search([1, 3, 4, 6, 8, 9, 11], 13)
|
42
42
|
|
43
43
|
def test_empty_array(self):
|
44
|
-
with self.
|
44
|
+
with self.assertRaisesWithMessage(ValueError):
|
45
45
|
binary_search([], 1)
|
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()
|
@@ -30,6 +30,21 @@ Binary is similar, but uses powers of 2 rather than powers of 10.
|
|
30
30
|
|
31
31
|
So: `101 => 1*2^2 + 0*2^1 + 1*2^0 => 1*4 + 0*2 + 1*1 => 4 + 1 => 5 base 10`.
|
32
32
|
|
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
|
+
|
33
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.
|
@@ -32,21 +32,31 @@ class BinaryTests(unittest.TestCase):
|
|
32
32
|
self.assertEqual(parse_binary("10001101000"), 1128)
|
33
33
|
|
34
34
|
def test_invalid_binary_text_only(self):
|
35
|
-
with self.
|
35
|
+
with self.assertRaisesWithMessage(ValueError):
|
36
36
|
parse_binary("carrot")
|
37
37
|
|
38
38
|
def test_invalid_binary_number_not_base2(self):
|
39
|
-
with self.
|
39
|
+
with self.assertRaisesWithMessage(ValueError):
|
40
40
|
parse_binary("102011")
|
41
41
|
|
42
42
|
def test_invalid_binary_numbers_with_text(self):
|
43
|
-
with self.
|
43
|
+
with self.assertRaisesWithMessage(ValueError):
|
44
44
|
parse_binary("10nope")
|
45
45
|
|
46
46
|
def test_invalid_binary_text_with_numbers(self):
|
47
|
-
with self.
|
47
|
+
with self.assertRaisesWithMessage(ValueError):
|
48
48
|
parse_binary("nope10")
|
49
49
|
|
50
|
+
# Utility functions
|
51
|
+
def setUp(self):
|
52
|
+
try:
|
53
|
+
self.assertRaisesRegex = self.assertRaisesRegexp
|
54
|
+
except AttributeError:
|
55
|
+
pass
|
56
|
+
|
57
|
+
def assertRaisesWithMessage(self, exception):
|
58
|
+
return self.assertRaisesRegex(exception, r".+")
|
59
|
+
|
50
60
|
|
51
61
|
if __name__ == '__main__':
|
52
62
|
unittest.main()
|
@@ -11,6 +11,21 @@ anything.
|
|
11
11
|
|
12
12
|
He answers 'Whatever.' to anything else.
|
13
13
|
|
14
|
+
## Exception messages
|
15
|
+
|
16
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
17
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
18
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
19
|
+
a message.
|
20
|
+
|
21
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
22
|
+
`raise Exception`, you shold write:
|
23
|
+
|
24
|
+
```python
|
25
|
+
raise Exception("Meaningful message indicating the source of the error")
|
26
|
+
```
|
27
|
+
|
28
|
+
|
14
29
|
## Submitting Exercises
|
15
30
|
|
16
31
|
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|
@@ -67,6 +67,21 @@ For a total of $51.20
|
|
67
67
|
|
68
68
|
And $51.20 is the price with the biggest discount.
|
69
69
|
|
70
|
+
## Exception messages
|
71
|
+
|
72
|
+
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
73
|
+
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
74
|
+
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
75
|
+
a message.
|
76
|
+
|
77
|
+
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
78
|
+
`raise Exception`, you shold write:
|
79
|
+
|
80
|
+
```python
|
81
|
+
raise Exception("Meaningful message indicating the source of the error")
|
82
|
+
```
|
83
|
+
|
84
|
+
|
70
85
|
## Submitting Exercises
|
71
86
|
|
72
87
|
Note that, when trying to submit an exercise, make sure the solution is in the `exercism/python/<exerciseName>` directory.
|