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