trackler 2.0.8.27 → 2.0.8.28
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -4,51 +4,49 @@ from say import say
|
|
4
4
|
|
5
5
|
|
6
6
|
class SayTest(unittest.TestCase):
|
7
|
-
|
8
7
|
def test_one(self):
|
9
|
-
self.assertEqual(
|
8
|
+
self.assertEqual(say(1), "one")
|
10
9
|
|
11
10
|
def test_fourteen(self):
|
12
|
-
self.assertEqual(
|
11
|
+
self.assertEqual(say(14), "fourteen")
|
13
12
|
|
14
13
|
def test_twenty(self):
|
15
|
-
self.assertEqual(
|
14
|
+
self.assertEqual(say(20), "twenty")
|
16
15
|
|
17
16
|
def test_twenty_two(self):
|
18
|
-
self.assertEqual("twenty-two"
|
17
|
+
self.assertEqual(say(22), "twenty-two")
|
19
18
|
|
20
19
|
def test_one_hundred(self):
|
21
|
-
self.assertEqual("one hundred"
|
20
|
+
self.assertEqual(say(100), "one hundred")
|
22
21
|
|
23
22
|
def test_one_hundred_twenty(self):
|
24
|
-
self.assertEqual("one hundred and twenty"
|
23
|
+
self.assertEqual(say(120), "one hundred and twenty")
|
25
24
|
|
26
25
|
def test_one_hundred_twenty_three(self):
|
27
|
-
self.assertEqual("one hundred and twenty-three"
|
26
|
+
self.assertEqual(say(123), "one hundred and twenty-three")
|
28
27
|
|
29
28
|
def test_one_thousand(self):
|
30
|
-
self.assertEqual("one thousand"
|
29
|
+
self.assertEqual(say(1000), "one thousand")
|
31
30
|
|
32
31
|
def test_one_thousand_two_hundred_thirty_four(self):
|
33
|
-
self.assertEqual("one thousand two hundred and thirty-four"
|
34
|
-
say(1234))
|
32
|
+
self.assertEqual(say(1234), "one thousand two hundred and thirty-four")
|
35
33
|
|
36
34
|
def test_eight_hundred_and_ten_thousand(self):
|
37
|
-
self.assertEqual("eight hundred and ten thousand"
|
35
|
+
self.assertEqual(say(810000), "eight hundred and ten thousand")
|
38
36
|
|
39
37
|
def test_one_million(self):
|
40
|
-
self.assertEqual("one million"
|
38
|
+
self.assertEqual(say(1e6), "one million")
|
41
39
|
|
42
40
|
def test_one_million_two(self):
|
43
|
-
self.assertEqual("one million and two"
|
41
|
+
self.assertEqual(say(1000002), "one million and two")
|
44
42
|
|
45
43
|
def test_1002345(self):
|
46
44
|
self.assertEqual(
|
47
|
-
|
48
|
-
|
45
|
+
say(1002345),
|
46
|
+
"one million two thousand three hundred and forty-five")
|
49
47
|
|
50
48
|
def test_one_billion(self):
|
51
|
-
self.assertEqual("one billion"
|
49
|
+
self.assertEqual(say(1e9), "one billion")
|
52
50
|
|
53
51
|
def test_number_to_large(self):
|
54
52
|
with self.assertRaises(AttributeError):
|
@@ -59,14 +57,14 @@ class SayTest(unittest.TestCase):
|
|
59
57
|
say(-42)
|
60
58
|
|
61
59
|
def test_zero(self):
|
62
|
-
self.assertEqual(
|
60
|
+
self.assertEqual(say(0), "zero")
|
63
61
|
|
64
62
|
def test_987654321123(self):
|
65
|
-
self.assertEqual(
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
63
|
+
self.assertEqual(
|
64
|
+
say(987654321123), ("nine hundred and eighty-seven billion "
|
65
|
+
"six hundred and fifty-four million "
|
66
|
+
"three hundred and twenty-one thousand "
|
67
|
+
"one hundred and twenty-three"))
|
70
68
|
|
71
69
|
|
72
70
|
if __name__ == '__main__':
|
@@ -5,25 +5,25 @@ from scrabble_score import score
|
|
5
5
|
|
6
6
|
class WordTest(unittest.TestCase):
|
7
7
|
def test_invalid_word_scores_zero(self):
|
8
|
-
self.assertEqual(
|
9
|
-
self.assertEqual(
|
10
|
-
self.assertEqual(
|
11
|
-
self.assertEqual(
|
8
|
+
self.assertEqual(score(''), 0)
|
9
|
+
self.assertEqual(score(' \t\n'), 0)
|
10
|
+
self.assertEqual(score('hous3'), 0)
|
11
|
+
self.assertEqual(score('wo rd'), 0)
|
12
12
|
|
13
13
|
def test_scores_very_short_word(self):
|
14
|
-
self.assertEqual(
|
14
|
+
self.assertEqual(score('a'), 1)
|
15
15
|
|
16
16
|
def test_scores_other_very_short_word(self):
|
17
|
-
self.assertEqual(
|
17
|
+
self.assertEqual(score('f'), 4)
|
18
18
|
|
19
19
|
def test_simple_word_scores_the_number_of_letters(self):
|
20
|
-
self.assertEqual(
|
20
|
+
self.assertEqual(score("street"), 6)
|
21
21
|
|
22
22
|
def test_complicated_word_scores_more(self):
|
23
|
-
self.assertEqual(
|
23
|
+
self.assertEqual(score("quirky"), 22)
|
24
24
|
|
25
25
|
def test_scores_are_case_insensitive(self):
|
26
|
-
self.assertEqual(
|
26
|
+
self.assertEqual(score("OxyphenButazone"), 41)
|
27
27
|
|
28
28
|
|
29
29
|
if __name__ == '__main__':
|
@@ -5,44 +5,45 @@ from secret_handshake import handshake, code
|
|
5
5
|
|
6
6
|
class HandshakeTest(unittest.TestCase):
|
7
7
|
def test_shake_int(self):
|
8
|
-
self.assertEqual(['wink', 'jump']
|
8
|
+
self.assertEqual(handshake(9), ['wink', 'jump'])
|
9
9
|
|
10
10
|
def test_shake_bin1(self):
|
11
|
-
self.assertEqual(
|
11
|
+
self.assertEqual(
|
12
|
+
handshake('10110'), ['close your eyes', 'double blink'])
|
12
13
|
|
13
14
|
def test_shake_bin2(self):
|
14
|
-
self.assertEqual(['wink', 'close your eyes']
|
15
|
+
self.assertEqual(handshake('101'), ['wink', 'close your eyes'])
|
15
16
|
|
16
17
|
def test_shake_negative_int(self):
|
17
|
-
self.assertEqual(
|
18
|
+
self.assertEqual(handshake(-9), [])
|
18
19
|
|
19
20
|
def test_shake_bin_invalid(self):
|
20
|
-
self.assertEqual(
|
21
|
+
self.assertEqual(handshake('121'), [])
|
21
22
|
|
22
23
|
def test_unknown_action(self):
|
23
|
-
self.assertEqual(
|
24
|
+
self.assertEqual(code(['wink', 'sneeze']), '0')
|
24
25
|
|
25
26
|
def test_code1(self):
|
26
|
-
self.assertEqual(
|
27
|
+
self.assertEqual(code(['close your eyes', 'jump']), '1100')
|
27
28
|
|
28
29
|
def test_code2(self):
|
29
|
-
self.assertEqual(
|
30
|
+
self.assertEqual(code(['wink', 'double blink']), '11')
|
30
31
|
|
31
32
|
def test_code3(self):
|
32
|
-
self.assertEqual(
|
33
|
+
self.assertEqual(code(['jump', 'double blink']), '11010')
|
33
34
|
|
34
35
|
def test_composition1(self):
|
35
|
-
self.assertEqual(
|
36
|
+
self.assertEqual(code(handshake(27)), '11011')
|
36
37
|
|
37
38
|
def test_composition2(self):
|
38
|
-
self.assertEqual(
|
39
|
+
self.assertEqual(code(handshake(1)), '1')
|
39
40
|
|
40
41
|
def test_composition3(self):
|
41
|
-
self.assertEqual(
|
42
|
+
self.assertEqual(code(handshake('111')), '111')
|
42
43
|
|
43
44
|
def test_composition4(self):
|
44
45
|
inp = ['wink', 'double blink', 'jump']
|
45
|
-
self.assertEqual(
|
46
|
+
self.assertEqual(handshake(code(inp)), inp)
|
46
47
|
|
47
48
|
|
48
49
|
if __name__ == '__main__':
|
@@ -1,6 +1,6 @@
|
|
1
1
|
def slices(series, length):
|
2
2
|
numbers = [int(digit) for digit in series]
|
3
3
|
if not 1 <= length <= len(numbers):
|
4
|
-
raise ValueError("Invalid slice length for this series: " + str(
|
5
|
-
|
6
|
-
|
4
|
+
raise ValueError("Invalid slice length for this series: " + str(
|
5
|
+
length))
|
6
|
+
return [numbers[i:i + length] for i in range(len(numbers) - length + 1)]
|
@@ -11,26 +11,30 @@ from series import slices
|
|
11
11
|
|
12
12
|
class SeriesTest(unittest.TestCase):
|
13
13
|
def test_slices_of_one(self):
|
14
|
-
self.assertEqual(
|
15
|
-
|
14
|
+
self.assertEqual(
|
15
|
+
slices("01234", 1),
|
16
|
+
[[0], [1], [2], [3], [4]], )
|
16
17
|
|
17
18
|
def test_slices_of_two(self):
|
18
|
-
self.assertEqual(
|
19
|
-
|
20
|
-
|
19
|
+
self.assertEqual(
|
20
|
+
slices("97867564", 2),
|
21
|
+
[[9, 7], [7, 8], [8, 6], [6, 7], [7, 5], [5, 6], [6, 4]], )
|
21
22
|
|
22
23
|
def test_slices_of_three(self):
|
23
|
-
self.assertEqual(
|
24
|
-
|
25
|
-
|
24
|
+
self.assertEqual(
|
25
|
+
slices("97867564", 3),
|
26
|
+
[[9, 7, 8], [7, 8, 6], [8, 6, 7], [6, 7, 5], [7, 5, 6], [5, 6, 4]],
|
27
|
+
)
|
26
28
|
|
27
29
|
def test_slices_of_four(self):
|
28
|
-
self.assertEqual(
|
29
|
-
|
30
|
+
self.assertEqual(
|
31
|
+
slices("01234", 4),
|
32
|
+
[[0, 1, 2, 3], [1, 2, 3, 4]], )
|
30
33
|
|
31
34
|
def test_slices_of_five(self):
|
32
|
-
self.assertEqual(
|
33
|
-
|
35
|
+
self.assertEqual(
|
36
|
+
slices("01234", 5),
|
37
|
+
[[0, 1, 2, 3, 4]], )
|
34
38
|
|
35
39
|
def test_overly_long_slice(self):
|
36
40
|
with self.assertRaises(ValueError):
|
@@ -4,64 +4,66 @@ from simple_cipher import Caesar, Cipher
|
|
4
4
|
|
5
5
|
|
6
6
|
class CipherTest(unittest.TestCase):
|
7
|
-
|
8
7
|
def test_caesar_encode1(self):
|
9
|
-
self.assertEqual('
|
10
|
-
|
8
|
+
self.assertEqual(Caesar().encode('itisawesomeprogramminginpython'),
|
9
|
+
'lwlvdzhvrphsurjudpplqjlqsbwkrq')
|
11
10
|
|
12
11
|
def test_caesar_encode2(self):
|
13
|
-
self.assertEqual(
|
12
|
+
self.assertEqual(Caesar().encode('venividivici'), 'yhqlylglylfl')
|
14
13
|
|
15
14
|
def test_caesar_encode3(self):
|
16
|
-
self.assertEqual('
|
17
|
-
|
15
|
+
self.assertEqual(Caesar().encode('\'Twas the night before Christmas'),
|
16
|
+
'wzdvwkhqljkwehiruhfkulvwpdv')
|
18
17
|
|
19
18
|
def test_caesar_encode_with_numbers(self):
|
20
|
-
self.assertEqual(
|
19
|
+
self.assertEqual(Caesar().encode('1, 2, 3, Go!'), 'jr')
|
21
20
|
|
22
21
|
def test_caesar_decode(self):
|
23
|
-
self.assertEqual(
|
22
|
+
self.assertEqual(Caesar().decode('yhqlylglylfl'), 'venividivici')
|
24
23
|
|
25
24
|
def test_cipher_encode1(self):
|
26
25
|
c = Cipher('a')
|
27
|
-
self.assertEqual(
|
28
|
-
|
26
|
+
self.assertEqual(
|
27
|
+
c.encode('itisawesomeprogramminginpython'),
|
28
|
+
'itisawesomeprogramminginpython')
|
29
29
|
|
30
30
|
def test_cipher_encode2(self):
|
31
31
|
c = Cipher('aaaaaaaaaaaaaaaaaaaaaa')
|
32
|
-
self.assertEqual(
|
33
|
-
|
32
|
+
self.assertEqual(
|
33
|
+
c.encode('itisawesomeprogramminginpython'),
|
34
|
+
'itisawesomeprogramminginpython')
|
34
35
|
|
35
36
|
def test_cipher_encode3(self):
|
36
37
|
c = Cipher('dddddddddddddddddddddd')
|
37
|
-
self.assertEqual(
|
38
|
+
self.assertEqual(c.encode('venividivici'), 'yhqlylglylfl')
|
38
39
|
|
39
40
|
def test_cipher_encode4(self):
|
40
41
|
key = ('duxrceqyaimciuucnelkeoxjhdyduucpmrxmaivacmybmsdrzwqxvbxsy'
|
41
42
|
'gzsabdjmdjabeorttiwinfrpmpogvabiofqexnohrqu')
|
42
43
|
c = Cipher(key)
|
43
|
-
self.assertEqual(
|
44
|
+
self.assertEqual(c.encode('diffiehellman'), 'gccwkixcltycv')
|
44
45
|
|
45
46
|
def test_cipher_encode_short_key(self):
|
46
47
|
c = Cipher('abcd')
|
47
|
-
self.assertEqual(
|
48
|
+
self.assertEqual(c.encode('aaaaaaaa'), 'abcdabcd')
|
48
49
|
|
49
50
|
def test_cipher_compositiion1(self):
|
50
51
|
key = ('duxrceqyaimciuucnelkeoxjhdyduucpmrxmaivacmybmsdrzwqxvbxsy'
|
51
52
|
'gzsabdjmdjabeorttiwinfrpmpogvabiofqexnohrqu')
|
52
53
|
plaintext = 'adaywithoutlaughterisadaywasted'
|
53
54
|
c = Cipher(key)
|
54
|
-
self.assertEqual(
|
55
|
+
self.assertEqual(c.decode(c.encode(plaintext)), plaintext)
|
55
56
|
|
56
57
|
def test_cipher_compositiion2(self):
|
57
58
|
plaintext = 'adaywithoutlaughterisadaywasted'
|
58
59
|
c = Cipher()
|
59
|
-
self.assertEqual(
|
60
|
+
self.assertEqual(c.decode(c.encode(plaintext)), plaintext)
|
60
61
|
|
61
62
|
def test_cipher_random_key(self):
|
62
63
|
c = Cipher()
|
63
|
-
self.assertTrue(
|
64
|
-
|
64
|
+
self.assertTrue(
|
65
|
+
len(c.key) >= 100,
|
66
|
+
'A random key must be generated when no key is given!')
|
65
67
|
self.assertTrue(c.key.islower() and c.key.isalpha(),
|
66
68
|
'All items in the key must be chars and lowercase!')
|
67
69
|
|
@@ -6,46 +6,46 @@ from space_age import SpaceAge
|
|
6
6
|
class SpaceAgeTest(unittest.TestCase):
|
7
7
|
def test_age_in_seconds(self):
|
8
8
|
age = SpaceAge(1e6)
|
9
|
-
self.assertEqual(
|
9
|
+
self.assertEqual(age.seconds, 1e6)
|
10
10
|
|
11
11
|
def test_age_in_earth_years(self):
|
12
12
|
age = SpaceAge(1e9)
|
13
|
-
self.assertEqual(
|
13
|
+
self.assertEqual(age.on_earth(), 31.69)
|
14
14
|
|
15
15
|
def test_age_in_mercury_years(self):
|
16
16
|
age = SpaceAge(2134835688)
|
17
|
-
self.assertEqual(
|
18
|
-
self.assertEqual(
|
17
|
+
self.assertEqual(age.on_earth(), 67.65)
|
18
|
+
self.assertEqual(age.on_mercury(), 280.88)
|
19
19
|
|
20
20
|
def test_age_in_venus_years(self):
|
21
21
|
age = SpaceAge(189839836)
|
22
|
-
self.assertEqual(
|
23
|
-
self.assertEqual(
|
22
|
+
self.assertEqual(age.on_earth(), 6.02)
|
23
|
+
self.assertEqual(age.on_venus(), 9.78)
|
24
24
|
|
25
25
|
def test_age_on_mars(self):
|
26
26
|
age = SpaceAge(2329871239)
|
27
|
-
self.assertEqual(
|
28
|
-
self.assertEqual(
|
27
|
+
self.assertEqual(age.on_earth(), 73.83)
|
28
|
+
self.assertEqual(age.on_mars(), 39.25)
|
29
29
|
|
30
30
|
def test_age_on_jupiter(self):
|
31
31
|
age = SpaceAge(901876382)
|
32
|
-
self.assertEqual(
|
33
|
-
self.assertEqual(
|
32
|
+
self.assertEqual(age.on_earth(), 28.58)
|
33
|
+
self.assertEqual(age.on_jupiter(), 2.41)
|
34
34
|
|
35
35
|
def test_age_on_saturn(self):
|
36
36
|
age = SpaceAge(3e9)
|
37
|
-
self.assertEqual(
|
38
|
-
self.assertEqual(
|
37
|
+
self.assertEqual(age.on_earth(), 95.06)
|
38
|
+
self.assertEqual(age.on_saturn(), 3.23)
|
39
39
|
|
40
40
|
def test_age_on_uranus(self):
|
41
41
|
age = SpaceAge(3210123456)
|
42
|
-
self.assertEqual(
|
43
|
-
self.assertEqual(
|
42
|
+
self.assertEqual(age.on_earth(), 101.72)
|
43
|
+
self.assertEqual(age.on_uranus(), 1.21)
|
44
44
|
|
45
45
|
def test_age_on_neptune(self):
|
46
46
|
age = SpaceAge(8210123456)
|
47
|
-
self.assertEqual(
|
48
|
-
self.assertEqual(
|
47
|
+
self.assertEqual(age.on_earth(), 260.16)
|
48
|
+
self.assertEqual(age.on_neptune(), 1.58)
|
49
49
|
|
50
50
|
|
51
51
|
if __name__ == '__main__':
|
@@ -5,40 +5,41 @@ from strain import keep, discard
|
|
5
5
|
|
6
6
|
class StrainTest(unittest.TestCase):
|
7
7
|
def test_empty_sequence(self):
|
8
|
-
self.assertEqual(
|
8
|
+
self.assertEqual(keep([], lambda x: x % 2 == 0), [])
|
9
9
|
|
10
10
|
def test_empty_keep(self):
|
11
11
|
inp = [2, 4, 6, 8, 10]
|
12
12
|
out = []
|
13
|
-
self.assertEqual(
|
13
|
+
self.assertEqual(keep(inp, lambda x: x % 2 == 1), out)
|
14
14
|
|
15
15
|
def test_empty_discard(self):
|
16
16
|
inp = [2, 4, 6, 8, 10]
|
17
17
|
out = []
|
18
|
-
self.assertEqual(
|
18
|
+
self.assertEqual(discard(inp, lambda x: x % 2 == 0), out)
|
19
19
|
|
20
20
|
def test_keep_everything(self):
|
21
21
|
inp = [2, 4, 6, 8, 10]
|
22
|
-
self.assertEqual(
|
22
|
+
self.assertEqual(keep(inp, lambda x: x % 2 == 0), inp)
|
23
23
|
|
24
24
|
def test_discard_endswith(self):
|
25
25
|
inp = ['dough', 'cash', 'plough', 'though', 'through', 'enough']
|
26
26
|
out = ['cash']
|
27
|
-
self.assertEqual(
|
27
|
+
self.assertEqual(discard(inp, lambda x: str.endswith(x, 'ough')), out)
|
28
28
|
|
29
29
|
def test_keep_z(self):
|
30
30
|
inp = ['zebra', 'arizona', 'apple', 'google', 'mozilla']
|
31
31
|
out = ['zebra', 'arizona', 'mozilla']
|
32
|
-
self.assertEqual(
|
32
|
+
self.assertEqual(keep(inp, lambda x: 'z' in x), out)
|
33
33
|
|
34
34
|
def test_keep_discard(self):
|
35
35
|
inp = ['1,2,3', 'one', 'almost!', 'love']
|
36
|
-
self.assertEqual(
|
36
|
+
self.assertEqual(discard(keep(inp, str.isalpha), str.isalpha), [])
|
37
37
|
|
38
38
|
def test_keep_plus_discard(self):
|
39
39
|
inp = ['1,2,3', 'one', 'almost!', 'love']
|
40
40
|
out = ['one', 'love', '1,2,3', 'almost!']
|
41
|
-
self.assertEqual(
|
41
|
+
self.assertEqual(
|
42
|
+
keep(inp, str.isalpha) + discard(inp, str.isalpha), out)
|
42
43
|
|
43
44
|
|
44
45
|
if __name__ == '__main__':
|
@@ -5,82 +5,81 @@ from sublist import check_lists, SUBLIST, SUPERLIST, EQUAL, UNEQUAL
|
|
5
5
|
|
6
6
|
class SublistTest(unittest.TestCase):
|
7
7
|
def test_unique_return_vals(self):
|
8
|
-
self.assertEqual(
|
8
|
+
self.assertEqual(len(set([SUBLIST, SUPERLIST, EQUAL, UNEQUAL])), 4)
|
9
9
|
|
10
10
|
def test_empty_lists(self):
|
11
|
-
self.assertEqual(
|
11
|
+
self.assertEqual(check_lists([], []), EQUAL)
|
12
12
|
|
13
13
|
def test_empty_list_within(self):
|
14
|
-
self.assertEqual(
|
14
|
+
self.assertEqual(check_lists([], [1, 2, 3]), SUBLIST)
|
15
15
|
|
16
16
|
def test_within_empty_list(self):
|
17
|
-
self.assertEqual(
|
17
|
+
self.assertEqual(check_lists([1], []), SUPERLIST)
|
18
18
|
|
19
19
|
def test_equal_lists(self):
|
20
20
|
l1 = [0, 1, 2]
|
21
21
|
l2 = [0, 1, 2]
|
22
|
-
self.assertEqual(
|
22
|
+
self.assertEqual(check_lists(l1, l2), EQUAL)
|
23
23
|
|
24
24
|
def test_different_lists(self):
|
25
25
|
l1 = list(range(1000000))
|
26
26
|
l2 = list(range(1, 1000001))
|
27
|
-
self.assertEqual(
|
27
|
+
self.assertEqual(check_lists(l1, l2), UNEQUAL)
|
28
28
|
|
29
29
|
def test_false_start(self):
|
30
30
|
l1 = [1, 2, 5]
|
31
31
|
l2 = [0, 1, 2, 3, 1, 2, 5, 6]
|
32
|
-
self.assertEqual(
|
32
|
+
self.assertEqual(check_lists(l1, l2), SUBLIST)
|
33
33
|
|
34
34
|
def test_consecutive(self):
|
35
35
|
l1 = [1, 1, 2]
|
36
36
|
l2 = [0, 1, 1, 1, 2, 1, 2]
|
37
|
-
self.assertEqual(
|
37
|
+
self.assertEqual(check_lists(l1, l2), SUBLIST)
|
38
38
|
|
39
39
|
def test_sublist_at_start(self):
|
40
40
|
l1 = [0, 1, 2]
|
41
41
|
l2 = [0, 1, 2, 3, 4, 5]
|
42
|
-
self.assertEqual(
|
42
|
+
self.assertEqual(check_lists(l1, l2), SUBLIST)
|
43
43
|
|
44
44
|
def test_sublist_in_middle(self):
|
45
45
|
l1 = [2, 3, 4]
|
46
46
|
l2 = [0, 1, 2, 3, 4, 5]
|
47
|
-
self.assertEqual(
|
47
|
+
self.assertEqual(check_lists(l1, l2), SUBLIST)
|
48
48
|
|
49
49
|
def test_sublist_at_end(self):
|
50
50
|
l1 = [3, 4, 5]
|
51
51
|
l2 = [0, 1, 2, 3, 4, 5]
|
52
|
-
self.assertEqual(
|
52
|
+
self.assertEqual(check_lists(l1, l2), SUBLIST)
|
53
53
|
|
54
54
|
def test_at_start_of_superlist(self):
|
55
55
|
l1 = [0, 1, 2, 3, 4, 5]
|
56
56
|
l2 = [0, 1, 2]
|
57
|
-
self.assertEqual(
|
57
|
+
self.assertEqual(check_lists(l1, l2), SUPERLIST)
|
58
58
|
|
59
59
|
def test_in_middle_of_superlist(self):
|
60
60
|
l1 = [0, 1, 2, 3, 4, 5]
|
61
61
|
l2 = [2, 3]
|
62
|
-
self.assertEqual(
|
62
|
+
self.assertEqual(check_lists(l1, l2), SUPERLIST)
|
63
63
|
|
64
64
|
def test_at_end_of_superlist(self):
|
65
65
|
l1 = [0, 1, 2, 3, 4, 5]
|
66
66
|
l2 = [3, 4, 5]
|
67
|
-
self.assertEqual(
|
67
|
+
self.assertEqual(check_lists(l1, l2), SUPERLIST)
|
68
68
|
|
69
69
|
def test_large_lists(self):
|
70
70
|
l1 = list(range(1000)) * 1000 + list(range(1000, 1100))
|
71
71
|
l2 = list(range(900, 1050))
|
72
|
-
self.assertEqual(
|
72
|
+
self.assertEqual(check_lists(l1, l2), SUPERLIST)
|
73
73
|
|
74
74
|
def test_spread_sublist(self):
|
75
75
|
multiples_of_3 = list(range(3, 200, 3))
|
76
76
|
multiples_of_15 = list(range(15, 200, 15))
|
77
|
-
self.assertEqual(UNEQUAL
|
78
|
-
check_lists(multiples_of_15, multiples_of_3))
|
77
|
+
self.assertEqual(check_lists(multiples_of_15, multiples_of_3), UNEQUAL)
|
79
78
|
|
80
79
|
def test_avoid_sets(self):
|
81
|
-
self.assertEqual(
|
82
|
-
self.assertEqual(
|
83
|
-
self.assertEqual(
|
80
|
+
self.assertEqual(check_lists([1, 3], [1, 2, 3]), UNEQUAL)
|
81
|
+
self.assertEqual(check_lists([1, 2, 3], [1, 3]), UNEQUAL)
|
82
|
+
self.assertEqual(check_lists([1, 2, 3], [3, 2, 1]), UNEQUAL)
|
84
83
|
|
85
84
|
|
86
85
|
if __name__ == '__main__':
|