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.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/common/exercises/simple-cipher/description.md +1 -1
  3. data/common/exercises/triangle/description.md +12 -23
  4. data/lib/trackler/version.rb +1 -1
  5. data/tracks/kotlin/config.json +5 -0
  6. data/tracks/kotlin/exercises/bank-account/build.gradle +32 -0
  7. data/tracks/kotlin/exercises/bank-account/src/example/kotlin/BankAccount.kt +27 -0
  8. data/tracks/kotlin/exercises/bank-account/src/main/kotlin/.keep +0 -0
  9. data/tracks/kotlin/exercises/bank-account/src/test/kotlin/BankAccountTest.kt +73 -0
  10. data/tracks/kotlin/exercises/settings.gradle +1 -0
  11. data/tracks/python/config.json +11 -11
  12. data/tracks/python/exercises/accumulate/accumulate_test.py +16 -14
  13. data/tracks/python/exercises/acronym/acronym_test.py +8 -7
  14. data/tracks/python/exercises/allergies/allergies_test.py +5 -6
  15. data/tracks/python/exercises/atbash-cipher/atbash_cipher_test.py +16 -22
  16. data/tracks/python/exercises/binary-search/binary_search_test.py +12 -10
  17. data/tracks/python/exercises/binary/binary_test.py +7 -8
  18. data/tracks/python/exercises/circular-buffer/circular_buffer_test.py +16 -17
  19. data/tracks/python/exercises/clock/clock_test.py +35 -35
  20. data/tracks/python/exercises/crypto-square/crypto_square_test.py +5 -6
  21. data/tracks/python/exercises/diamond/diamond_test.py +3 -4
  22. data/tracks/python/exercises/etl/etl_test.py +4 -4
  23. data/tracks/python/exercises/gigasecond/gigasecond_test.py +11 -19
  24. data/tracks/python/exercises/grade-school/grade_school_test.py +17 -19
  25. data/tracks/python/exercises/grains/grains_test.py +14 -14
  26. data/tracks/python/exercises/grep/grep_test.py +51 -64
  27. data/tracks/python/exercises/hamming/hamming_test.py +13 -13
  28. data/tracks/python/exercises/hello-world/hello_world_test.py +1 -2
  29. data/tracks/python/exercises/hexadecimal/hexadecimal_test.py +9 -10
  30. data/tracks/python/exercises/house/house_test.py +6 -6
  31. data/tracks/python/exercises/kindergarten-garden/kindergarten_garden_test.py +22 -19
  32. data/tracks/python/exercises/largest-series-product/largest_series_product_test.py +29 -28
  33. data/tracks/python/exercises/linked-list/linked_list_test.py +18 -19
  34. data/tracks/python/exercises/list-ops/list_ops_test.py +44 -39
  35. data/tracks/python/exercises/matrix/matrix_test.py +6 -6
  36. data/tracks/python/exercises/meetup/meetup_test.py +27 -27
  37. data/tracks/python/exercises/minesweeper/example.py +4 -2
  38. data/tracks/python/exercises/minesweeper/minesweeper_test.py +9 -9
  39. data/tracks/python/exercises/nucleotide-count/nucleotide_count_test.py +6 -6
  40. data/tracks/python/exercises/ocr-numbers/ocr_numbers_test.py +63 -49
  41. data/tracks/python/exercises/octal/octal_test.py +7 -7
  42. data/tracks/python/exercises/palindrome-products/palindrome_products_test.py +9 -9
  43. data/tracks/python/exercises/pascals-triangle/pascals_triangle_test.py +7 -7
  44. data/tracks/python/exercises/phone-number/phone_number_test.py +8 -8
  45. data/tracks/python/exercises/pig-latin/pig_latin_test.py +15 -15
  46. data/tracks/python/exercises/point-mutations/point_mutations_test.py +11 -11
  47. data/tracks/python/exercises/poker/poker_test.py +32 -30
  48. data/tracks/python/exercises/prime-factors/prime_factors_test.py +11 -11
  49. data/tracks/python/exercises/proverb/proverb_test.py +16 -9
  50. data/tracks/python/exercises/pythagorean-triplet/pythagorean_triplet_test.py +14 -12
  51. data/tracks/python/exercises/queen-attack/queen_attack_test.py +10 -10
  52. data/tracks/python/exercises/rail-fence-cipher/example.py +2 -1
  53. data/tracks/python/exercises/rail-fence-cipher/rail_fence_cipher_test.py +14 -13
  54. data/tracks/python/exercises/raindrops/raindrops_test.py +16 -16
  55. data/tracks/python/exercises/rectangles/rectangles_test.py +9 -9
  56. data/tracks/python/exercises/rna-transcription/rna_transcription_test.py +8 -8
  57. data/tracks/python/exercises/robot-name/robot_name_test.py +1 -1
  58. data/tracks/python/exercises/robot-simulator/robot_simulator_test.py +18 -19
  59. data/tracks/python/exercises/roman-numerals/roman_numerals_test.py +1 -1
  60. data/tracks/python/exercises/run-length-encoding/run_length_encoding_test.py +15 -16
  61. data/tracks/python/exercises/saddle-points/saddle_points_test.py +4 -4
  62. data/tracks/python/exercises/say/say_test.py +21 -23
  63. data/tracks/python/exercises/scrabble-score/scrabble_score_test.py +9 -9
  64. data/tracks/python/exercises/secret-handshake/secret_handshake_test.py +14 -13
  65. data/tracks/python/exercises/series/example.py +3 -3
  66. data/tracks/python/exercises/series/series_test.py +16 -12
  67. data/tracks/python/exercises/simple-cipher/simple_cipher_test.py +21 -19
  68. data/tracks/python/exercises/space-age/space_age_test.py +16 -16
  69. data/tracks/python/exercises/strain/strain_test.py +9 -8
  70. data/tracks/python/exercises/sublist/sublist_test.py +19 -20
  71. data/tracks/python/exercises/sum-of-multiples/example.py +1 -4
  72. data/tracks/python/exercises/sum-of-multiples/sum_of_multiples_test.py +31 -26
  73. data/tracks/python/exercises/triangle/triangle_test.py +15 -30
  74. data/tracks/python/exercises/trinary/trinary_test.py +7 -7
  75. data/tracks/python/exercises/twelve-days/twelve_days_test.py +13 -14
  76. data/tracks/python/exercises/word-count/example.py +1 -9
  77. data/tracks/python/exercises/word-count/word_count_test.py +0 -15
  78. data/tracks/python/exercises/wordy/wordy_test.py +17 -18
  79. data/tracks/python/exercises/zebra-puzzle/example.py +20 -23
  80. data/tracks/python/exercises/zebra-puzzle/zebra_puzzle_test.py +3 -3
  81. data/tracks/python/test/check-exercises.py +1 -1
  82. 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("one", say(1))
