trackler 2.0.8.27 → 2.0.8.28
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/common/exercises/simple-cipher/description.md +1 -1
- data/common/exercises/triangle/description.md +12 -23
- data/lib/trackler/version.rb +1 -1
- data/tracks/kotlin/config.json +5 -0
- data/tracks/kotlin/exercises/bank-account/build.gradle +32 -0
- data/tracks/kotlin/exercises/bank-account/src/example/kotlin/BankAccount.kt +27 -0
- data/tracks/kotlin/exercises/bank-account/src/main/kotlin/.keep +0 -0
- data/tracks/kotlin/exercises/bank-account/src/test/kotlin/BankAccountTest.kt +73 -0
- data/tracks/kotlin/exercises/settings.gradle +1 -0
- data/tracks/python/config.json +11 -11
- data/tracks/python/exercises/accumulate/accumulate_test.py +16 -14
- data/tracks/python/exercises/acronym/acronym_test.py +8 -7
- data/tracks/python/exercises/allergies/allergies_test.py +5 -6
- data/tracks/python/exercises/atbash-cipher/atbash_cipher_test.py +16 -22
- data/tracks/python/exercises/binary-search/binary_search_test.py +12 -10
- data/tracks/python/exercises/binary/binary_test.py +7 -8
- data/tracks/python/exercises/circular-buffer/circular_buffer_test.py +16 -17
- data/tracks/python/exercises/clock/clock_test.py +35 -35
- data/tracks/python/exercises/crypto-square/crypto_square_test.py +5 -6
- data/tracks/python/exercises/diamond/diamond_test.py +3 -4
- data/tracks/python/exercises/etl/etl_test.py +4 -4
- data/tracks/python/exercises/gigasecond/gigasecond_test.py +11 -19
- data/tracks/python/exercises/grade-school/grade_school_test.py +17 -19
- data/tracks/python/exercises/grains/grains_test.py +14 -14
- data/tracks/python/exercises/grep/grep_test.py +51 -64
- data/tracks/python/exercises/hamming/hamming_test.py +13 -13
- data/tracks/python/exercises/hello-world/hello_world_test.py +1 -2
- data/tracks/python/exercises/hexadecimal/hexadecimal_test.py +9 -10
- data/tracks/python/exercises/house/house_test.py +6 -6
- data/tracks/python/exercises/kindergarten-garden/kindergarten_garden_test.py +22 -19
- data/tracks/python/exercises/largest-series-product/largest_series_product_test.py +29 -28
- data/tracks/python/exercises/linked-list/linked_list_test.py +18 -19
- data/tracks/python/exercises/list-ops/list_ops_test.py +44 -39
- data/tracks/python/exercises/matrix/matrix_test.py +6 -6
- data/tracks/python/exercises/meetup/meetup_test.py +27 -27
- data/tracks/python/exercises/minesweeper/example.py +4 -2
- data/tracks/python/exercises/minesweeper/minesweeper_test.py +9 -9
- data/tracks/python/exercises/nucleotide-count/nucleotide_count_test.py +6 -6
- data/tracks/python/exercises/ocr-numbers/ocr_numbers_test.py +63 -49
- data/tracks/python/exercises/octal/octal_test.py +7 -7
- data/tracks/python/exercises/palindrome-products/palindrome_products_test.py +9 -9
- data/tracks/python/exercises/pascals-triangle/pascals_triangle_test.py +7 -7
- data/tracks/python/exercises/phone-number/phone_number_test.py +8 -8
- data/tracks/python/exercises/pig-latin/pig_latin_test.py +15 -15
- data/tracks/python/exercises/point-mutations/point_mutations_test.py +11 -11
- data/tracks/python/exercises/poker/poker_test.py +32 -30
- data/tracks/python/exercises/prime-factors/prime_factors_test.py +11 -11
- data/tracks/python/exercises/proverb/proverb_test.py +16 -9
- data/tracks/python/exercises/pythagorean-triplet/pythagorean_triplet_test.py +14 -12
- data/tracks/python/exercises/queen-attack/queen_attack_test.py +10 -10
- data/tracks/python/exercises/rail-fence-cipher/example.py +2 -1
- data/tracks/python/exercises/rail-fence-cipher/rail_fence_cipher_test.py +14 -13
- data/tracks/python/exercises/raindrops/raindrops_test.py +16 -16
- data/tracks/python/exercises/rectangles/rectangles_test.py +9 -9
- data/tracks/python/exercises/rna-transcription/rna_transcription_test.py +8 -8
- data/tracks/python/exercises/robot-name/robot_name_test.py +1 -1
- data/tracks/python/exercises/robot-simulator/robot_simulator_test.py +18 -19
- data/tracks/python/exercises/roman-numerals/roman_numerals_test.py +1 -1
- data/tracks/python/exercises/run-length-encoding/run_length_encoding_test.py +15 -16
- data/tracks/python/exercises/saddle-points/saddle_points_test.py +4 -4
- data/tracks/python/exercises/say/say_test.py +21 -23
- data/tracks/python/exercises/scrabble-score/scrabble_score_test.py +9 -9
- data/tracks/python/exercises/secret-handshake/secret_handshake_test.py +14 -13
- data/tracks/python/exercises/series/example.py +3 -3
- data/tracks/python/exercises/series/series_test.py +16 -12
- data/tracks/python/exercises/simple-cipher/simple_cipher_test.py +21 -19
- data/tracks/python/exercises/space-age/space_age_test.py +16 -16
- data/tracks/python/exercises/strain/strain_test.py +9 -8
- data/tracks/python/exercises/sublist/sublist_test.py +19 -20
- data/tracks/python/exercises/sum-of-multiples/example.py +1 -4
- data/tracks/python/exercises/sum-of-multiples/sum_of_multiples_test.py +31 -26
- data/tracks/python/exercises/triangle/triangle_test.py +15 -30
- data/tracks/python/exercises/trinary/trinary_test.py +7 -7
- data/tracks/python/exercises/twelve-days/twelve_days_test.py +13 -14
- data/tracks/python/exercises/word-count/example.py +1 -9
- data/tracks/python/exercises/word-count/word_count_test.py +0 -15
- data/tracks/python/exercises/wordy/wordy_test.py +17 -18
- data/tracks/python/exercises/zebra-puzzle/example.py +20 -23
- data/tracks/python/exercises/zebra-puzzle/zebra_puzzle_test.py +3 -3
- data/tracks/python/test/check-exercises.py +1 -1
- metadata +6 -2
@@ -1,7 +1,4 @@
|
|
1
|
-
def sum_of_multiples(limit, multiples
|
2
|
-
if multiples[0] == 0:
|
3
|
-
# multiples of 0 don't change the sum
|
4
|
-
multiples = multiples[1:]
|
1
|
+
def sum_of_multiples(limit, multiples):
|
5
2
|
return sum(value for value in range(limit)
|
6
3
|
if any(value % multiple == 0
|
7
4
|
for multiple in multiples))
|
@@ -1,10 +1,10 @@
|
|
1
1
|
"""
|
2
2
|
You can make the following assumptions about the inputs to the
|
3
3
|
'sum_of_multiples' function:
|
4
|
-
* All input numbers are non-negative 'int's, i.e. natural numbers
|
5
|
-
zero.
|
6
|
-
* A list of factors must be given, and its elements are unique
|
7
|
-
ascending order.
|
4
|
+
* All input numbers are non-negative 'int's, i.e. natural numbers
|
5
|
+
including zero.
|
6
|
+
* A list of factors must be given, and its elements are unique
|
7
|
+
and sorted in ascending order.
|
8
8
|
"""
|
9
9
|
|
10
10
|
import unittest
|
@@ -12,39 +12,44 @@ import unittest
|
|
12
12
|
from sum_of_multiples import sum_of_multiples
|
13
13
|
|
14
14
|
|
15
|
+
# test cases adapted from `x-common//canonical-data.json` @ version: 1.0.0
|
16
|
+
|
15
17
|
class SumOfMultiplesTest(unittest.TestCase):
|
16
|
-
def
|
17
|
-
self.assertEqual(
|
18
|
+
def test_multiples_of_3_or_5_up_to_1(self):
|
19
|
+
self.assertEqual(sum_of_multiples(1, [3, 5]), 0)
|
20
|
+
|
21
|
+
def test_multiples_of_3_or_5_up_to_4(self):
|
22
|
+
self.assertEqual(sum_of_multiples(4, [3, 5]), 3)
|
18
23
|
|
19
|
-
def
|
20
|
-
self.assertEqual(
|
24
|
+
def test_multiples_of_3_or_5_up_to_10(self):
|
25
|
+
self.assertEqual(sum_of_multiples(10, [3, 5]), 23)
|
21
26
|
|
22
|
-
def
|
23
|
-
self.assertEqual(
|
27
|
+
def test_multiples_of_3_or_5_up_to_100(self):
|
28
|
+
self.assertEqual(sum_of_multiples(100, [3, 5]), 2318)
|
24
29
|
|
25
|
-
def
|
26
|
-
self.assertEqual(
|
30
|
+
def test_multiples_of_3_or_5_up_to_1000(self):
|
31
|
+
self.assertEqual(sum_of_multiples(1000, [3, 5]), 233168)
|
27
32
|
|
28
|
-
def
|
29
|
-
self.assertEqual(
|
33
|
+
def test_multiples_of_7_13_or_17_up_to_20(self):
|
34
|
+
self.assertEqual(sum_of_multiples(20, [7, 13, 17]), 51)
|
30
35
|
|
31
|
-
def
|
32
|
-
self.assertEqual(
|
36
|
+
def test_multiples_of_4_or_6_up_to_15(self):
|
37
|
+
self.assertEqual(sum_of_multiples(15, [4, 6]), 30)
|
33
38
|
|
34
|
-
def
|
35
|
-
self.assertEqual(
|
39
|
+
def test_multiples_of_5_6_or_8_up_to_150(self):
|
40
|
+
self.assertEqual(sum_of_multiples(150, [5, 6, 8]), 4419)
|
36
41
|
|
37
|
-
def
|
38
|
-
self.assertEqual(
|
42
|
+
def test_multiples_of_5_or_25_up_to_51(self):
|
43
|
+
self.assertEqual(sum_of_multiples(51, [5, 25]), 275)
|
39
44
|
|
40
|
-
def
|
41
|
-
self.assertEqual(
|
45
|
+
def test_multiples_of_43_or_47_up_to_10000(self):
|
46
|
+
self.assertEqual(sum_of_multiples(10000, [43, 47]), 2203160)
|
42
47
|
|
43
|
-
def
|
44
|
-
self.assertEqual(
|
48
|
+
def test_multiples_of_1_up_to_100(self):
|
49
|
+
self.assertEqual(sum_of_multiples(100, [1]), 4950)
|
45
50
|
|
46
|
-
def
|
47
|
-
self.assertEqual(
|
51
|
+
def test_multiples_of_an_empty_list_up_to_10000(self):
|
52
|
+
self.assertEqual(sum_of_multiples(10000, []), 0)
|
48
53
|
|
49
54
|
|
50
55
|
if __name__ == '__main__':
|
@@ -5,63 +5,48 @@ from triangle import Triangle, TriangleError
|
|
5
5
|
|
6
6
|
class TriangleTests(unittest.TestCase):
|
7
7
|
def test_equilateral_triangles_have_equal_sides(self):
|
8
|
-
self.assertEqual(
|
8
|
+
self.assertEqual(Triangle(2, 2, 2).kind(), "equilateral")
|
9
9
|
|
10
10
|
def test_larger_equilateral_triangles_also_have_equal_sides(self):
|
11
|
-
self.assertEqual(
|
11
|
+
self.assertEqual(Triangle(10, 10, 10).kind(), "equilateral")
|
12
12
|
|
13
13
|
def test_isosceles_triangles_have_last_two_sides_equal(self):
|
14
|
-
self.assertEqual(
|
14
|
+
self.assertEqual(Triangle(3, 4, 4).kind(), "isosceles")
|
15
15
|
|
16
16
|
def test_isosceles_triangles_have_first_and_last_sides_equal(self):
|
17
|
-
self.assertEqual(
|
17
|
+
self.assertEqual(Triangle(4, 3, 4).kind(), "isosceles")
|
18
18
|
|
19
19
|
def test_isosceles_triangles_have_two_first_sides_equal(self):
|
20
|
-
self.assertEqual(
|
20
|
+
self.assertEqual(Triangle(4, 4, 3).kind(), "isosceles")
|
21
21
|
|
22
22
|
def test_isosceles_triangles_have_in_fact_exactly_two_sides_equal(self):
|
23
|
-
self.assertEqual(
|
23
|
+
self.assertEqual(Triangle(10, 10, 2).kind(), "isosceles")
|
24
24
|
|
25
25
|
def test_scalene_triangles_have_no_equal_sides(self):
|
26
|
-
self.assertEqual(
|
26
|
+
self.assertEqual(Triangle(3, 4, 5).kind(), "scalene")
|
27
27
|
|
28
28
|
def test_scalene_triangles_have_no_equal_sides_at_a_larger_scale_too(self):
|
29
|
-
self.assertEqual(
|
29
|
+
self.assertEqual(Triangle(10, 11, 12).kind(), "scalene")
|
30
30
|
|
31
|
-
self.assertEqual(
|
31
|
+
self.assertEqual(Triangle(5, 4, 2).kind(), "scalene")
|
32
32
|
|
33
33
|
def test_very_small_triangles_are_legal(self):
|
34
|
-
self.assertEqual(
|
34
|
+
self.assertEqual(Triangle(0.4, 0.6, 0.3).kind(), "scalene")
|
35
35
|
|
36
36
|
def test_triangles_with_no_size_are_illegal(self):
|
37
|
-
self.assertRaises(
|
38
|
-
TriangleError,
|
39
|
-
Triangle, 0, 0, 0
|
40
|
-
)
|
37
|
+
self.assertRaises(TriangleError, Triangle, 0, 0, 0)
|
41
38
|
|
42
39
|
def test_triangles_with_negative_sides_are_illegal(self):
|
43
|
-
self.assertRaises(
|
44
|
-
TriangleError,
|
45
|
-
Triangle, 3, 4, -5
|
46
|
-
)
|
40
|
+
self.assertRaises(TriangleError, Triangle, 3, 4, -5)
|
47
41
|
|
48
42
|
def test_triangles_violating_triangle_inequality_are_illegal(self):
|
49
|
-
self.assertRaises(
|
50
|
-
TriangleError,
|
51
|
-
Triangle, 1, 1, 3
|
52
|
-
)
|
43
|
+
self.assertRaises(TriangleError, Triangle, 1, 1, 3)
|
53
44
|
|
54
45
|
def test_triangles_violating_triangle_inequality_are_illegal_2(self):
|
55
|
-
self.assertRaises(
|
56
|
-
TriangleError,
|
57
|
-
Triangle, 2, 4, 2
|
58
|
-
)
|
46
|
+
self.assertRaises(TriangleError, Triangle, 2, 4, 2)
|
59
47
|
|
60
48
|
def test_triangles_violating_triangle_inequality_are_illegal_3(self):
|
61
|
-
self.assertRaises(
|
62
|
-
TriangleError,
|
63
|
-
Triangle, 7, 3, 2
|
64
|
-
)
|
49
|
+
self.assertRaises(TriangleError, Triangle, 7, 3, 2)
|
65
50
|
|
66
51
|
|
67
52
|
if __name__ == '__main__':
|
@@ -5,25 +5,25 @@ from trinary import trinary
|
|
5
5
|
|
6
6
|
class TrinaryTest(unittest.TestCase):
|
7
7
|
def test_valid_trinary1(self):
|
8
|
-
self.assertEqual(
|
8
|
+
self.assertEqual(trinary('0'), 0)
|
9
9
|
|
10
10
|
def test_valid_trinary2(self):
|
11
|
-
self.assertEqual(
|
11
|
+
self.assertEqual(trinary('1'), 1)
|
12
12
|
|
13
13
|
def test_valid_trinary3(self):
|
14
|
-
self.assertEqual(
|
14
|
+
self.assertEqual(trinary('10'), 3)
|
15
15
|
|
16
16
|
def test_valid_trinary4(self):
|
17
|
-
self.assertEqual(
|
17
|
+
self.assertEqual(trinary('102101'), 307)
|
18
18
|
|
19
19
|
def test_valid_trinary5(self):
|
20
|
-
self.assertEqual(
|
20
|
+
self.assertEqual(trinary('22222'), 242)
|
21
21
|
|
22
22
|
def test_valid_trinary6(self):
|
23
|
-
self.assertEqual(
|
23
|
+
self.assertEqual(trinary('10000'), 81)
|
24
24
|
|
25
25
|
def test_invalid_trinary(self):
|
26
|
-
self.assertEqual(
|
26
|
+
self.assertEqual(trinary('13201'), 0)
|
27
27
|
|
28
28
|
|
29
29
|
if __name__ == '__main__':
|
@@ -4,24 +4,23 @@ from twelve_days import sing, verse, verses
|
|
4
4
|
|
5
5
|
|
6
6
|
class TwelveDaysTests(unittest.TestCase):
|
7
|
-
|
8
7
|
def test_verse1(self):
|
9
8
|
expected = ("On the first day of Christmas my true love gave to me, "
|
10
9
|
"a Partridge in a Pear Tree.\n")
|
11
|
-
self.assertEqual(
|
10
|
+
self.assertEqual(verse(1), expected)
|
12
11
|
|
13
12
|
def test_verse2(self):
|
14
13
|
expected = ("On the second day of Christmas my true love gave to me, "
|
15
14
|
"two Turtle Doves, "
|
16
15
|
"and a Partridge in a Pear Tree.\n")
|
17
|
-
self.assertEqual(
|
16
|
+
self.assertEqual(verse(2), expected)
|
18
17
|
|
19
18
|
def test_verse3(self):
|
20
19
|
expected = ("On the third day of Christmas my true love gave to me, "
|
21
20
|
"three French Hens, "
|
22
21
|
"two Turtle Doves, "
|
23
22
|
"and a Partridge in a Pear Tree.\n")
|
24
|
-
self.assertEqual(
|
23
|
+
self.assertEqual(verse(3), expected)
|
25
24
|
|
26
25
|
def test_verse4(self):
|
27
26
|
expected = ("On the fourth day of Christmas my true love gave to me, "
|
@@ -29,7 +28,7 @@ class TwelveDaysTests(unittest.TestCase):
|
|
29
28
|
"three French Hens, "
|
30
29
|
"two Turtle Doves, "
|
31
30
|
"and a Partridge in a Pear Tree.\n")
|
32
|
-
self.assertEqual(
|
31
|
+
self.assertEqual(verse(4), expected)
|
33
32
|
|
34
33
|
def test_verse5(self):
|
35
34
|
expected = ("On the fifth day of Christmas my true love gave to me, "
|
@@ -38,7 +37,7 @@ class TwelveDaysTests(unittest.TestCase):
|
|
38
37
|
"three French Hens, "
|
39
38
|
"two Turtle Doves, "
|
40
39
|
"and a Partridge in a Pear Tree.\n")
|
41
|
-
self.assertEqual(
|
40
|
+
self.assertEqual(verse(5), expected)
|
42
41
|
|
43
42
|
def test_verse6(self):
|
44
43
|
expected = ("On the sixth day of Christmas my true love gave to me, "
|
@@ -48,7 +47,7 @@ class TwelveDaysTests(unittest.TestCase):
|
|
48
47
|
"three French Hens, "
|
49
48
|
"two Turtle Doves, "
|
50
49
|
"and a Partridge in a Pear Tree.\n")
|
51
|
-
self.assertEqual(
|
50
|
+
self.assertEqual(verse(6), expected)
|
52
51
|
|
53
52
|
def test_verse7(self):
|
54
53
|
expected = ("On the seventh day of Christmas my true love gave to me, "
|
@@ -59,7 +58,7 @@ class TwelveDaysTests(unittest.TestCase):
|
|
59
58
|
"three French Hens, "
|
60
59
|
"two Turtle Doves, "
|
61
60
|
"and a Partridge in a Pear Tree.\n")
|
62
|
-
self.assertEqual(
|
61
|
+
self.assertEqual(verse(7), expected)
|
63
62
|
|
64
63
|
def test_verse8(self):
|
65
64
|
expected = ("On the eighth day of Christmas my true love gave to me, "
|
@@ -71,7 +70,7 @@ class TwelveDaysTests(unittest.TestCase):
|
|
71
70
|
"three French Hens, "
|
72
71
|
"two Turtle Doves, "
|
73
72
|
"and a Partridge in a Pear Tree.\n")
|
74
|
-
self.assertEqual(
|
73
|
+
self.assertEqual(verse(8), expected)
|
75
74
|
|
76
75
|
def test_verse9(self):
|
77
76
|
expected = ("On the ninth day of Christmas my true love gave to me, "
|
@@ -84,7 +83,7 @@ class TwelveDaysTests(unittest.TestCase):
|
|
84
83
|
"three French Hens, "
|
85
84
|
"two Turtle Doves, "
|
86
85
|
"and a Partridge in a Pear Tree.\n")
|
87
|
-
self.assertEqual(
|
86
|
+
self.assertEqual(verse(9), expected)
|
88
87
|
|
89
88
|
def test_verse10(self):
|
90
89
|
expected = ("On the tenth day of Christmas my true love gave to me, "
|
@@ -98,7 +97,7 @@ class TwelveDaysTests(unittest.TestCase):
|
|
98
97
|
"three French Hens, "
|
99
98
|
"two Turtle Doves, "
|
100
99
|
"and a Partridge in a Pear Tree.\n")
|
101
|
-
self.assertEqual(
|
100
|
+
self.assertEqual(verse(10), expected)
|
102
101
|
|
103
102
|
def test_verse11(self):
|
104
103
|
expected = ("On the eleventh day of Christmas "
|
@@ -114,7 +113,7 @@ class TwelveDaysTests(unittest.TestCase):
|
|
114
113
|
"three French Hens, "
|
115
114
|
"two Turtle Doves, "
|
116
115
|
"and a Partridge in a Pear Tree.\n")
|
117
|
-
self.assertEqual(
|
116
|
+
self.assertEqual(verse(11), expected)
|
118
117
|
|
119
118
|
def test_verse12(self):
|
120
119
|
expected = ("On the twelfth day of Christmas my true love gave to me, "
|
@@ -130,7 +129,7 @@ class TwelveDaysTests(unittest.TestCase):
|
|
130
129
|
"three French Hens, "
|
131
130
|
"two Turtle Doves, "
|
132
131
|
"and a Partridge in a Pear Tree.\n")
|
133
|
-
self.assertEqual(
|
132
|
+
self.assertEqual(verse(12), expected)
|
134
133
|
|
135
134
|
def test_multiple_verses(self):
|
136
135
|
expected = ("On the first day of Christmas my true love gave to me, "
|
@@ -142,7 +141,7 @@ class TwelveDaysTests(unittest.TestCase):
|
|
142
141
|
"three French Hens, "
|
143
142
|
"two Turtle Doves, "
|
144
143
|
"and a Partridge in a Pear Tree.\n\n")
|
145
|
-
self.assertEqual(
|
144
|
+
self.assertEqual(verses(1, 3), expected)
|
146
145
|
|
147
146
|
def test_the_whole_song(self):
|
148
147
|
self.assertEqual(verses(1, 12), sing())
|
@@ -1,16 +1,8 @@
|
|
1
1
|
from collections import Counter
|
2
2
|
|
3
3
|
|
4
|
-
# to be backwards compatible with the old Python 2.X
|
5
|
-
def decode_if_needed(string):
|
6
|
-
try:
|
7
|
-
return string.decode('utf-8')
|
8
|
-
except AttributeError:
|
9
|
-
return string
|
10
|
-
|
11
|
-
|
12
4
|
def word_count(text):
|
13
5
|
def replace_nonalpha(char):
|
14
6
|
return char.lower() if char.isalnum() else ' '
|
15
|
-
text = ''.join(replace_nonalpha(c) for c in
|
7
|
+
text = ''.join(replace_nonalpha(c) for c in text)
|
16
8
|
return Counter(text.split())
|
@@ -1,17 +1,8 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
1
|
import unittest
|
3
2
|
|
4
3
|
from word_count import word_count
|
5
4
|
|
6
5
|
|
7
|
-
# to be backwards compatible with the old Python 2.X
|
8
|
-
def decode_if_needed(string):
|
9
|
-
try:
|
10
|
-
return string.decode('utf-8')
|
11
|
-
except AttributeError:
|
12
|
-
return string
|
13
|
-
|
14
|
-
|
15
6
|
class WordCountTests(unittest.TestCase):
|
16
7
|
|
17
8
|
def test_count_one_word(self):
|
@@ -78,12 +69,6 @@ class WordCountTests(unittest.TestCase):
|
|
78
69
|
word_count('hey,my_spacebar_is_broken.')
|
79
70
|
)
|
80
71
|
|
81
|
-
def test_unicode(self):
|
82
|
-
self.assertEqual(
|
83
|
-
{decode_if_needed('до'): 1, decode_if_needed('свидания'): 1},
|
84
|
-
word_count('до🖖свидания!')
|
85
|
-
)
|
86
|
-
|
87
72
|
|
88
73
|
if __name__ == '__main__':
|
89
74
|
unittest.main()
|
@@ -4,50 +4,49 @@ from wordy import calculate
|
|
4
4
|
|
5
5
|
|
6
6
|
class WordyTest(unittest.TestCase):
|
7
|
-
|
8
7
|
def test_simple_add_1(self):
|
9
|
-
self.assertEqual(
|
8
|
+
self.assertEqual(calculate("What is 5 plus 13?"), 18)
|
10
9
|
|
11
10
|
def test_simple_add_2(self):
|
12
|
-
self.assertEqual(
|
11
|
+
self.assertEqual(calculate("What is 5 plus -13?"), -8)
|
13
12
|
|
14
13
|
def test_simple_sub_1(self):
|
15
|
-
self.assertEqual(
|
14
|
+
self.assertEqual(calculate("What is 103 minus 97?"), 6)
|
16
15
|
|
17
16
|
def test_simple_sub_2(self):
|
18
|
-
self.assertEqual(
|
17
|
+
self.assertEqual(calculate("What is 97 minus 103?"), -6)
|
19
18
|
|
20
19
|
def test_simple_mult(self):
|
21
|
-
self.assertEqual(
|
20
|
+
self.assertEqual(calculate("What is 7 multiplied by 3?"), 21)
|
22
21
|
|
23
22
|
def test_simple_div(self):
|
24
|
-
self.assertEqual(
|
23
|
+
self.assertEqual(calculate("What is 45 divided by 5?"), 9)
|
25
24
|
|
26
25
|
def test_add_negative_numbers(self):
|
27
|
-
self.assertEqual(
|
26
|
+
self.assertEqual(calculate("What is -1 plus -10?"), -11)
|
28
27
|
|
29
28
|
def test_add_more_digits(self):
|
30
|
-
self.assertEqual(
|
29
|
+
self.assertEqual(calculate("What is 123 plus 45678?"), 45801)
|
31
30
|
|
32
31
|
def test_add_twice(self):
|
33
|
-
self.assertEqual(
|
32
|
+
self.assertEqual(calculate("What is 1 plus 2 plus 1?"), 4)
|
34
33
|
|
35
34
|
def test_add_then_subtract(self):
|
36
|
-
self.assertEqual(
|
35
|
+
self.assertEqual(calculate("What is 1 plus 5 minus -8?"), 14)
|
37
36
|
|
38
37
|
def test_subtract_twice(self):
|
39
|
-
self.assertEqual(
|
38
|
+
self.assertEqual(calculate("What is 20 minus 14 minus 13?"), -7)
|
40
39
|
|
41
40
|
def test_multiply_twice(self):
|
42
|
-
self.assertEqual(
|
43
|
-
|
41
|
+
self.assertEqual(
|
42
|
+
calculate("What is 2 multiplied by -2 multiplied by 3?"), -12)
|
44
43
|
|
45
44
|
def test_add_then_multiply(self):
|
46
|
-
self.assertEqual(
|
45
|
+
self.assertEqual(calculate("What is -3 plus 7 multiplied by -2?"), -8)
|
47
46
|
|
48
47
|
def test_divide_twice(self):
|
49
48
|
self.assertEqual(
|
50
|
-
|
49
|
+
calculate("What is -12000 divided by 25 divided by -30?"), 16)
|
51
50
|
|
52
51
|
def test_invalid_operation(self):
|
53
52
|
self.assertRaises(ValueError, calculate, "What is 4 xor 7?")
|
@@ -56,8 +55,8 @@ class WordyTest(unittest.TestCase):
|
|
56
55
|
self.assertRaises(ValueError, calculate, "What is 2 2 minus 3?")
|
57
56
|
|
58
57
|
def test_missing_number(self):
|
59
|
-
self.assertRaises(ValueError, calculate,
|
60
|
-
|
58
|
+
self.assertRaises(ValueError, calculate,
|
59
|
+
"What is 7 plus multiplied by -2?")
|
61
60
|
|
62
61
|
def test_irrelevant_question(self):
|
63
62
|
self.assertRaises(ValueError, calculate, "Which is greater, 3 or 2?")
|
@@ -17,28 +17,25 @@ def next_to(x, y):
|
|
17
17
|
def solution():
|
18
18
|
houses = first, _, middle, _, _ = range(5)
|
19
19
|
orderings = list(permutations(houses))
|
20
|
-
result = next(
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
if OldGold is snails
|
41
|
-
if next_to(Chesterfields, fox)
|
42
|
-
if next_to(Kools, horse))
|
20
|
+
result = next(
|
21
|
+
[{
|
22
|
+
Englishman: "Englishman",
|
23
|
+
Spaniard: "Spaniard",
|
24
|
+
Ukranian: "Ukranian",
|
25
|
+
Japanese: "Japanese",
|
26
|
+
Norwegian: "Norwegian"
|
27
|
+
}[x] for x in (water, zebra)]
|
28
|
+
for (red, green, ivory, yellow, blue) in orderings
|
29
|
+
if just_right_of(green, ivory)
|
30
|
+
for (Englishman, Spaniard, Ukranian, Japanese, Norwegian) in orderings
|
31
|
+
if Englishman is red if Norwegian is first if next_to(Norwegian, blue)
|
32
|
+
for (coffee, tea, milk, oj, water) in orderings if coffee is green
|
33
|
+
if Ukranian is tea if milk is middle
|
34
|
+
for (OldGold, Kools, Chesterfields, LuckyStrike, Parliaments
|
35
|
+
) in orderings if Kools is yellow if LuckyStrike is oj
|
36
|
+
if Japanese is Parliaments
|
37
|
+
for (dog, snails, fox, horse, zebra) in orderings if Spaniard is dog
|
38
|
+
if OldGold is snails if next_to(Chesterfields, fox)
|
39
|
+
if next_to(Kools, horse))
|
43
40
|
return ("It is the {} who drinks the water.\n"
|
44
41
|
"The {} keeps the zebra.").format(*result)
|