8
+ self.assertEqual(say(1), "one")
10
9
 
11
10
  def test_fourteen(self):
12
- self.assertEqual("fourteen", say(14))
11
+ self.assertEqual(say(14), "fourteen")
13
12
 
14
13
  def test_twenty(self):
15
- self.assertEqual("twenty", say(20))
14
+ self.assertEqual(say(20), "twenty")
16
15
 
17
16
  def test_twenty_two(self):
18
- self.assertEqual("twenty-two", say(22))
17
+ self.assertEqual(say(22), "twenty-two")
19
18
 
20
19
  def test_one_hundred(self):
21
- self.assertEqual("one hundred", say(100))
20
+ self.assertEqual(say(100), "one hundred")
22
21
 
23
22
  def test_one_hundred_twenty(self):
24
- self.assertEqual("one hundred and twenty", say(120))
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", say(123))
26
+ self.assertEqual(say(123), "one hundred and twenty-three")
28
27
 
29
28
  def test_one_thousand(self):
30
- self.assertEqual("one thousand", say(1000))
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", say(810000))
35
+ self.assertEqual(say(810000), "eight hundred and ten thousand")
38
36
 
39
37
  def test_one_million(self):
40
- self.assertEqual("one million", say(1e6))
38
+ self.assertEqual(say(1e6), "one million")
41
39
 
42
40
  def test_one_million_two(self):
43
- self.assertEqual("one million and two", say(1000002))
41
+ self.assertEqual(say(1000002), "one million and two")
44
42
 
45
43
  def test_1002345(self):
46
44
  self.assertEqual(
47
- "one million two thousand three hundred and forty-five",
48
- say(1002345))
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", say(1e9))
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("zero", say(0))
60
+ self.assertEqual(say(0), "zero")
63
61
 
64
62
  def test_987654321123(self):
65
- self.assertEqual("nine hundred and eighty-seven billion " +
66
- "six hundred and fifty-four million " +
67
- "three hundred and twenty-one thousand " +
68
- "one hundred and twenty-three",
69
- say(987654321123))
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(0, score(''))
9
- self.assertEqual(0, score(' \t\n'))
10
- self.assertEqual(0, score('hous3'))
11
- self.assertEqual(0, score('wo rd'))
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(1, score('a'))
14
+ self.assertEqual(score('a'), 1)
15
15
 
16
16
  def test_scores_other_very_short_word(self):
17
- self.assertEqual(4, score('f'))
17
+ self.assertEqual(score('f'), 4)
18
18
 
19
19
  def test_simple_word_scores_the_number_of_letters(self):
20
- self.assertEqual(6, score("street"))
20
+ self.assertEqual(score("street"), 6)
21
21
 
22
22
  def test_complicated_word_scores_more(self):
23
- self.assertEqual(22, score("quirky"))
23
+ self.assertEqual(score("quirky"), 22)
24
24
 
25
25
  def test_scores_are_case_insensitive(self):
26
- self.assertEqual(41, score("OxyphenButazone"))
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'], handshake(9))
8
+ self.assertEqual(handshake(9), ['wink', 'jump'])
9
9
 
10
10
  def test_shake_bin1(self):
11
- self.assertEqual(['close your eyes', 'double blink'], handshake('10110'))
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'], handshake('101'))
15
+ self.assertEqual(handshake('101'), ['wink', 'close your eyes'])
15
16
 
16
17
  def test_shake_negative_int(self):
17
- self.assertEqual([], handshake(-9))
18
+ self.assertEqual(handshake(-9), [])
18
19
 
19
20
  def test_shake_bin_invalid(self):
20
- self.assertEqual([], handshake('121'))
21
+ self.assertEqual(handshake('121'), [])
21
22
 
22
23
  def test_unknown_action(self):
23
- self.assertEqual('0', code(['wink', 'sneeze']))
24
+ self.assertEqual(code(['wink', 'sneeze']), '0')
24
25
 
25
26
  def test_code1(self):
26
- self.assertEqual('1100', code(['close your eyes', 'jump']))
27
+ self.assertEqual(code(['close your eyes', 'jump']), '1100')
27
28
 
28
29
  def test_code2(self):
29
- self.assertEqual('11', code(['wink', 'double blink']))
30
+ self.assertEqual(code(['wink', 'double blink']), '11')
30
31
 
31
32
  def test_code3(self):
32
- self.assertEqual('11010', code(['jump', 'double blink']))
33
+ self.assertEqual(code(['jump', 'double blink']), '11010')
33
34
 
34
35
  def test_composition1(self):
35
- self.assertEqual('11011', code(handshake(27)))
36
+ self.assertEqual(code(handshake(27)), '11011')
36
37
 
37
38
  def test_composition2(self):
38
- self.assertEqual('1', code(handshake(1)))
39
+ self.assertEqual(code(handshake(1)), '1')
39
40
 
40
41
  def test_composition3(self):
41
- self.assertEqual('111', code(handshake('111')))
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(inp, handshake(code(inp)))
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(length))
5
- return [numbers[i:i + length]
6
- for i in range(len(numbers) - length + 1)]
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([[0], [1], [2], [3], [4]],
15
- slices("01234", 1))
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([[9, 7], [7, 8], [8, 6], [6, 7],
19
- [7, 5], [5, 6], [6, 4]],
20
- slices("97867564", 2))
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([[9, 7, 8], [7, 8, 6], [8, 6, 7],
24
- [6, 7, 5], [7, 5, 6], [5, 6, 4]],
25
- slices("97867564", 3))
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([[0, 1, 2, 3], [1, 2, 3, 4]],
29
- slices("01234", 4))
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([[0, 1, 2, 3, 4]],
33
- slices("01234", 5))
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('lwlvdzhvrphsurjudpplqjlqsbwkrq',
10
- Caesar().encode('itisawesomeprogramminginpython'))
8
+ self.assertEqual(Caesar().encode('itisawesomeprogramminginpython'),
9
+ 'lwlvdzhvrphsurjudpplqjlqsbwkrq')
11
10
 
12
11
  def test_caesar_encode2(self):
13
- self.assertEqual('yhqlylglylfl', Caesar().encode('venividivici'))
12
+ self.assertEqual(Caesar().encode('venividivici'), 'yhqlylglylfl')
14
13
 
15
14
  def test_caesar_encode3(self):
16
- self.assertEqual('wzdvwkhqljkwehiruhfkulvwpdv',
17
- Caesar().encode('\'Twas the night before Christmas'))
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('jr', Caesar().encode('1, 2, 3, Go!'))
19
+ self.assertEqual(Caesar().encode('1, 2, 3, Go!'), 'jr')
21
20
 
22
21
  def test_caesar_decode(self):
23
- self.assertEqual('venividivici', Caesar().decode('yhqlylglylfl'))
22
+ self.assertEqual(Caesar().decode('yhqlylglylfl'), 'venividivici')
24
23
 
25
24
  def test_cipher_encode1(self):
26
25
  c = Cipher('a')
27
- self.assertEqual('itisawesomeprogramminginpython',
28
- c.encode('itisawesomeprogramminginpython'))
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('itisawesomeprogramminginpython',
33
- c.encode('itisawesomeprogramminginpython'))
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('yhqlylglylfl', c.encode('venividivici'))
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('gccwkixcltycv', c.encode('diffiehellman'))
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('abcdabcd', c.encode('aaaaaaaa'))
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(plaintext, c.decode(c.encode(plaintext)))
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(plaintext, c.decode(c.encode(plaintext)))
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(len(c.key) >= 100,
64
- 'A random key must be generated when no key is given!')
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(1e6, age.seconds)
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(31.69, age.on_earth())
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(67.65, age.on_earth())
18
- self.assertEqual(280.88, age.on_mercury())
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(6.02, age.on_earth())
23
- self.assertEqual(9.78, age.on_venus())
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(73.83, age.on_earth())
28
- self.assertEqual(39.25, age.on_mars())
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(28.58, age.on_earth())
33
- self.assertEqual(2.41, age.on_jupiter())
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(95.06, age.on_earth())
38
- self.assertEqual(3.23, age.on_saturn())
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(101.72, age.on_earth())
43
- self.assertEqual(1.21, age.on_uranus())
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(260.16, age.on_earth())
48
- self.assertEqual(1.58, age.on_neptune())
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([], keep([], lambda x: x % 2 == 0))
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(out, keep(inp, lambda x: x % 2 == 1))
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(out, discard(inp, lambda x: x % 2 == 0))
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(inp, keep(inp, lambda x: x % 2 == 0))
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(out, discard(inp, lambda x: str.endswith(x, 'ough')))
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(out, keep(inp, lambda x: 'z' in x))
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([], discard(keep(inp, str.isalpha), str.isalpha))
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(out, keep(inp, str.isalpha) + discard(inp, str.isalpha))
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(4, len(set([SUBLIST, SUPERLIST, EQUAL, UNEQUAL])))
8
+ self.assertEqual(len(set([SUBLIST, SUPERLIST, EQUAL, UNEQUAL])), 4)
9
9
 
10
10
  def test_empty_lists(self):
11
- self.assertEqual(EQUAL, check_lists([], []))
11
+ self.assertEqual(check_lists([], []), EQUAL)
12
12
 
13
13
  def test_empty_list_within(self):
14
- self.assertEqual(SUBLIST, check_lists([], [1, 2, 3]))
14
+ self.assertEqual(check_lists([], [1, 2, 3]), SUBLIST)
15
15
 
16
16
  def test_within_empty_list(self):
17
- self.assertEqual(SUPERLIST, check_lists([1], []))
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(EQUAL, check_lists(l1, l2))
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(UNEQUAL, check_lists(l1, l2))
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(SUBLIST, check_lists(l1, l2))
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(SUBLIST, check_lists(l1, l2))
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(SUBLIST, check_lists(l1, l2))
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(SUBLIST, check_lists(l1, l2))
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(SUBLIST, check_lists(l1, l2))
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(SUPERLIST, check_lists(l1, l2))
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(SUPERLIST, check_lists(l1, l2))
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(SUPERLIST, check_lists(l1, l2))
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(SUPERLIST, check_lists(l1, l2))
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(UNEQUAL, check_lists([1, 3], [1, 2, 3]))
82
- self.assertEqual(UNEQUAL, check_lists([1, 2, 3], [1, 3]))
83
- self.assertEqual(UNEQUAL, check_lists([1, 2, 3], [3, 2, 1]))
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__':