From b80622a2699d937bdb3bda3d9f121ef43c191624 Mon Sep 17 00:00:00 2001 From: Tammo Behrends Date: Thu, 23 Mar 2017 12:45:27 +0100 Subject: [PATCH] Refactor assertEqual(actual,expected) param order closes #440 --- exercises/accumulate/accumulate_test.py | 30 ++--- exercises/acronym/acronym_test.py | 15 +-- exercises/allergies/allergies_test.py | 11 +- exercises/atbash-cipher/atbash_cipher_test.py | 38 +++--- exercises/binary-search/binary_search_test.py | 22 ++-- exercises/binary/binary_test.py | 15 ++- .../circular-buffer/circular_buffer_test.py | 33 +++-- exercises/clock/clock_test.py | 70 +++++------ exercises/crypto-square/crypto_square_test.py | 11 +- exercises/diamond/diamond_test.py | 7 +- exercises/etl/etl_test.py | 8 +- exercises/gigasecond/gigasecond_test.py | 30 ++--- exercises/grade-school/grade_school_test.py | 36 +++--- exercises/grains/grains_test.py | 28 ++--- exercises/grep/grep_test.py | 115 ++++++++---------- exercises/hamming/hamming_test.py | 26 ++-- exercises/hello-world/hello_world_test.py | 3 +- exercises/hexadecimal/hexadecimal_test.py | 19 ++- exercises/house/house_test.py | 12 +- .../kindergarten_garden_test.py | 41 ++++--- .../largest_series_product_test.py | 57 ++++----- exercises/linked-list/linked_list_test.py | 37 +++--- exercises/list-ops/list_ops_test.py | 83 +++++++------ exercises/matrix/matrix_test.py | 12 +- exercises/meetup/meetup_test.py | 54 ++++---- exercises/minesweeper/minesweeper_test.py | 18 +-- .../nucleotide-count/nucleotide_count_test.py | 12 +- exercises/ocr-numbers/ocr_numbers_test.py | 112 +++++++++-------- exercises/octal/octal_test.py | 14 +-- .../palindrome_products_test.py | 18 +-- .../pascals-triangle/pascals_triangle_test.py | 14 +-- exercises/phone-number/phone_number_test.py | 16 +-- exercises/pig-latin/pig_latin_test.py | 30 ++--- .../point-mutations/point_mutations_test.py | 22 ++-- exercises/poker/poker_test.py | 62 +++++----- exercises/prime-factors/prime_factors_test.py | 22 ++-- exercises/proverb/proverb_test.py | 25 ++-- .../pythagorean_triplet_test.py | 26 ++-- exercises/queen-attack/queen_attack_test.py | 20 +-- .../rail_fence_cipher_test.py | 27 ++-- exercises/raindrops/raindrops_test.py | 32 ++--- exercises/rectangles/rectangles_test.py | 18 +-- .../rna_transcription_test.py | 19 +-- exercises/robot-name/robot_name_test.py | 2 +- .../robot-simulator/robot_simulator_test.py | 37 +++--- .../roman-numerals/roman_numerals_test.py | 2 +- .../run_length_encoding_test.py | 31 +++-- exercises/saddle-points/saddle_points_test.py | 8 +- exercises/say/say_test.py | 44 ++++--- .../scrabble-score/scrabble_score_test.py | 18 +-- .../secret-handshake/secret_handshake_test.py | 27 ++-- exercises/series/series_test.py | 28 +++-- exercises/simple-cipher/simple_cipher_test.py | 40 +++--- exercises/space-age/space_age_test.py | 32 ++--- exercises/strain/strain_test.py | 17 +-- exercises/sublist/sublist_test.py | 39 +++--- exercises/triangle/triangle_test.py | 45 +++---- exercises/trinary/trinary_test.py | 14 +-- exercises/twelve-days/twelve_days_test.py | 27 ++-- exercises/wordy/wordy_test.py | 35 +++--- exercises/zebra-puzzle/zebra_puzzle_test.py | 6 +- 61 files changed, 881 insertions(+), 891 deletions(-) diff --git a/exercises/accumulate/accumulate_test.py b/exercises/accumulate/accumulate_test.py index 427e4d16e1..a49be036d0 100644 --- a/exercises/accumulate/accumulate_test.py +++ b/exercises/accumulate/accumulate_test.py @@ -5,32 +5,34 @@ class AccumulateTest(unittest.TestCase): def test_empty_sequence(self): - self.assertEqual([], accumulate([], lambda x: x / 2)) + self.assertEqual(accumulate([], lambda x: x / 2), []) def test_pow(self): - self.assertEqual([1, 4, 9, 16, 25], accumulate([1, 2, 3, 4, 5], - lambda x: x * x)) + self.assertEqual( + accumulate([1, 2, 3, 4, 5], lambda x: x * x), [1, 4, 9, 16, 25]) def test_divmod(self): - inp = [10, 17, 23] - out = [(1, 3), (2, 3), (3, 2)] - self.assertEqual(out, accumulate(inp, lambda x: divmod(x, 7))) + self.assertEqual( + accumulate([10, 17, 23], lambda x: divmod(x, 7)), + [(1, 3), (2, 3), (3, 2)]) def test_composition(self): inp = [10, 17, 23] - self.assertEqual(inp, accumulate(accumulate(inp, lambda x: divmod(x, 7)), - lambda x: 7 * x[0] + x[1])) + self.assertEqual( + accumulate( + accumulate(inp, lambda x: divmod(x, 7)), + lambda x: 7 * x[0] + x[1]), inp) def test_capitalize(self): - inp = ['hello', 'world'] - out = ['HELLO', 'WORLD'] - self.assertEqual(out, accumulate(inp, str.upper)) + self.assertEqual( + accumulate(['hello', 'world'], str.upper), ['HELLO', 'WORLD']) def test_recursive(self): - inp = list('abc') + inp = ['a', 'b', 'c'] out = [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3'], ['c1', 'c2', 'c3']] - self.assertEqual(out, accumulate(inp, lambda x: accumulate(list('123'), - lambda y: x + y))) + self.assertEqual( + accumulate( + inp, lambda x: accumulate(list('123'), lambda y: x + y)), out) if __name__ == '__main__': diff --git a/exercises/acronym/acronym_test.py b/exercises/acronym/acronym_test.py index f8a3bd884a..e8c43112f6 100644 --- a/exercises/acronym/acronym_test.py +++ b/exercises/acronym/acronym_test.py @@ -7,25 +7,26 @@ class AcronymTest(unittest.TestCase): def test_basic(self): - self.assertEqual('PNG', abbreviate('Portable Network Graphics')) + self.assertEqual(abbreviate('Portable Network Graphics'), 'PNG') def test_lowercase_words(self): - self.assertEqual('ROR', abbreviate('Ruby on Rails')) + self.assertEqual(abbreviate('Ruby on Rails'), 'ROR') def test_camelcase(self): - self.assertEqual('HTML', abbreviate('HyperText Markup Language')) + self.assertEqual(abbreviate('HyperText Markup Language'), 'HTML') def test_punctuation(self): - self.assertEqual('FIFO', abbreviate('First In, First Out')) + self.assertEqual(abbreviate('First In, First Out'), 'FIFO') def test_all_caps_words(self): - self.assertEqual('PHP', abbreviate('PHP: Hypertext Preprocessor')) + self.assertEqual(abbreviate('PHP: Hypertext Preprocessor'), 'PHP') def test_non_acronym_all_caps_word(self): - self.assertEqual('GIMP', abbreviate('GNU Image Manipulation Program')) + self.assertEqual(abbreviate('GNU Image Manipulation Program'), 'GIMP') def test_hyphenated(self): - self.assertEqual('CMOS', abbreviate('Complementary metal-oxide semiconductor')) + self.assertEqual( + abbreviate('Complementary metal-oxide semiconductor'), 'CMOS') if __name__ == '__main__': diff --git a/exercises/allergies/allergies_test.py b/exercises/allergies/allergies_test.py index 713385dd5b..ca0b0ae574 100644 --- a/exercises/allergies/allergies_test.py +++ b/exercises/allergies/allergies_test.py @@ -4,7 +4,6 @@ class AllergiesTests(unittest.TestCase): - def test_no_allergies_means_not_allergic(self): allergies = Allergies(0) self.assertFalse(allergies.is_allergic_to('peanuts')) @@ -21,20 +20,20 @@ def test_has_the_right_allergies(self): self.assertFalse(allergies.is_allergic_to('strawberries')) def test_no_allergies_at_all(self): - self.assertEqual([], Allergies(0).lst) + self.assertEqual(Allergies(0).lst, []) def test_allergic_to_just_peanuts(self): - self.assertEqual(['peanuts'], Allergies(2).lst) + self.assertEqual(Allergies(2).lst, ['peanuts']) def test_allergic_to_everything(self): self.assertEqual( + sorted(Allergies(255).lst), sorted(('eggs peanuts shellfish strawberries tomatoes ' - 'chocolate pollen cats').split()), - sorted(Allergies(255).lst)) + 'chocolate pollen cats').split())) @unittest.skip('Extra Credit: Passes with a specific type of solution') def test_ignore_non_allergen_score_parts(self): - self.assertEqual(['eggs'], Allergies(257).lst) + self.assertEqual(Allergies(257).lst, ['eggs']) if __name__ == '__main__': diff --git a/exercises/atbash-cipher/atbash_cipher_test.py b/exercises/atbash-cipher/atbash_cipher_test.py index e0e09b93b1..a650c0ba8a 100644 --- a/exercises/atbash-cipher/atbash_cipher_test.py +++ b/exercises/atbash-cipher/atbash_cipher_test.py @@ -6,61 +6,55 @@ # test cases adapted from `x-common//canonical-data.json` @ version: 1.0.0 class AtbashCipherTest(unittest.TestCase): - def test_encode_no(self): - self.assertMultiLineEqual("ml", encode("no")) + self.assertMultiLineEqual(encode("no"), "ml") def test_encode_yes(self): - self.assertMultiLineEqual("bvh", encode("yes")) + self.assertMultiLineEqual(encode("yes"), "bvh") def test_encode_OMG(self): - self.assertMultiLineEqual("lnt", encode("OMG")) + self.assertMultiLineEqual(encode("OMG"), "lnt") def test_encode_O_M_G(self): - self.assertMultiLineEqual("lnt", encode("O M G")) + self.assertMultiLineEqual(encode("O M G"), "lnt") def test_encode_long_word(self): - self.assertMultiLineEqual("nrmwy oldrm tob", encode("mindblowingly")) + self.assertMultiLineEqual(encode("mindblowingly"), "nrmwy oldrm tob") def test_encode_numbers(self): - self.assertMultiLineEqual("gvhgr mt123 gvhgr mt", - encode("Testing, 1 2 3, testing.")) + self.assertMultiLineEqual( + encode("Testing, 1 2 3, testing."), "gvhgr mt123 gvhgr mt") def test_encode_sentence(self): - self.assertMultiLineEqual("gifgs rhurx grlm", - encode("Truth is fiction.")) + self.assertMultiLineEqual( + encode("Truth is fiction."), "gifgs rhurx grlm") def test_encode_all_things(self): plaintext = "The quick brown fox jumps over the lazy dog." ciphertext = "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt" - self.assertMultiLineEqual(ciphertext, encode(plaintext)) + self.assertMultiLineEqual(encode(plaintext), ciphertext) def test_decode_word(self): - self.assertMultiLineEqual("exercism", decode("vcvix rhn")) + self.assertMultiLineEqual(decode("vcvix rhn"), "exercism") def test_decode_sentence(self): self.assertMultiLineEqual( - "anobstacleisoftenasteppingstone", - decode("zmlyh gzxov rhlug vmzhg vkkrm thglm v") - ) + decode("zmlyh gzxov rhlug vmzhg vkkrm thglm v"), + "anobstacleisoftenasteppingstone") def test_decode_numbers(self): self.assertMultiLineEqual( - "testing123testing", - decode("gvhgr mt123 gvhgr mt") - ) + decode("gvhgr mt123 gvhgr mt"), "testing123testing") def test_decode_all_the_letters(self): ciphertext = "gsvjf rxpyi ldmul cqfnk hlevi gsvoz abwlt" plaintext = "thequickbrownfoxjumpsoverthelazydog" - self.assertMultiLineEqual(plaintext, decode(ciphertext)) + self.assertMultiLineEqual(decode(ciphertext), plaintext) # additional track specific test def test_encode_decode(self): self.assertMultiLineEqual( - "testing123testing", - decode(encode("Testing, 1 2 3, testing.")) - ) + decode(encode("Testing, 1 2 3, testing.")), "testing123testing") if __name__ == '__main__': diff --git a/exercises/binary-search/binary_search_test.py b/exercises/binary-search/binary_search_test.py index 53532297da..96200e4ceb 100644 --- a/exercises/binary-search/binary_search_test.py +++ b/exercises/binary-search/binary_search_test.py @@ -4,26 +4,27 @@ class BinarySearchTests(unittest.TestCase): - def test_finds_value_in_array_with_one_element(self): - self.assertEqual(0, binary_search([6], 6)) + self.assertEqual(binary_search([6], 6), 0) def test_finds_value_in_middle_of_array(self): - self.assertEqual(3, binary_search([1, 3, 4, 6, 8, 9, 11], 6)) + self.assertEqual(binary_search([1, 3, 4, 6, 8, 9, 11], 6), 3) def test_finds_value_at_beginning_of_array(self): - self.assertEqual(0, binary_search([1, 3, 4, 6, 8, 9, 11], 1)) + self.assertEqual(binary_search([1, 3, 4, 6, 8, 9, 11], 1), 0) def test_finds_value_at_end_of_array(self): - self.assertEqual(6, binary_search([1, 3, 4, 6, 8, 9, 11], 11)) + self.assertEqual(binary_search([1, 3, 4, 6, 8, 9, 11], 11), 6) def test_finds_value_in_array_of_odd_length(self): - self.assertEqual(9, binary_search( - [1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 634], 144)) + self.assertEqual( + binary_search([1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 634], + 144), 9) def test_finds_value_in_array_of_even_length(self): - self.assertEqual(5, binary_search( - [1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377], 21)) + self.assertEqual( + binary_search([1, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377], 21), + 5) def test_identifies_value_missing(self): self.assertRaises(ValueError, binary_search, [1, 3, 4, 6, 8, 9, 11], 7) @@ -32,7 +33,8 @@ def test_value_smaller_than_arrays_minimum(self): self.assertRaises(ValueError, binary_search, [1, 3, 4, 6, 8, 9, 11], 0) def test_value_larger_than_arrays_maximum(self): - self.assertRaises(ValueError, binary_search, [1, 3, 4, 6, 8, 9, 11], 13) + self.assertRaises(ValueError, binary_search, [1, 3, 4, 6, 8, 9, 11], + 13) def test_empty_array(self): self.assertRaises(ValueError, binary_search, [], 1) diff --git a/exercises/binary/binary_test.py b/exercises/binary/binary_test.py index e4a31cf86f..8254d7b549 100644 --- a/exercises/binary/binary_test.py +++ b/exercises/binary/binary_test.py @@ -10,27 +10,26 @@ class BinaryTests(unittest.TestCase): - def test_binary_1_is_decimal_1(self): - self.assertEqual(1, parse_binary("1")) + self.assertEqual(parse_binary("1"), 1) def test_binary_10_is_decimal_2(self): - self.assertEqual(2, parse_binary("10")) + self.assertEqual(parse_binary("10"), 2) def test_binary_11_is_decimal_3(self): - self.assertEqual(3, parse_binary("11")) + self.assertEqual(parse_binary("11"), 3) def test_binary_100_is_decimal_4(self): - self.assertEqual(4, parse_binary("100")) + self.assertEqual(parse_binary("100"), 4) def test_binary_1001_is_decimal_9(self): - self.assertEqual(9, parse_binary("1001")) + self.assertEqual(parse_binary("1001"), 9) def test_binary_11010_is_decimal_26(self): - self.assertEqual(26, parse_binary("11010")) + self.assertEqual(parse_binary("11010"), 26) def test_binary_10001101000_is_decimal_1128(self): - self.assertEqual(1128, parse_binary("10001101000")) + self.assertEqual(parse_binary("10001101000"), 1128) def test_invalid_binary_text_only(self): self.assertRaises(ValueError, parse_binary, "carrot") diff --git a/exercises/circular-buffer/circular_buffer_test.py b/exercises/circular-buffer/circular_buffer_test.py index a51a2d7a94..8e49bf77ae 100644 --- a/exercises/circular-buffer/circular_buffer_test.py +++ b/exercises/circular-buffer/circular_buffer_test.py @@ -8,7 +8,6 @@ class CircularBufferTest(unittest.TestCase): - def test_read_empty_buffer(self): buf = CircularBuffer(1) with self.assertRaises(BufferEmptyException): @@ -25,8 +24,8 @@ def test_write_and_read_back_multiple_items(self): buf = CircularBuffer(2) buf.write('1') buf.write('2') - self.assertEqual('1', buf.read()) - self.assertEqual('2', buf.read()) + self.assertEqual(buf.read(), '1') + self.assertEqual(buf.read(), '2') with self.assertRaises(BufferEmptyException): buf.read() @@ -39,16 +38,16 @@ def test_clearing_buffer(self): buf.read() buf.write('1') buf.write('2') - self.assertEqual('1', buf.read()) + self.assertEqual(buf.read(), '1') buf.write('3') - self.assertEqual('2', buf.read()) + self.assertEqual(buf.read(), '2') def test_alternate_write_and_read(self): buf = CircularBuffer(2) buf.write('1') - self.assertEqual('1', buf.read()) + self.assertEqual(buf.read(), '1') buf.write('2') - self.assertEqual('2', buf.read()) + self.assertEqual(buf.read(), '2') def test_read_back_oldest_item(self): buf = CircularBuffer(3) @@ -57,7 +56,7 @@ def test_read_back_oldest_item(self): buf.read() buf.write('3') buf.read() - self.assertEqual('3', buf.read()) + self.assertEqual(buf.read(), '3') def test_write_full_buffer(self): buf = CircularBuffer(2) @@ -71,8 +70,8 @@ def test_overwrite_full_buffer(self): buf.write('1') buf.write('2') buf.overwrite('A') - self.assertEqual('2', buf.read()) - self.assertEqual('A', buf.read()) + self.assertEqual(buf.read(), '2') + self.assertEqual(buf.read(), 'A') with self.assertRaises(BufferEmptyException): buf.read() @@ -80,8 +79,8 @@ def test_overwrite_non_full_buffer(self): buf = CircularBuffer(2) buf.overwrite('1') buf.overwrite('2') - self.assertEqual('1', buf.read()) - self.assertEqual('2', buf.read()) + self.assertEqual(buf.read(), '1') + self.assertEqual(buf.read(), '2') with self.assertRaises(BufferEmptyException): buf.read() @@ -97,11 +96,11 @@ def test_alternate_read_and_overwrite(self): buf.write(c) buf.overwrite('A') buf.overwrite('B') - self.assertEqual('6', buf.read()) - self.assertEqual('7', buf.read()) - self.assertEqual('8', buf.read()) - self.assertEqual('A', buf.read()) - self.assertEqual('B', buf.read()) + self.assertEqual(buf.read(), '6') + self.assertEqual(buf.read(), '7') + self.assertEqual(buf.read(), '8') + self.assertEqual(buf.read(), 'A') + self.assertEqual(buf.read(), 'B') with self.assertRaises(BufferEmptyException): buf.read() diff --git a/exercises/clock/clock_test.py b/exercises/clock/clock_test.py index a046fc0061..444e30021d 100644 --- a/exercises/clock/clock_test.py +++ b/exercises/clock/clock_test.py @@ -6,110 +6,110 @@ class ClockTest(unittest.TestCase): # Test creating a new clock with an initial time. def test_on_the_hour(self): - self.assertEqual('08:00', str(Clock(8, 0))) + self.assertEqual(str(Clock(8, 0)), '08:00') def test_past_the_hour(self): - self.assertEqual('11:09', str(Clock(11, 9))) + self.assertEqual(str(Clock(11, 9)), '11:09') def test_midnight_is_zero_hours(self): - self.assertEqual('00:00', str(Clock(24, 0))) + self.assertEqual(str(Clock(24, 0)), '00:00') def test_hour_rolls_over(self): - self.assertEqual('01:00', str(Clock(25, 0))) + self.assertEqual(str(Clock(25, 0)), '01:00') def test_hour_rolls_over_continuously(self): - self.assertEqual('04:00', str(Clock(100, 0))) + self.assertEqual(str(Clock(100, 0)), '04:00') def test_sixty_minutes_is_next_hour(self): - self.assertEqual('02:00', str(Clock(1, 60))) + self.assertEqual(str(Clock(1, 60)), '02:00') def test_minutes_roll_over(self): - self.assertEqual('02:40', str(Clock(0, 160))) + self.assertEqual(str(Clock(0, 160)), '02:40') def test_minutes_roll_over_continuously(self): - self.assertEqual('04:43', str(Clock(0, 1723))) + self.assertEqual(str(Clock(0, 1723)), '04:43') def test_hour_and_minutes_roll_over(self): - self.assertEqual('03:40', str(Clock(25, 160))) + self.assertEqual(str(Clock(25, 160)), '03:40') def test_hour_and_minutes_roll_over_continuously(self): - self.assertEqual('11:01', str(Clock(201, 3001))) + self.assertEqual(str(Clock(201, 3001)), '11:01') def test_hour_and_minutes_roll_over_to_exactly_midnight(self): - self.assertEqual('00:00', str(Clock(72, 8640))) + self.assertEqual(str(Clock(72, 8640)), '00:00') def test_negative_hour(self): - self.assertEqual('23:15', str(Clock(-1, 15))) + self.assertEqual(str(Clock(-1, 15)), '23:15') def test_negative_hour_rolls_over(self): - self.assertEqual('23:00', str(Clock(-25, 0))) + self.assertEqual(str(Clock(-25, 0)), '23:00') def test_negative_hour_rolls_over_continuously(self): - self.assertEqual('05:00', str(Clock(-91, 0))) + self.assertEqual(str(Clock(-91, 0)), '05:00') def test_negative_minutes(self): - self.assertEqual('00:20', str(Clock(1, -40))) + self.assertEqual(str(Clock(1, -40)), '00:20') def test_negative_minutes_roll_over(self): - self.assertEqual('22:20', str(Clock(1, -160))) + self.assertEqual(str(Clock(1, -160)), '22:20') def test_negative_minutes_roll_over_continuously(self): - self.assertEqual('16:40', str(Clock(1, -4820))) + self.assertEqual(str(Clock(1, -4820)), '16:40') def test_negative_hour_and_minutes_both_roll_over(self): - self.assertEqual('20:20', str(Clock(-25, -160))) + self.assertEqual(str(Clock(-25, -160)), '20:20') def test_negative_hour_and_minutes_both_roll_over_continuously(self): - self.assertEqual('22:10', str(Clock(-121, -5810))) + self.assertEqual(str(Clock(-121, -5810)), '22:10') # Test adding and subtracting minutes. def test_add_minutes(self): - self.assertEqual('10:03', str(Clock(10, 0).add(3))) + self.assertEqual(str(Clock(10, 0).add(3)), '10:03') def test_add_no_minutes(self): - self.assertEqual('06:41', str(Clock(6, 41).add(0))) + self.assertEqual(str(Clock(6, 41).add(0)), '06:41') def test_add_to_next_hour(self): - self.assertEqual('01:25', str(Clock(0, 45).add(40))) + self.assertEqual(str(Clock(0, 45).add(40)), '01:25') def test_add_more_than_one_hour(self): - self.assertEqual('11:01', str(Clock(10, 0).add(61))) + self.assertEqual(str(Clock(10, 0).add(61)), '11:01') def test_add_more_than_two_hours_with_carry(self): - self.assertEqual('03:25', str(Clock(0, 45).add(160))) + self.assertEqual(str(Clock(0, 45).add(160)), '03:25') def test_add_across_midnight(self): - self.assertEqual('00:01', str(Clock(23, 59).add(2))) + self.assertEqual(str(Clock(23, 59).add(2)), '00:01') def test_add_more_than_one_day(self): - self.assertEqual('06:32', str(Clock(5, 32).add(1500))) + self.assertEqual(str(Clock(5, 32).add(1500)), '06:32') def test_add_more_than_two_days(self): - self.assertEqual('11:21', str(Clock(1, 1).add(3500))) + self.assertEqual(str(Clock(1, 1).add(3500)), '11:21') def test_subtract_minutes(self): - self.assertEqual('10:00', str(Clock(10, 3).add(-3))) + self.assertEqual(str(Clock(10, 3).add(-3)), '10:00') def test_subtract_to_previous_hour(self): - self.assertEqual('10:00', str(Clock(10, 3).add(-3))) + self.assertEqual(str(Clock(10, 3).add(-3)), '10:00') def test_subtract_more_than_an_hour(self): - self.assertEqual('09:33', str(Clock(10, 3).add(-30))) + self.assertEqual(str(Clock(10, 3).add(-30)), '09:33') def test_subtract_across_midnight(self): - self.assertEqual('08:53', str(Clock(10, 3).add(-70))) + self.assertEqual(str(Clock(10, 3).add(-70)), '08:53') def test_subtract_more_than_two_hours(self): - self.assertEqual('21:20', str(Clock(0, 0).add(-160))) + self.assertEqual(str(Clock(0, 0).add(-160)), '21:20') def test_subtract_more_than_two_hours_with_borrow(self): - self.assertEqual('03:35', str(Clock(6, 15).add(-160))) + self.assertEqual(str(Clock(6, 15).add(-160)), '03:35') def test_subtract_more_than_one_day(self): - self.assertEqual('04:32', str(Clock(5, 32).add(-1500))) + self.assertEqual(str(Clock(5, 32).add(-1500)), '04:32') def test_subtract_more_than_two_days(self): - self.assertEqual('00:20', str(Clock(2, 20).add(-3000))) + self.assertEqual(str(Clock(2, 20).add(-3000)), '00:20') # Construct two separate clocks, set times, test if they are equal. def test_clocks_with_same_time(self): diff --git a/exercises/crypto-square/crypto_square_test.py b/exercises/crypto-square/crypto_square_test.py index 0f7bb478e6..e4b5160fc4 100644 --- a/exercises/crypto-square/crypto_square_test.py +++ b/exercises/crypto-square/crypto_square_test.py @@ -4,26 +4,25 @@ class CryptoSquareTest(unittest.TestCase): - def test_empty_string(self): - self.assertEqual('', encode('')) + self.assertEqual(encode(''), '') def test_perfect_square(self): - self.assertEqual('ac bd', encode('ABCD')) + self.assertEqual(encode('ABCD'), 'ac bd') def test_small_imperfect_square(self): - self.assertEqual('tis hsy ie sa', encode('This is easy!')) + self.assertEqual(encode('This is easy!'), 'tis hsy ie sa') def test_punctuation_and_numbers(self): msg = "1, 2, 3, Go! Go, for God's sake!" ciph = '1gga 2ook 3fde gos ors' - self.assertEqual(ciph, encode(msg)) + self.assertEqual(encode(msg), ciph) def test_long_string(self): msg = ("If man was meant to stay on the ground, god would have given " "us roots.") ciph = "imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau" - self.assertEqual(ciph, encode(msg)) + self.assertEqual(encode(msg), ciph) if __name__ == '__main__': diff --git a/exercises/diamond/diamond_test.py b/exercises/diamond/diamond_test.py index 0134218fa4..6821fcbf0c 100644 --- a/exercises/diamond/diamond_test.py +++ b/exercises/diamond/diamond_test.py @@ -4,9 +4,8 @@ class DiamondTests(unittest.TestCase): - def test_letter_A(self): - self.assertMultiLineEqual('A\n', make_diamond('A')) + self.assertMultiLineEqual(make_diamond('A'), 'A\n') def test_letter_C(self): result = [' A ', @@ -14,7 +13,7 @@ def test_letter_C(self): 'C C', ' B B ', ' A '] - self.assertMultiLineEqual('\n'.join(result) + '\n', make_diamond('C')) + self.assertMultiLineEqual(make_diamond('C'), '\n'.join(result) + '\n') def test_letter_E(self): result = [' A ', @@ -26,7 +25,7 @@ def test_letter_E(self): ' C C ', ' B B ', ' A '] - self.assertMultiLineEqual('\n'.join(result) + '\n', make_diamond('E')) + self.assertMultiLineEqual(make_diamond('E'), '\n'.join(result) + '\n') if __name__ == '__main__': diff --git a/exercises/etl/etl_test.py b/exercises/etl/etl_test.py index 0567b9b378..7c89795a9a 100644 --- a/exercises/etl/etl_test.py +++ b/exercises/etl/etl_test.py @@ -8,13 +8,13 @@ def test_transform_one_value(self): old = {1: ['WORLD']} expected = {'world': 1} - self.assertEqual(expected, etl.transform(old)) + self.assertEqual(etl.transform(old), expected) def test_transform_more_values(self): old = {1: ['WORLD', 'GSCHOOLERS']} expected = {'world': 1, 'gschoolers': 1} - self.assertEqual(expected, etl.transform(old)) + self.assertEqual(etl.transform(old), expected) def test_more_keys(self): old = {1: ['APPLE', 'ARTICHOKE'], 2: ['BOAT', 'BALLERINA']} @@ -25,7 +25,7 @@ def test_more_keys(self): 'ballerina': 2 } - self.assertEqual(expected, etl.transform(old)) + self.assertEqual(etl.transform(old), expected) def test_full_dataset(self): old = { @@ -47,7 +47,7 @@ def test_full_dataset(self): "z": 10 } - self.assertEqual(expected, etl.transform(old)) + self.assertEqual(etl.transform(old), expected) if __name__ == '__main__': diff --git a/exercises/gigasecond/gigasecond_test.py b/exercises/gigasecond/gigasecond_test.py index 48e58e34e9..f868859182 100644 --- a/exercises/gigasecond/gigasecond_test.py +++ b/exercises/gigasecond/gigasecond_test.py @@ -7,43 +7,35 @@ class GigasecondTest(unittest.TestCase): def test_1(self): self.assertEqual( - datetime(2043, 1, 1, 1, 46, 40), - add_gigasecond(datetime(2011, 4, 25)) - ) + add_gigasecond(datetime(2011, 4, 25)), + datetime(2043, 1, 1, 1, 46, 40)) def test_2(self): self.assertEqual( - datetime(2009, 2, 19, 1, 46, 40), - add_gigasecond(datetime(1977, 6, 13)) - ) + add_gigasecond(datetime(1977, 6, 13)), + datetime(2009, 2, 19, 1, 46, 40)) def test_3(self): self.assertEqual( - datetime(1991, 3, 27, 1, 46, 40), - add_gigasecond(datetime(1959, 7, 19)) - ) + add_gigasecond(datetime(1959, 7, 19)), + datetime(1991, 3, 27, 1, 46, 40)) def test_4(self): self.assertEqual( - datetime(2046, 10, 2, 23, 46, 40), - add_gigasecond(datetime(2015, 1, 24, 22, 0, 0)) - ) + add_gigasecond(datetime(2015, 1, 24, 22, 0, 0)), + datetime(2046, 10, 2, 23, 46, 40)) def test_5(self): self.assertEqual( - datetime(2046, 10, 3, 1, 46, 39), - add_gigasecond(datetime(2015, 1, 24, 23, 59, 59)) - ) + add_gigasecond(datetime(2015, 1, 24, 23, 59, 59)), + datetime(2046, 10, 3, 1, 46, 39)) def test_yourself(self): # customize this to test your birthday and find your gigasecond date: your_birthday = datetime(1970, 1, 1) your_gigasecond = datetime(2001, 9, 9, 1, 46, 40) - self.assertEqual( - your_gigasecond, - add_gigasecond(your_birthday) - ) + self.assertEqual(add_gigasecond(your_birthday), your_gigasecond) if __name__ == '__main__': diff --git a/exercises/grade-school/grade_school_test.py b/exercises/grade-school/grade_school_test.py index be22eaa064..29540a924c 100644 --- a/exercises/grade-school/grade_school_test.py +++ b/exercises/grade-school/grade_school_test.py @@ -1,6 +1,6 @@ +import unittest from collections import Sequence from types import GeneratorType -import unittest from grade_school import School @@ -14,40 +14,37 @@ def setUp(self): def test_an_empty_school(self): for n in range(1, 9): - self.assertCountEqual(set(), self.school.grade(n)) + self.assertCountEqual(self.school.grade(n), set()) def test_add_student(self): self.school.add("Aimee", 2) - self.assertCountEqual(("Aimee",), self.school.grade(2)) + self.assertCountEqual(self.school.grade(2), ("Aimee", )) def test_add_more_students_in_same_class(self): self.school.add("James", 2) self.school.add("Blair", 2) self.school.add("Paul", 2) - self.assertCountEqual(("James", "Blair", "Paul"), self.school.grade(2)) + self.assertCountEqual(self.school.grade(2), ("James", "Blair", "Paul")) def test_add_students_to_different_grades(self): self.school.add("Chelsea", 3) self.school.add("Logan", 7) - self.assertCountEqual(("Chelsea",), self.school.grade(3)) - self.assertCountEqual(("Logan",), self.school.grade(7)) + self.assertCountEqual(self.school.grade(3), ("Chelsea", )) + self.assertCountEqual(self.school.grade(7), ("Logan", )) def test_get_students_in_a_grade(self): self.school.add("Franklin", 5) self.school.add("Bradley", 5) self.school.add("Jeff", 1) - self.assertCountEqual(("Franklin", "Bradley"), self.school.grade(5)) + self.assertCountEqual(self.school.grade(5), ("Franklin", "Bradley")) def test_get_students_in_a_non_existant_grade(self): - self.assertCountEqual(set(), self.school.grade(1)) + self.assertCountEqual(self.school.grade(1), set()) def test_sort_school(self): + students = [(3, ("Kyle", )), (4, ("Christopher", "Jennifer", )), + (6, ("Kareem", ))] - students = [ - (3, ("Kyle",)), - (4, ("Christopher", "Jennifer",)), - (6, ("Kareem",)) - ] for grade, students_in_grade in students: for student in students_in_grade: self.school.add(student, grade) @@ -55,14 +52,15 @@ def test_sort_school(self): result = self.school.sort() # Attempts to catch false positives - self.assertTrue(isinstance(result, Sequence) or - isinstance(result, GeneratorType) or - callable(getattr(result, '__reversed__', False))) + self.assertTrue( + isinstance(result, Sequence) or + isinstance(result, GeneratorType) or + callable(getattr(result, '__reversed__', False))) - result_list = list(result.items() if hasattr(result, "items") - else result) + result_list = list(result.items() + if hasattr(result, "items") else result) - self.assertEqual(result_list, students) + self.assertEqual(students, result_list) if __name__ == '__main__': diff --git a/exercises/grains/grains_test.py b/exercises/grains/grains_test.py index 50d46e735b..ce15b1a955 100644 --- a/exercises/grains/grains_test.py +++ b/exercises/grains/grains_test.py @@ -5,32 +5,32 @@ class GrainsTest(unittest.TestCase): def test_square_1(self): - self.assertEqual(1, on_square(1)) - self.assertEqual(1, total_after(1)) + self.assertEqual(on_square(1), 1) + self.assertEqual(total_after(1), 1) def test_square_2(self): - self.assertEqual(2, on_square(2)) - self.assertEqual(3, total_after(2)) + self.assertEqual(on_square(2), 2) + self.assertEqual(total_after(2), 3) def test_square_3(self): - self.assertEqual(4, on_square(3)) - self.assertEqual(7, total_after(3)) + self.assertEqual(on_square(3), 4) + self.assertEqual(total_after(3), 7) def test_square_4(self): - self.assertEqual(8, on_square(4)) - self.assertEqual(15, total_after(4)) + self.assertEqual(on_square(4), 8) + self.assertEqual(total_after(4), 15) def test_square_16(self): - self.assertEqual(32768, on_square(16)) - self.assertEqual(65535, total_after(16)) + self.assertEqual(on_square(16), 32768) + self.assertEqual(total_after(16), 65535) def test_square_32(self): - self.assertEqual(2147483648, on_square(32)) - self.assertEqual(4294967295, total_after(32)) + self.assertEqual(on_square(32), 2147483648) + self.assertEqual(total_after(32), 4294967295) def test_square_64(self): - self.assertEqual(9223372036854775808, on_square(64)) - self.assertEqual(18446744073709551615, total_after(64)) + self.assertEqual(on_square(64), 9223372036854775808) + self.assertEqual(total_after(64), 18446744073709551615) if __name__ == '__main__': diff --git a/exercises/grep/grep_test.py b/exercises/grep/grep_test.py index 70c7bc48e3..2d486f9465 100644 --- a/exercises/grep/grep_test.py +++ b/exercises/grep/grep_test.py @@ -3,7 +3,6 @@ from grep import grep - ILIADFILENAME = 'iliad.txt' ILIADCONTENTS = '''Achilles sing, O Goddess! Peleus' son; His wrath pernicious, who ten thousand woes @@ -51,7 +50,6 @@ def create_file(name, contents): class GrepTest(unittest.TestCase): - @classmethod def setUpClass(self): create_file(ILIADFILENAME, ILIADCONTENTS) @@ -67,67 +65,57 @@ def tearDownClass(self): def test_one_file_one_match_no_flags(self): self.assertMultiLineEqual( grep("Agamemnon", [ILIADFILENAME]), - "Of Atreus, Agamemnon, King of men.\n" - ) + "Of Atreus, Agamemnon, King of men.\n") def test_one_file_one_match_print_line_numbers_flag(self): self.assertMultiLineEqual( grep("Forbidden", [PARADISELOSTFILENAME], "-n"), - "2:Of that Forbidden Tree, whose mortal tast\n" - ) + "2:Of that Forbidden Tree, whose mortal tast\n") def test_one_file_one_match_case_insensitive_flag(self): self.assertMultiLineEqual( grep("FORBIDDEN", [PARADISELOSTFILENAME], "-i"), - "Of that Forbidden Tree, whose mortal tast\n" - ) + "Of that Forbidden Tree, whose mortal tast\n") def test_one_file_one_match_print_file_names_flag(self): self.assertMultiLineEqual( grep("Forbidden", [PARADISELOSTFILENAME], "-l"), - PARADISELOSTFILENAME + '\n' - ) + PARADISELOSTFILENAME + '\n') def test_one_file_one_match_match_entire_lines_flag(self): self.assertMultiLineEqual( - grep("With loss of Eden, till one greater Man", [PARADISELOSTFILENAME], "-x"), - "With loss of Eden, till one greater Man\n" - ) + grep("With loss of Eden, till one greater Man", + [PARADISELOSTFILENAME], "-x"), + "With loss of Eden, till one greater Man\n") def test_one_file_one_match_multiple_flags(self): self.assertMultiLineEqual( - grep("OF ATREUS, Agamemnon, KIng of MEN.", [ILIADFILENAME], "-n -i -x"), - "9:Of Atreus, Agamemnon, King of men.\n" - ) + grep("OF ATREUS, Agamemnon, KIng of MEN.", [ILIADFILENAME], + "-n -i -x"), "9:Of Atreus, Agamemnon, King of men.\n") def test_one_file_several_matches_no_flags(self): self.assertMultiLineEqual( grep("may", [MIDSUMMERNIGHTFILENAME]), ("Nor how it may concern my modesty,\n" "But I beseech your grace that I may know\n" - "The worst that may befall me in this case,\n") - ) + "The worst that may befall me in this case,\n")) def test_one_file_several_matches_print_line_numbers_flag(self): self.assertMultiLineEqual( grep("may", [MIDSUMMERNIGHTFILENAME], "-n"), ("3:Nor how it may concern my modesty,\n" "5:But I beseech your grace that I may know\n" - "6:The worst that may befall me in this case,\n") - ) + "6:The worst that may befall me in this case,\n")) def test_one_file_several_matches_match_entire_lines_flag(self): self.assertMultiLineEqual( - grep("may", [MIDSUMMERNIGHTFILENAME], "-x"), - "" - ) + grep("may", [MIDSUMMERNIGHTFILENAME], "-x"), "") def test_one_file_several_matches_case_insensitive_flag(self): self.assertMultiLineEqual( grep("ACHILLES", [ILIADFILENAME], "-i"), ("Achilles sing, O Goddess! Peleus' son;\n" - "The noble Chief Achilles from the son\n") - ) + "The noble Chief Achilles from the son\n")) def test_one_file_several_matches_inverted_flag(self): self.assertMultiLineEqual( @@ -136,89 +124,88 @@ def test_one_file_several_matches_inverted_flag(self): "With loss of Eden, till one greater Man\n" "Restore us, and regain the blissful Seat,\n" "Sing Heav'nly Muse, that on the secret top\n" - "That Shepherd, who first taught the chosen Seed\n") - ) + "That Shepherd, who first taught the chosen Seed\n")) def test_one_file_no_matches_various_flags(self): self.assertMultiLineEqual( - grep("Gandalf", [ILIADFILENAME], "-n -l -x -i"), - "" - ) + grep("Gandalf", [ILIADFILENAME], "-n -l -x -i"), "") def test_multiple_files_one_match_no_flags(self): self.assertMultiLineEqual( - grep("Agamemnon", [ILIADFILENAME, MIDSUMMERNIGHTFILENAME, PARADISELOSTFILENAME]), - "iliad.txt:Of Atreus, Agamemnon, King of men.\n" - ) + grep( + "Agamemnon", + [ILIADFILENAME, MIDSUMMERNIGHTFILENAME, PARADISELOSTFILENAME]), + "iliad.txt:Of Atreus, Agamemnon, King of men.\n") def test_multiple_files_several_matches_no_flags(self): self.assertMultiLineEqual( - grep("may", ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"]), + grep("may", + ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"]), ("midsummer-night.txt:Nor how it may concern my modesty,\n" "midsummer-night.txt:But I beseech your grace that I may know\n" - "midsummer-night.txt:The worst that may befall me in this case,\n") - ) + "midsummer-night.txt:The worst that may befall me in this case,\n" + )) def test_multiple_files_several_matches_print_line_numbers_flag(self): self.assertMultiLineEqual( - grep("that", ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], "-n"), + grep("that", + ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], + "-n"), ("midsummer-night.txt:5:But I beseech your grace that I may know\n" - "midsummer-night.txt:6:The worst that may befall me in this case,\n" - "paradise-lost.txt:2:Of that Forbidden Tree, whose mortal tast\n" - "paradise-lost.txt:6:Sing Heav'nly Muse, that on the secret top\n") - ) + "midsummer-night.txt:6:The worst that may befall me in this case," + "\nparadise-lost.txt:2:Of that Forbidden Tree, whose mortal tast" + "\nparadise-lost.txt:6:Sing Heav'nly Muse, that on the secret top" + "\n")) def test_multiple_files_one_match_print_file_names_flag(self): self.assertMultiLineEqual( - grep("who", ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], "-l"), - ILIADFILENAME + '\n' + PARADISELOSTFILENAME + '\n' - ) + grep("who", + ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], + "-l"), ILIADFILENAME + '\n' + PARADISELOSTFILENAME + '\n') def test_multiple_files_several_matches_case_insensitive_flag(self): self.assertMultiLineEqual( - grep("TO", ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], "-i"), + grep("TO", + ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], + "-i"), ("iliad.txt:Caused to Achaia's host, sent many a soul\n" "iliad.txt:Illustrious into Ades premature,\n" "iliad.txt:And Heroes gave (so stood the will of Jove)\n" "iliad.txt:To dogs and to all ravening fowls a prey,\n" "midsummer-night.txt:I do entreat your grace to pardon me.\n" - "midsummer-night.txt:In such a presence here to plead my thoughts;\n" - "midsummer-night.txt:If I refuse to wed Demetrius.\n" - "paradise-lost.txt:Brought Death into the World, and all our woe,\n" - "paradise-lost.txt:Restore us, and regain the blissful Seat,\n" - "paradise-lost.txt:Sing Heav'nly Muse, that on the secret top\n") - ) + "midsummer-night.txt:In such a presence here to plead my thoughts" + ";\nmidsummer-night.txt:If I refuse to wed Demetrius.\n" + "paradise-lost.txt:Brought Death into the World, and all our woe," + "\nparadise-lost.txt:Restore us, and regain the blissful Seat,\n" + "paradise-lost.txt:Sing Heav'nly Muse, that on the secret top\n")) def test_multiple_files_several_matches_inverted_flag(self): self.assertMultiLineEqual( - grep("a", ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], "-v"), - ("iliad.txt:Achilles sing, O Goddess! Peleus' son;\n" - "iliad.txt:The noble Chief Achilles from the son\n" - "midsummer-night.txt:If I refuse to wed Demetrius.\n") - ) + grep( + "a", ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], + "-v"), ("iliad.txt:Achilles sing, O Goddess! Peleus' son;\n" + "iliad.txt:The noble Chief Achilles from the son\n" + "midsummer-night.txt:If I refuse to wed Demetrius.\n")) def test_multiple_files_one_match_match_entire_lines_flag(self): self.assertMultiLineEqual( grep("But I beseech your grace that I may know", ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], "-x"), - "midsummer-night.txt:But I beseech your grace that I may know\n" - ) + "midsummer-night.txt:But I beseech your grace that I may know\n") def test_multiple_files_one_match_multiple_flags(self): self.assertMultiLineEqual( grep("WITH LOSS OF EDEN, TILL ONE GREATER MAN", ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], "-n -i -x"), - "paradise-lost.txt:4:With loss of Eden, till one greater Man\n" - ) + "paradise-lost.txt:4:With loss of Eden, till one greater Man\n") def test_multiple_files_no_matches_various_flags(self): self.assertMultiLineEqual( - grep("Frodo", ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], - "-n -l -x -i"), - "" - ) + grep("Frodo", + ["iliad.txt", "midsummer-night.txt", "paradise-lost.txt"], + "-n -l -x -i"), "") if __name__ == '__main__': diff --git a/exercises/hamming/hamming_test.py b/exercises/hamming/hamming_test.py index c2e5a417b2..15cd14bb72 100644 --- a/exercises/hamming/hamming_test.py +++ b/exercises/hamming/hamming_test.py @@ -8,43 +8,43 @@ class HammingTest(unittest.TestCase): def test_identical_strands(self): - self.assertEqual(0, hamming.distance("A", "A")) + self.assertEqual(hamming.distance("A", "A"), 0) def test_long_identical_strands(self): - self.assertEqual(0, hamming.distance("GGACTGA", "GGACTGA")) + self.assertEqual(hamming.distance("GGACTGA", "GGACTGA"), 0) def test_complete_distance_in_single_nucleotide_strands(self): - self.assertEqual(1, hamming.distance("A", "G")) + self.assertEqual(hamming.distance("A", "G"), 1) def test_complete_distance_in_small_strands(self): - self.assertEqual(2, hamming.distance("AG", "CT")) + self.assertEqual(hamming.distance("AG", "CT"), 2) def test_small_distance_in_small_strands(self): - self.assertEqual(1, hamming.distance("AT", "CT")) + self.assertEqual(hamming.distance("AT", "CT"), 1) def test_small_distance(self): - self.assertEqual(1, hamming.distance("GGACG", "GGTCG")) + self.assertEqual(hamming.distance("GGACG", "GGTCG"), 1) def test_small_distance_in_long_strands(self): - self.assertEqual(2, hamming.distance("ACCAGGG", "ACTATGG")) + self.assertEqual(hamming.distance("ACCAGGG", "ACTATGG"), 2) def test_non_unique_character_in_first_strand(self): - self.assertEqual(1, hamming.distance("AGA", "AGG")) + self.assertEqual(hamming.distance("AGA", "AGG"), 1) def test_non_unique_character_in_second_strand(self): - self.assertEqual(1, hamming.distance("AGG", "AGA")) + self.assertEqual(hamming.distance("AGG", "AGA"), 1) def test_same_nucleotides_in_different_positions(self): - self.assertEqual(2, hamming.distance("TAG", "GAT")) + self.assertEqual(hamming.distance("TAG", "GAT"), 2) def test_large_distance(self): - self.assertEqual(4, hamming.distance("GATACA", "GCATAA")) + self.assertEqual(hamming.distance("GATACA", "GCATAA"), 4) def test_large_distance_in_off_by_one_strand(self): - self.assertEqual(9, hamming.distance("GGACGGATTCTG", "AGGACGGATTCT")) + self.assertEqual(hamming.distance("GGACGGATTCTG", "AGGACGGATTCT"), 9) def test_empty_strands(self): - self.assertEqual(0, hamming.distance("", "")) + self.assertEqual(hamming.distance("", ""), 0) def test_disallow_first_strand_longer(self): with self.assertRaises(ValueError): diff --git a/exercises/hello-world/hello_world_test.py b/exercises/hello-world/hello_world_test.py index b7b6ec1aec..c0e5178f1d 100644 --- a/exercises/hello-world/hello_world_test.py +++ b/exercises/hello-world/hello_world_test.py @@ -6,9 +6,8 @@ # test cases adapted from `x-common//canonical-data.json` @ version: 1.0.0 class HelloWorldTests(unittest.TestCase): - def test_hello(self): - self.assertEqual('Hello, World!', hello_world.hello()) + self.assertEqual(hello_world.hello(), 'Hello, World!') if __name__ == '__main__': diff --git a/exercises/hexadecimal/hexadecimal_test.py b/exercises/hexadecimal/hexadecimal_test.py index 1ddbcf8e8c..c805b32a66 100644 --- a/exercises/hexadecimal/hexadecimal_test.py +++ b/exercises/hexadecimal/hexadecimal_test.py @@ -7,33 +7,32 @@ class HexadecimalTest(unittest.TestCase): - def test_valid_hexa1(self): - self.assertEqual(1, hexa('1')) + self.assertEqual(hexa('1'), 1) def test_valid_hexa2(self): - self.assertEqual(12, hexa('c')) + self.assertEqual(hexa('c'), 12) def test_valid_hexa3(self): - self.assertEqual(16, hexa('10')) + self.assertEqual(hexa('10'), 16) def test_valid_hexa4(self): - self.assertEqual(175, hexa('af')) + self.assertEqual(hexa('af'), 175) def test_valid_hexa5(self): - self.assertEqual(256, hexa('100')) + self.assertEqual(hexa('100'), 256) def test_valid_hexa6(self): - self.assertEqual(105166, hexa('19ACE')) + self.assertEqual(hexa('19ACE'), 105166) def test_valid_hexa7(self): - self.assertEqual(0, hexa('000000')) + self.assertEqual(hexa('000000'), 0) def test_valid_hexa8(self): - self.assertEqual(16776960, hexa('ffff00')) + self.assertEqual(hexa('ffff00'), 16776960) def test_valid_hexa9(self): - self.assertEqual(65520, hexa('00fff0')) + self.assertEqual(hexa('00fff0'), 65520) def test_invalid_hexa(self): with self.assertRaises(ValueError): diff --git a/exercises/house/house_test.py b/exercises/house/house_test.py index c4045f9b2c..34a694679b 100644 --- a/exercises/house/house_test.py +++ b/exercises/house/house_test.py @@ -8,25 +8,25 @@ class VerseTest(unittest.TestCase): def test_verse_0(self): expected = 'This is the house that Jack built.' - self.assertEqual(expected, verse(0)) + self.assertEqual(verse(0), expected) def test_verse_1(self): expected = 'This is the malt\n'\ 'that lay in the house that Jack built.' - self.assertEqual(expected, verse(1)) + self.assertEqual(verse(1), expected) def test_verse_2(self): expected = 'This is the rat\n'\ 'that ate the malt\n'\ 'that lay in the house that Jack built.' - self.assertEqual(expected, verse(2)) + self.assertEqual(verse(2), expected) def test_verse_3(self): expected = 'This is the cat\n'\ 'that killed the rat\n'\ 'that ate the malt\n'\ 'that lay in the house that Jack built.' - self.assertEqual(expected, verse(3)) + self.assertEqual(verse(3), expected) def test_verse_11(self): expected = 'This is the horse and the hound and the horn\n'\ @@ -41,7 +41,7 @@ def test_verse_11(self): 'that killed the rat\n'\ 'that ate the malt\n'\ 'that lay in the house that Jack built.' - self.assertEqual(expected, verse(11)) + self.assertEqual(verse(11), expected) def test_rhyme(self): expected = 'This is the house that Jack built.\n\n'\ @@ -122,7 +122,7 @@ def test_rhyme(self): 'that killed the rat\n'\ 'that ate the malt\n'\ 'that lay in the house that Jack built.' - self.assertEqual(expected, rhyme()) + self.assertEqual(rhyme(), expected) if __name__ == '__main__': diff --git a/exercises/kindergarten-garden/kindergarten_garden_test.py b/exercises/kindergarten-garden/kindergarten_garden_test.py index 258d47726b..ca6ad5f415 100644 --- a/exercises/kindergarten-garden/kindergarten_garden_test.py +++ b/exercises/kindergarten-garden/kindergarten_garden_test.py @@ -4,34 +4,37 @@ class KindergartenGardenTests(unittest.TestCase): - def test_alices_garden(self): - self.assertEqual("Radishes Clover Grass Grass".split(), - Garden("RC\nGG").plants("Alice")) + self.assertEqual( + Garden("RC\nGG").plants("Alice"), + "Radishes Clover Grass Grass".split()) def test_bob_and_charlies_gardens(self): garden = Garden("VVCCGG\nVVCCGG") - self.assertEqual(["Clover"] * 4, garden.plants("Bob")) - self.assertEqual(["Grass"] * 4, garden.plants("Charlie")) + self.assertEqual(garden.plants("Bob"), ["Clover"] * 4) + self.assertEqual(garden.plants("Charlie"), ["Grass"] * 4) def test_full_garden(self): garden = Garden("VRCGVVRVCGGCCGVRGCVCGCGV\nVRCCCGCRRGVCGCRVVCVGCGCV") - self.assertEqual("Violets Radishes Violets Radishes".split(), - garden.plants("Alice")) - self.assertEqual("Clover Grass Clover Clover".split(), - garden.plants("Bob")) - self.assertEqual("Grass Clover Clover Grass".split(), - garden.plants("Kincaid")) - self.assertEqual("Grass Violets Clover Violets".split(), - garden.plants("Larry")) + self.assertEqual( + garden.plants("Alice"), + "Violets Radishes Violets Radishes".split()) + self.assertEqual( + garden.plants("Bob"), "Clover Grass Clover Clover".split()) + self.assertEqual( + garden.plants("Kincaid"), "Grass Clover Clover Grass".split()) + self.assertEqual( + garden.plants("Larry"), "Grass Violets Clover Violets".split()) def test_disordered_test(self): - garden = Garden("VCRRGVRG\nRVGCCGCV", - students="Samantha Patricia Xander Roger".split()) - self.assertEqual("Violets Clover Radishes Violets".split(), - garden.plants("Patricia")) - self.assertEqual("Radishes Grass Clover Violets".split(), - garden.plants("Xander")) + garden = Garden( + "VCRRGVRG\nRVGCCGCV", + students="Samantha Patricia Xander Roger".split()) + self.assertEqual( + garden.plants("Patricia"), + "Violets Clover Radishes Violets".split()) + self.assertEqual( + garden.plants("Xander"), "Radishes Grass Clover Violets".split()) if __name__ == '__main__': diff --git a/exercises/largest-series-product/largest_series_product_test.py b/exercises/largest-series-product/largest_series_product_test.py index 6f396a9233..8603178cd4 100644 --- a/exercises/largest-series-product/largest_series_product_test.py +++ b/exercises/largest-series-product/largest_series_product_test.py @@ -13,61 +13,62 @@ class SeriesTest(unittest.TestCase): def test_largest_product_of_2(self): - self.assertEqual(72, largest_product("0123456789", 2)) + self.assertEqual(largest_product("0123456789", 2), 72) def test_largest_product_of_2_unordered(self): - self.assertEqual(48, largest_product("576802143", 2)) + self.assertEqual(largest_product("576802143", 2), 48) def test__largest_product_span_equals_length(self): - self.assertEqual(18, largest_product("29", 2)) + self.assertEqual(largest_product("29", 2), 18) def test_largest_product_of_3(self): - self.assertEqual(504, largest_product("0123456789", 3)) + self.assertEqual(largest_product("0123456789", 3), 504) def test_largest_product_of_3_unordered(self): - self.assertEqual(270, largest_product("1027839564", 3)) + self.assertEqual(largest_product("1027839564", 3), 270) def test_largest_product_of_5(self): - self.assertEqual(15120, largest_product("0123456789", 5)) + self.assertEqual(largest_product("0123456789", 5), 15120) def test_big_number(self): series = "73167176531330624919225119674426574742355349194934" - self.assertEqual(23520, largest_product(series, 6)) + self.assertEqual(largest_product(series, 6), 23520) def test_another_big_number(self): series = "52677741234314237566414902593461595376319419139427" - self.assertEqual(28350, largest_product(series, 6)) + self.assertEqual(largest_product(series, 6), 28350) def test_project_euler_big_number(self): series = ( - "731671765313306249192251196744265747423553491949349698352031277450632623957" - "831801698480186947885184385861560789112949495459501737958331952853208805511" - "125406987471585238630507156932909632952274430435576689664895044524452316173" - "185640309871112172238311362229893423380308135336276614282806444486645238749" - "303589072962904915604407723907138105158593079608667017242712188399879790879" - "227492190169972088809377665727333001053367881220235421809751254540594752243" - "525849077116705560136048395864467063244157221553975369781797784617406495514" - "929086256932197846862248283972241375657056057490261407972968652414535100474" - "821663704844031998900088952434506585412275886668811642717147992444292823086" - "346567481391912316282458617866458359124566529476545682848912883142607690042" - "242190226710556263211111093705442175069416589604080719840385096245544436298" - "123098787992724428490918884580156166097919133875499200524063689912560717606" - "058861164671094050775410022569831552000559357297257163626956188267042825248" - "3600823257530420752963450" - ) - self.assertEqual(23514624000, largest_product(series, 13)) + "73167176531330624919225119674426574742355349194934969835203127745" + "06326239578318016984801869478851843858615607891129494954595017379" + "58331952853208805511125406987471585238630507156932909632952274430" + "43557668966489504452445231617318564030987111217223831136222989342" + "33803081353362766142828064444866452387493035890729629049156044077" + "23907138105158593079608667017242712188399879790879227492190169972" + "08880937766572733300105336788122023542180975125454059475224352584" + "90771167055601360483958644670632441572215539753697817977846174064" + "95514929086256932197846862248283972241375657056057490261407972968" + "65241453510047482166370484403199890008895243450658541227588666881" + "16427171479924442928230863465674813919123162824586178664583591245" + "66529476545682848912883142607690042242190226710556263211111093705" + "44217506941658960408071984038509624554443629812309878799272442849" + "09188845801561660979191338754992005240636899125607176060588611646" + "71094050775410022569831552000559357297257163626956188267042825248" + "3600823257530420752963450") + self.assertEqual(largest_product(series, 13), 23514624000) def test_all_digits_zero(self): - self.assertEqual(0, largest_product("0000", 2)) + self.assertEqual(largest_product("0000", 2), 0) def test_all_spans_contain_zero(self): - self.assertEqual(0, largest_product("99099", 3)) + self.assertEqual(largest_product("99099", 3), 0) def test_identity_with_empty_string(self): - self.assertEqual(1, largest_product("", 0)) + self.assertEqual(largest_product("", 0), 1) def test_identity_with_nonempty_string(self): - self.assertEqual(1, largest_product("123", 0)) + self.assertEqual(largest_product("123", 0), 1) def test_span_long_than_number(self): with self.assertRaises(ValueError): diff --git a/exercises/linked-list/linked_list_test.py b/exercises/linked-list/linked_list_test.py index cf7dffde2f..70d380532f 100644 --- a/exercises/linked-list/linked_list_test.py +++ b/exercises/linked-list/linked_list_test.py @@ -4,63 +4,62 @@ class LinkedListTests(unittest.TestCase): - def setUp(self): self.list = LinkedList() def test_push_pop(self): self.list.push(10) self.list.push(20) - self.assertEqual(20, self.list.pop()) - self.assertEqual(10, self.list.pop()) + self.assertEqual(self.list.pop(), 20) + self.assertEqual(self.list.pop(), 10) def test_push_shift(self): self.list.push(10) self.list.push(20) - self.assertEqual(10, self.list.shift()) - self.assertEqual(20, self.list.shift()) + self.assertEqual(self.list.shift(), 10) + self.assertEqual(self.list.shift(), 20) def test_unshift_shift(self): self.list.unshift(10) self.list.unshift(20) - self.assertEqual(20, self.list.shift()) - self.assertEqual(10, self.list.shift()) + self.assertEqual(self.list.shift(), 20) + self.assertEqual(self.list.shift(), 10) def test_unshift_pop(self): self.list.unshift(10) self.list.unshift(20) - self.assertEqual(10, self.list.pop()) - self.assertEqual(20, self.list.pop()) + self.assertEqual(self.list.pop(), 10) + self.assertEqual(self.list.pop(), 20) def test_all(self): self.list.push(10) self.list.push(20) - self.assertEqual(20, self.list.pop()) + self.assertEqual(self.list.pop(), 20) self.list.push(30) - self.assertEqual(10, self.list.shift()) + self.assertEqual(self.list.shift(), 10) self.list.unshift(40) self.list.push(50) - self.assertEqual(40, self.list.shift()) - self.assertEqual(50, self.list.pop()) - self.assertEqual(30, self.list.shift()) + self.assertEqual(self.list.shift(), 40) + self.assertEqual(self.list.pop(), 50) + self.assertEqual(self.list.shift(), 30) @unittest.skip("extra-credit") def test_length(self): self.list.push(10) self.list.push(20) - self.assertEqual(2, len(self.list)) + self.assertEqual(len(self.list), 2) self.list.shift() - self.assertEqual(1, len(self.list)) + self.assertEqual(len(self.list), 1) self.list.pop() - self.assertEqual(0, len(self.list)) + self.assertEqual(len(self.list), 0) @unittest.skip("extra-credit") def test_iterator(self): self.list.push(10) self.list.push(20) iterator = iter(self.list) - self.assertEqual(10, next(iterator)) - self.assertEqual(20, next(iterator)) + self.assertEqual(next(iterator), 10) + self.assertEqual(next(iterator), 20) if __name__ == '__main__': diff --git a/exercises/list-ops/list_ops_test.py b/exercises/list-ops/list_ops_test.py index ffe3105945..14b11a2eeb 100644 --- a/exercises/list-ops/list_ops_test.py +++ b/exercises/list-ops/list_ops_test.py @@ -9,112 +9,117 @@ class ListOpsTest(unittest.TestCase): # tests for map def test_map_square(self): self.assertEqual( - [1, 4, 9, 16, 25, 36, 49, 64, 81, 100], - list_ops.map_clone( - lambda x: x**2, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])) + list_ops.map_clone(lambda x: x**2, + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), + [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]) def test_map_cube(self): self.assertEqual( - [-1, 8, -27, 64, -125, 216, -343, 512, -729, 1000], - list_ops.map_clone( - lambda x: x**3, [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10])) + list_ops.map_clone(lambda x: x**3, + [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10]), + [-1, 8, -27, 64, -125, 216, -343, 512, -729, 1000]) def test_map_absolute(self): self.assertEqual( - [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], - list_ops.map_clone( - lambda x: abs(x), [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10])) + list_ops.map_clone(lambda x: abs(x), + [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10]), + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) def test_map_empty(self): - self.assertEqual([], list_ops.map_clone(operator.index, [])) + self.assertEqual(list_ops.map_clone(operator.index, []), []) # tests for length def test_pos_leng(self): - self.assertEqual(10, list_ops.length([-1, 2, -3, 4, -5, 6, -7, 8, -9, 10])) + self.assertEqual( + list_ops.length([-1, 2, -3, 4, -5, 6, -7, 8, -9, 10]), 10) def test_empty_len(self): - self.assertEqual(0, list_ops.length([])) + self.assertEqual(list_ops.length([]), 0) # tests for filter def test_filter_odd(self): self.assertEqual( - [1, 3, 5], - list_ops.filter_clone(lambda x: x % 2 != 0, [1, 2, 3, 4, 5, 6])) + list_ops.filter_clone(lambda x: x % 2 != 0, [1, 2, 3, 4, 5, 6]), + [1, 3, 5]) def test_filter_even(self): self.assertEqual( - [2, 4, 6], - list_ops.filter_clone(lambda x: x % 2 == 0, [1, 2, 3, 4, 5, 6])) + list_ops.filter_clone(lambda x: x % 2 == 0, [1, 2, 3, 4, 5, 6]), + [2, 4, 6]) # tests for reverse def test_reverse_small(self): - self.assertEqual([1, 2, 3], list_ops.reverse([3, 2, 1])) + self.assertEqual(list_ops.reverse([3, 2, 1]), [1, 2, 3]) def test_reverse_mixed_types(self): self.assertEqual( - [1, "cat", 4.0, "xyz"], - list_ops.reverse(["xyz", 4.0, "cat", 1])) + list_ops.reverse(["xyz", 4.0, "cat", 1]), [1, "cat", 4.0, "xyz"]) def test_reverse_empty(self): - self.assertEqual([], list_ops.reverse([])) + self.assertEqual(list_ops.reverse([]), []) # tests for append def test_append_tuple(self): self.assertEqual( - ["10", "python", "hello"], - list_ops.append(["10", "python"], "hello")) + list_ops.append(["10", "python"], "hello"), + ["10", "python", "hello"]) def test_append_range(self): - self.assertEqual([100, range(1000)], list_ops.append([100], range(1000))) + self.assertEqual( + list_ops.append([100], range(1000)), [100, range(1000)]) def test_append_to_empty(self): - self.assertEqual([42], list_ops.append([], 42)) + self.assertEqual(list_ops.append([], 42), [42]) # tests for foldl def test_foldl_sum(self): - self.assertEqual(21, list_ops.foldl(operator.add, [1, 2, 3, 4, 5, 6], 0)) + self.assertEqual( + list_ops.foldl(operator.add, [1, 2, 3, 4, 5, 6], 0), 21) def test_foldl_product(self): - self.assertEqual(720, list_ops.foldl(operator.mul, [1, 2, 3, 4, 5, 6], 1)) + self.assertEqual( + list_ops.foldl(operator.mul, [1, 2, 3, 4, 5, 6], 1), 720) def test_foldl_div(self): - self.assertEqual(0, list_ops.foldl(operator.floordiv, [1, 2, 3, 4, 5, 6], 1)) + self.assertEqual( + list_ops.foldl(operator.floordiv, [1, 2, 3, 4, 5, 6], 1), 0) def test_foldl_sub(self): - self.assertEqual(-15, list_ops.foldl(operator.sub, [1, 2, 3, 4, 5], 0)) + self.assertEqual(list_ops.foldl(operator.sub, [1, 2, 3, 4, 5], 0), -15) # tests for foldr def test_foldr_sub(self): - self.assertEqual(3, list_ops.foldr(operator.sub, [1, 2, 3, 4, 5], 0)) + self.assertEqual(list_ops.foldr(operator.sub, [1, 2, 3, 4, 5], 0), 3) def test_foldr_add_str(self): self.assertEqual( - "exercism!", - list_ops.foldr(operator.add, ["e", "x", "e", "r", "c", "i", "s", "m"], "!")) + list_ops.foldr(operator.add, + ["e", "x", "e", "r", "c", "i", "s", "m"], "!"), + "exercism!") # tests for flatten def test_flatten_nested(self): - self.assertEqual([1, 2, 3, 4], list_ops.flat([[[1, 2], [3]], [[4]]])) + self.assertEqual(list_ops.flat([[[1, 2], [3]], [[4]]]), [1, 2, 3, 4]) def test_flatten_once(self): - self.assertEqual(["x", "y", "z"], list_ops.flat([["x", "y", "z"]])) + self.assertEqual(list_ops.flat([["x", "y", "z"]]), ["x", "y", "z"]) def test_flatten_empty(self): - self.assertEqual([], list_ops.flat([])) + self.assertEqual(list_ops.flat([]), []) # tests for concat def test_concat_two(self): self.assertEqual( - [1, 3, 5, 8, 9, 4, 5, 6], - list_ops.concat([1, 3, 5, 8], [9, 4, 5, 6])) + list_ops.concat([1, 3, 5, 8], [9, 4, 5, 6]), + [1, 3, 5, 8, 9, 4, 5, 6]) def test_concat_nothing(self): self.assertEqual( - ["orange", "apple", "banana"], - list_ops.concat(['orange', 'apple', 'banana'], None)) + list_ops.concat(['orange', 'apple', 'banana'], None), + ["orange", "apple", "banana"]) def test_concat_empty(self): - self.assertEqual([], list_ops.concat([], [])) + self.assertEqual(list_ops.concat([], []), []) if __name__ == '__main__': diff --git a/exercises/matrix/matrix_test.py b/exercises/matrix/matrix_test.py index 2d832c3401..8461e45df2 100644 --- a/exercises/matrix/matrix_test.py +++ b/exercises/matrix/matrix_test.py @@ -6,27 +6,27 @@ class MatrixTest(unittest.TestCase): def test_extract_a_row(self): matrix = Matrix("1 2\n10 20") - self.assertEqual([1, 2], matrix.rows[0]) + self.assertEqual(matrix.rows[0], [1, 2]) def test_extract_same_row_again(self): matrix = Matrix("9 7\n8 6") - self.assertEqual([9, 7], matrix.rows[0]) + self.assertEqual(matrix.rows[0], [9, 7]) def test_extract_other_row(self): matrix = Matrix("9 8 7\n19 18 17") - self.assertEqual([19, 18, 17], matrix.rows[1]) + self.assertEqual(matrix.rows[1], [19, 18, 17]) def test_extract_other_row_again(self): matrix = Matrix("1 4 9\n16 25 36") - self.assertEqual([16, 25, 36], matrix.rows[1]) + self.assertEqual(matrix.rows[1], [16, 25, 36]) def test_extract_a_column(self): matrix = Matrix("1 2 3\n4 5 6\n7 8 9\n8 7 6") - self.assertEqual([1, 4, 7, 8], matrix.columns[0]) + self.assertEqual(matrix.columns[0], [1, 4, 7, 8]) def test_extract_another_column(self): matrix = Matrix("89 1903 3\n18 3 1\n9 4 800") - self.assertEqual([1903, 3, 4], matrix.columns[1]) + self.assertEqual(matrix.columns[1], [1903, 3, 4]) if __name__ == '__main__': diff --git a/exercises/meetup/meetup_test.py b/exercises/meetup/meetup_test.py index 9a54679d01..e4dc3e76b6 100644 --- a/exercises/meetup/meetup_test.py +++ b/exercises/meetup/meetup_test.py @@ -1,5 +1,5 @@ -from datetime import date import unittest +from datetime import date from meetup import meetup_day @@ -11,56 +11,56 @@ class MeetupTest(unittest.TestCase): def test_monteenth_of_may_2013(self): - self.assertEqual(date(2013, 5, 13), - meetup_day(2013, 5, 'Monday', 'teenth')) + self.assertEqual( + meetup_day(2013, 5, 'Monday', 'teenth'), date(2013, 5, 13)) def test_saturteenth_of_february_2013(self): - self.assertEqual(date(2013, 2, 16), - meetup_day(2013, 2, 'Saturday', 'teenth')) + self.assertEqual( + meetup_day(2013, 2, 'Saturday', 'teenth'), date(2013, 2, 16)) def test_first_tuesday_of_may_2013(self): - self.assertEqual(date(2013, 5, 7), - meetup_day(2013, 5, 'Tuesday', '1st')) + self.assertEqual( + meetup_day(2013, 5, 'Tuesday', '1st'), date(2013, 5, 7)) def test_second_monday_of_april_2013(self): - self.assertEqual(date(2013, 4, 8), - meetup_day(2013, 4, 'Monday', '2nd')) + self.assertEqual( + meetup_day(2013, 4, 'Monday', '2nd'), date(2013, 4, 8)) def test_third_thursday_of_september_2013(self): - self.assertEqual(date(2013, 9, 19), - meetup_day(2013, 9, 'Thursday', '3rd')) + self.assertEqual( + meetup_day(2013, 9, 'Thursday', '3rd'), date(2013, 9, 19)) def test_fourth_sunday_of_march_2013(self): - self.assertEqual(date(2013, 3, 24), - meetup_day(2013, 3, 'Sunday', '4th')) + self.assertEqual( + meetup_day(2013, 3, 'Sunday', '4th'), date(2013, 3, 24)) def test_last_thursday_of_october_2013(self): - self.assertEqual(date(2013, 10, 31), - meetup_day(2013, 10, 'Thursday', 'last')) + self.assertEqual( + meetup_day(2013, 10, 'Thursday', 'last'), date(2013, 10, 31)) def test_last_wednesday_of_february_2012(self): - self.assertEqual(date(2012, 2, 29), - meetup_day(2012, 2, 'Wednesday', 'last')) + self.assertEqual( + meetup_day(2012, 2, 'Wednesday', 'last'), date(2012, 2, 29)) def test_last_wednesday_of_december_2014(self): - self.assertEqual(date(2014, 12, 31), - meetup_day(2014, 12, 'Wednesday', 'last')) + self.assertEqual( + meetup_day(2014, 12, 'Wednesday', 'last'), date(2014, 12, 31)) def test_last_sunday_of_only_four_week_february_2015(self): - self.assertEqual(date(2015, 2, 22), - meetup_day(2015, 2, 'Sunday', 'last')) + self.assertEqual( + meetup_day(2015, 2, 'Sunday', 'last'), date(2015, 2, 22)) def test_first_friday_of_december_2012(self): - self.assertEqual(date(2012, 12, 7), - meetup_day(2012, 12, 'Friday', '1st')) + self.assertEqual( + meetup_day(2012, 12, 'Friday', '1st'), date(2012, 12, 7)) def test_fifth_monday_of_march_2015(self): - self.assertEqual(date(2015, 3, 30), - meetup_day(2015, 3, 'Monday', '5th')) + self.assertEqual( + meetup_day(2015, 3, 'Monday', '5th'), date(2015, 3, 30)) def test_nonexistent_fifth_monday_of_february_2015(self): - self.assertRaises(MeetupDayException, meetup_day, - 2015, 2, 'Monday', '5th') + self.assertRaises(MeetupDayException, meetup_day, 2015, 2, 'Monday', + '5th') if __name__ == '__main__': diff --git a/exercises/minesweeper/minesweeper_test.py b/exercises/minesweeper/minesweeper_test.py index d470f61e1a..f3518f3c67 100644 --- a/exercises/minesweeper/minesweeper_test.py +++ b/exercises/minesweeper/minesweeper_test.py @@ -29,7 +29,7 @@ def test_board1(self): "|1*22*2|", "|111111|", "+------+"] - self.assertEqual(out, board(inp)) + self.assertEqual(board(inp), out) def test_board2(self): inp = ["+-----+", @@ -46,7 +46,7 @@ def test_board2(self): "|12*4*|", "|1*3*2|", "+-----+"] - self.assertEqual(out, board(inp)) + self.assertEqual(board(inp), out) def test_board3(self): inp = ["+-----+", @@ -55,7 +55,7 @@ def test_board3(self): out = ["+-----+", "|1*2*1|", "+-----+"] - self.assertEqual(out, board(inp)) + self.assertEqual(board(inp), out) def test_board4(self): inp = ["+-+", @@ -72,7 +72,7 @@ def test_board4(self): "|1|", "| |", "+-+"] - self.assertEqual(out, board(inp)) + self.assertEqual(board(inp), out) def test_board5(self): inp = ["+-+", @@ -81,7 +81,7 @@ def test_board5(self): out = ["+-+", "|*|", "+-+"] - self.assertEqual(out, board(inp)) + self.assertEqual(board(inp), out) def test_board6(self): inp = ["+--+", @@ -92,7 +92,7 @@ def test_board6(self): "|**|", "|**|", "+--+"] - self.assertEqual(out, board(inp)) + self.assertEqual(board(inp), out) def test_board7(self): inp = ["+--+", @@ -103,7 +103,7 @@ def test_board7(self): "|**|", "|**|", "+--+"] - self.assertEqual(out, board(inp)) + self.assertEqual(board(inp), out) def test_board8(self): inp = ["+---+", @@ -116,7 +116,7 @@ def test_board8(self): "|*8*|", "|***|", "+---+"] - self.assertEqual(out, board(inp)) + self.assertEqual(board(inp), out) def test_board9(self): inp = ["+-----+", @@ -133,7 +133,7 @@ def test_board9(self): "|111 |", "|1*1 |", "+-----+"] - self.assertEqual(out, board(inp)) + self.assertEqual(board(inp), out) def test_different_len(self): inp = ["+-+", diff --git a/exercises/nucleotide-count/nucleotide_count_test.py b/exercises/nucleotide-count/nucleotide_count_test.py index 90e8f7813f..dd59e2be3e 100644 --- a/exercises/nucleotide-count/nucleotide_count_test.py +++ b/exercises/nucleotide-count/nucleotide_count_test.py @@ -11,21 +11,21 @@ class DNATest(unittest.TestCase): def test_empty_dna_string_has_no_adenosine(self): - self.assertEqual(0, count('', 'A')) + self.assertEqual(count('', 'A'), 0) def test_empty_dna_string_has_no_nucleotides(self): expected = {'A': 0, 'T': 0, 'C': 0, 'G': 0} - self.assertEqual(expected, nucleotide_counts("")) + self.assertEqual(nucleotide_counts(""), expected) def test_repetitive_cytidine_gets_counted(self): - self.assertEqual(5, count('CCCCC', 'C')) + self.assertEqual(count('CCCCC', 'C'), 5) def test_repetitive_sequence_has_only_guanosine(self): expected = {'A': 0, 'T': 0, 'C': 0, 'G': 8} - self.assertEqual(expected, nucleotide_counts('GGGGGGGG')) + self.assertEqual(nucleotide_counts('GGGGGGGG'), expected) def test_counts_only_thymidine(self): - self.assertEqual(1, count('GGGGGTAACCCGG', 'T')) + self.assertEqual(count('GGGGGTAACCCGG', 'T'), 1) def test_validates_nucleotides(self): with self.assertRaises(ValueError): @@ -35,7 +35,7 @@ def test_counts_all_nucleotides(self): dna = ('AGCTTTTCATTCTGACTGCAACGGGCAATATGTCT' 'CTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC') expected = {'A': 20, 'T': 21, 'G': 17, 'C': 12} - self.assertEqual(expected, nucleotide_counts(dna)) + self.assertEqual(nucleotide_counts(dna), expected) if __name__ == '__main__': diff --git a/exercises/ocr-numbers/ocr_numbers_test.py b/exercises/ocr-numbers/ocr_numbers_test.py index bca52b7199..1fae0d1019 100644 --- a/exercises/ocr-numbers/ocr_numbers_test.py +++ b/exercises/ocr-numbers/ocr_numbers_test.py @@ -12,36 +12,35 @@ class OcrTest(unittest.TestCase): - def test_0(self): - self.assertEqual('0', number([" _ ", - "| |", - "|_|", - " "])) + self.assertEqual(number([" _ ", + "| |", + "|_|", + " "]), '0') def test_1(self): - self.assertEqual('1', number([" ", - " |", - " |", - " "])) + self.assertEqual(number([" ", + " |", + " |", + " "]), '1') def test_garbage(self): - self.assertEqual('?', number([" _ ", - " _|", - " |", - " "])) + self.assertEqual(number([" _ ", + " _|", + " |", + " "]), '?') def test_last_line_nonblank(self): - self.assertEqual('?', number([" ", - " |", - " |", - "| |"])) + self.assertEqual(number([" ", + " |", + " |", + "| |"]), '?') def test_unknown_char(self): - self.assertEqual('?', number([" - ", - " _|", - " X|", - " "])) + self.assertEqual(number([" - ", + " _|", + " X|", + " "]), '?') def test_too_short_row(self): self.assertRaises(ValueError, number, [" ", @@ -55,49 +54,64 @@ def test_insufficient_rows(self): " X|"]) def test_grid0(self): - self.assertEqual([" _ ", - "| |", - "|_|", - " "], grid('0')) + self.assertEqual(grid('0'), [" _ ", + "| |", + "|_|", + " "]) def test_grid1(self): - self.assertEqual([" ", - " |", - " |", - " "], grid('1')) + self.assertEqual(grid('1'), [" ", + " |", + " |", + " "]) def test_0010110(self): - self.assertEqual('0010110', number([" _ _ _ _ ", - "| || | || | | || |", - "|_||_| ||_| | ||_|", - " "])) + self.assertEqual( + number([ + " _ _ _ _ ", + "| || | || | | || |", + "|_||_| ||_| | ||_|", + " " + ]), '0010110') def test_3186547290(self): digits = '3186547290' - self.assertEqual(digits, number([" _ _ _ _ _ _ _ _ ", - " _| ||_||_ |_ |_| | _||_|| |", - " _| ||_||_| _| | ||_ _||_|", - " "])) + self.assertEqual( + number([ + " _ _ _ _ _ _ _ _ ", + " _| ||_||_ |_ |_| | _||_|| |", + " _| ||_||_| _| | ||_ _||_|", + " " + ]), digits) def test_Lost(self): digits = '4815162342' - self.assertEqual(digits, number([" _ _ _ _ _ _ ", - "|_||_| ||_ ||_ _| _||_| _|", - " ||_| | _| ||_||_ _| ||_ ", - " "])) + self.assertEqual( + number([ + " _ _ _ _ _ _ ", + "|_||_| ||_ ||_ _| _||_| _|", + " ||_| | _| ||_||_ _| ||_ ", + " " + ]), digits) def test_garble_middle(self): - self.assertEqual('12?45', number([" _ _ _ ", - " | _| ||_||_ ", - " ||_ _| | _|", - " "])) + self.assertEqual( + number([ + " _ _ _ ", + " | _| ||_||_ ", + " ||_ _| | _|", + " " + ]), '12?45') def test_grid3186547290(self): digits = '3186547290' - self.assertEqual([" _ _ _ _ _ _ _ _ ", - " _| ||_||_ |_ |_| | _||_|| |", - " _| ||_||_| _| | ||_ _||_|", - " "], grid(digits)) + self.assertEqual( + grid(digits), [ + " _ _ _ _ _ _ _ _ ", + " _| ||_||_ |_ |_| | _||_|| |", + " _| ||_||_| _| | ||_ _||_|", + " " + ]) def test_invalid_grid(self): self.assertRaises(ValueError, grid, '123a') diff --git a/exercises/octal/octal_test.py b/exercises/octal/octal_test.py index d6abbbf14d..43cdf1037e 100644 --- a/exercises/octal/octal_test.py +++ b/exercises/octal/octal_test.py @@ -11,22 +11,22 @@ class OctalTest(unittest.TestCase): def test_octal_1_is_decimal_1(self): - self.assertEqual(1, parse_octal("1")) + self.assertEqual(parse_octal("1"), 1) def test_octal_10_is_decimal_8(self): - self.assertEqual(8, parse_octal("10")) + self.assertEqual(parse_octal("10"), 8) def test_octal_17_is_decimal_15(self): - self.assertEqual(15, parse_octal("17")) + self.assertEqual(parse_octal("17"), 15) def test_octal_130_is_decimal_88(self): - self.assertEqual(88, parse_octal("130")) + self.assertEqual(parse_octal("130"), 88) def test_octal_2047_is_decimal_1063(self): - self.assertEqual(1063, parse_octal("2047")) + self.assertEqual(parse_octal("2047"), 1063) def test_octal_1234567_is_decimal_342391(self): - self.assertEqual(342391, parse_octal("1234567")) + self.assertEqual(parse_octal("1234567"), 342391) def test_8_is_seen_as_invalid(self): self.assertRaises(ValueError, parse_octal, "8") @@ -38,7 +38,7 @@ def test_6789_is_seen_as_invalid(self): self.assertRaises(ValueError, parse_octal, "6789") def test_valid_octal_formatted_string_011_is_decimal_9(self): - self.assertEqual(9, parse_octal("011")) + self.assertEqual(parse_octal("011"), 9) if __name__ == '__main__': diff --git a/exercises/palindrome-products/palindrome_products_test.py b/exercises/palindrome-products/palindrome_products_test.py index 8b35442a88..dc71dab1de 100644 --- a/exercises/palindrome-products/palindrome_products_test.py +++ b/exercises/palindrome-products/palindrome_products_test.py @@ -19,28 +19,28 @@ class PalindromesTests(unittest.TestCase): def test_largest_palindrome_from_single_digit_factors(self): value, factors = largest_palindrome(max_factor=9) - self.assertEqual(9, value) + self.assertEqual(value, 9) self.assertIn(set(factors), [{1, 9}, {3, 3}]) def test_largest_palindrome_from_double_digit_factors(self): value, factors = largest_palindrome(max_factor=99, min_factor=10) - self.assertEqual(9009, value) - self.assertEqual({91, 99}, set(factors)) + self.assertEqual(value, 9009) + self.assertEqual(set(factors), {91, 99}) def test_smallest_palindrome_from_double_digit_factors(self): value, factors = smallest_palindrome(max_factor=99, min_factor=10) - self.assertEqual(121, value) - self.assertEqual({11}, set(factors)) + self.assertEqual(value, 121) + self.assertEqual(set(factors), {11}) def test_largest_palindrome_from_triple_digit_factors(self): value, factors = largest_palindrome(max_factor=999, min_factor=100) - self.assertEqual(906609, value) - self.assertEqual({913, 993}, set(factors)) + self.assertEqual(value, 906609) + self.assertEqual(set(factors), {913, 993}) def test_smallest_palindrome_from_triple_digit_factors(self): value, factors = smallest_palindrome(max_factor=999, min_factor=100) - self.assertEqual(10201, value) - self.assertEqual({101, 101}, set(factors)) + self.assertEqual(value, 10201) + self.assertEqual(set(factors), {101, 101}) if __name__ == '__main__': diff --git a/exercises/pascals-triangle/pascals_triangle_test.py b/exercises/pascals-triangle/pascals_triangle_test.py index a1882a02bc..c9107790a7 100644 --- a/exercises/pascals-triangle/pascals_triangle_test.py +++ b/exercises/pascals-triangle/pascals_triangle_test.py @@ -6,32 +6,32 @@ class PascalsTriangleTest(unittest.TestCase): def test_triangle1(self): ans = ['1', '1 1', '1 2 1', '1 3 3 1', '1 4 6 4 1'] - self.assertEqual(ans, triangle(4)) + self.assertEqual(triangle(4), ans) def test_triangle2(self): ans = ['1', '1 1', '1 2 1', '1 3 3 1', '1 4 6 4 1', '1 5 10 10 5 1', '1 6 15 20 15 6 1'] - self.assertEqual(ans, triangle(6)) + self.assertEqual(triangle(6), ans) def test_is_triangle_true(self): inp = ['1', '1 1', '1 2 1', '1 3 3 1', '1 4 6 4 1', '1 5 10 10 5 1'] - self.assertEqual(True, is_triangle(inp)) + self.assertTrue(is_triangle(inp)) def test_is_triangle_false(self): inp = ['1', '1 1', '1 2 1', '1 4 4 1'] - self.assertEqual(False, is_triangle(inp)) + self.assertFalse(is_triangle(inp)) def test_row1(self): ans = '1' - self.assertEqual(ans, row(0)) + self.assertEqual(row(0), ans) def test_row2(self): ans = '1 2 1' - self.assertEqual(ans, row(2)) + self.assertEqual(row(2), ans) def test_row3(self): ans = '1 7 21 35 35 21 7 1' - self.assertEqual(ans, row(7)) + self.assertEqual(row(7), ans) if __name__ == '__main__': diff --git a/exercises/phone-number/phone_number_test.py b/exercises/phone-number/phone_number_test.py index fd037b0e57..338aa6d3d5 100644 --- a/exercises/phone-number/phone_number_test.py +++ b/exercises/phone-number/phone_number_test.py @@ -6,35 +6,35 @@ class PhoneTest(unittest.TestCase): def test_cleans_number(self): number = Phone("(123) 456-7890").number - self.assertEqual("1234567890", number) + self.assertEqual(number, "1234567890") def test_cleans_number_with_dots(self): number = Phone("123.456.7890").number - self.assertEqual("1234567890", number) + self.assertEqual(number, "1234567890") def test_valid_when_11_digits_and_first_is_1(self): number = Phone("11234567890").number - self.assertEqual("1234567890", number) + self.assertEqual(number, "1234567890") def test_invalid_when_11_digits(self): number = Phone("21234567890").number - self.assertEqual("0000000000", number) + self.assertEqual(number, "0000000000") def test_invalid_when_9_digits(self): number = Phone("123456789").number - self.assertEqual("0000000000", number) + self.assertEqual(number, "0000000000") def test_area_code(self): number = Phone("1234567890") - self.assertEqual("123", number.area_code()) + self.assertEqual(number.area_code(), "123") def test_pretty_print(self): number = Phone("1234567890") - self.assertEqual("(123) 456-7890", number.pretty()) + self.assertEqual(number.pretty(), "(123) 456-7890") def test_pretty_print_with_full_us_phone_number(self): number = Phone("11234567890") - self.assertEqual("(123) 456-7890", number.pretty()) + self.assertEqual(number.pretty(), "(123) 456-7890") if __name__ == '__main__': diff --git a/exercises/pig-latin/pig_latin_test.py b/exercises/pig-latin/pig_latin_test.py index aba99cca4e..71e965c6d3 100644 --- a/exercises/pig-latin/pig_latin_test.py +++ b/exercises/pig-latin/pig_latin_test.py @@ -5,49 +5,49 @@ class PigLatinTests(unittest.TestCase): def test_word_beginning_with_a(self): - self.assertEqual("appleay", translate("apple")) + self.assertEqual(translate("apple"), "appleay") def test_word_beginning_with_e(self): - self.assertEqual("earay", translate("ear")) + self.assertEqual(translate("ear"), "earay") def test_word_beginning_with_p(self): - self.assertEqual("igpay", translate("pig")) + self.assertEqual(translate("pig"), "igpay") def test_word_beginning_with_k(self): - self.assertEqual("oalakay", translate("koala")) + self.assertEqual(translate("koala"), "oalakay") def test_word_beginning_with_ch(self): - self.assertEqual("airchay", translate("chair")) + self.assertEqual(translate("chair"), "airchay") def test_word_beginning_with_qu(self): - self.assertEqual("eenquay", translate("queen")) + self.assertEqual(translate("queen"), "eenquay") def test_word_beginning_with_squ(self): - self.assertEqual("aresquay", translate("square")) + self.assertEqual(translate("square"), "aresquay") def test_word_beginning_with_th(self): - self.assertEqual("erapythay", translate("therapy")) + self.assertEqual(translate("therapy"), "erapythay") def test_word_beginning_with_thr(self): - self.assertEqual("ushthray", translate("thrush")) + self.assertEqual(translate("thrush"), "ushthray") def test_word_beginning_with_sch(self): - self.assertEqual("oolschay", translate("school")) + self.assertEqual(translate("school"), "oolschay") def test_translates_phrase(self): - self.assertEqual("ickquay astfay unray", translate("quick fast run")) + self.assertEqual(translate("quick fast run"), "ickquay astfay unray") def test_word_beginning_with_ye(self): - self.assertEqual("ellowyay", translate("yellow")) + self.assertEqual(translate("yellow"), "ellowyay") def test_word_beginning_with_yt(self): - self.assertEqual("yttriaay", translate("yttria")) + self.assertEqual(translate("yttria"), "yttriaay") def test_word_beginning_with_xe(self): - self.assertEqual("enonxay", translate("xenon")) + self.assertEqual(translate("xenon"), "enonxay") def test_word_beginning_with_xr(self): - self.assertEqual("xrayay", translate("xray")) + self.assertEqual(translate("xray"), "xrayay") if __name__ == '__main__': diff --git a/exercises/point-mutations/point_mutations_test.py b/exercises/point-mutations/point_mutations_test.py index be0032b289..bacb2bb2a9 100644 --- a/exercises/point-mutations/point_mutations_test.py +++ b/exercises/point-mutations/point_mutations_test.py @@ -5,31 +5,31 @@ class DNATest(unittest.TestCase): def test_no_difference_between_empty_strands(self): - self.assertEqual(0, hamming_distance('', '')) + self.assertEqual(hamming_distance('', ''), 0) def test_no_difference_between_identical_strands(self): - self.assertEqual(0, hamming_distance('GGACTGA', 'GGACTGA')) + self.assertEqual(hamming_distance('GGACTGA', 'GGACTGA'), 0) def test_complete_hamming_distance_in_small_strand(self): - self.assertEqual(3, hamming_distance('ACT', 'GGA')) + self.assertEqual(hamming_distance('ACT', 'GGA'), 3) def test_hamming_distance_in_off_by_one_strand(self): - self.assertEqual(19, - hamming_distance('GGACGGATTCTGACCTGGACTAATTTTGGGG', - 'AGGACGGATTCTGACCTGGACTAATTTTGGGG')) + self.assertEqual( + hamming_distance('GGACGGATTCTGACCTGGACTAATTTTGGGG', + 'AGGACGGATTCTGACCTGGACTAATTTTGGGG'), 19) def test_small_hamming_distance_in_middle_somewhere(self): - self.assertEqual(1, hamming_distance('GGACG', 'GGTCG')) + self.assertEqual(hamming_distance('GGACG', 'GGTCG'), 1) def test_larger_distance(self): - self.assertEqual(2, hamming_distance('ACCAGGG', 'ACTATGG')) + self.assertEqual(hamming_distance('ACCAGGG', 'ACTATGG'), 2) def test_ignores_extra_length_on_other_strand_when_longer(self): - self.assertEqual(3, hamming_distance('AAACTAGGGG', 'AGGCTAGCGGTAGGAC')) + self.assertEqual(hamming_distance('AAACTAGGGG', 'AGGCTAGCGGTAGGAC'), 3) def test_ignores_extra_length_on_original_strand_when_longer(self): - self.assertEqual(5, hamming_distance('GACTACGGACAGGGTAGGGAAT', - 'GACATCGCACACC')) + self.assertEqual( + hamming_distance('GACTACGGACAGGGTAGGGAAT', 'GACATCGCACACC'), 5) if __name__ == '__main__': diff --git a/exercises/poker/poker_test.py b/exercises/poker/poker_test.py index 9d9c396fad..5b0ca81839 100644 --- a/exercises/poker/poker_test.py +++ b/exercises/poker/poker_test.py @@ -6,112 +6,114 @@ class PokerTest(unittest.TestCase): def test_one_hand(self): hand = '4S 5S 7H 8D JC'.split() - self.assertEqual([hand], poker([hand])) + self.assertEqual(poker([hand]), [hand]) def test_nothing_vs_one_pair(self): nothing = '4S 5H 6S 8D JH'.split() pairOf4 = '2S 4H 6S 4D JH'.split() - self.assertEqual([pairOf4], poker([nothing, pairOf4])) + self.assertEqual(poker([nothing, pairOf4]), [pairOf4]) def test_two_pair(self): pairOf2 = '4S 2H 6S 2D JH'.split() pairOf4 = '2S 4H 6S 4D JH'.split() - self.assertEqual([pairOf4], poker([pairOf2, pairOf4])) + self.assertEqual(poker([pairOf2, pairOf4]), [pairOf4]) def test_one_pair_vs_double_pair(self): pairOf8 = '2S 8H 6S 8D JH'.split() doublePair = '4S 5H 4S 8D 5H'.split() - self.assertEqual([doublePair], poker([pairOf8, doublePair])) + self.assertEqual(poker([pairOf8, doublePair]), [doublePair]) def test_two_double_pair(self): doublePair2and8 = '2S 8H 2S 8D JH'.split() doublePair4and5 = '4S 5H 4S 8D 5H'.split() - self.assertEqual([doublePair2and8], - poker([doublePair2and8, doublePair4and5])) + self.assertEqual( + poker([doublePair2and8, doublePair4and5]), [doublePair2and8]) def test_two_double_pair_lower(self): doublePair2and8 = '2S 8H 2S 8C JH'.split() doublePair3and8 = '4S 3H 8S 8D 3H'.split() - self.assertEqual([doublePair3and8], - poker([doublePair2and8, doublePair3and8])) + self.assertEqual( + poker([doublePair2and8, doublePair3and8]), [doublePair3and8]) def test_two_double_pair_and_high(self): doublePair2and8 = '2S 8H 2C 8C 3H'.split() doublePair2and8high = '2D 2H 8S 8D AH'.split() - self.assertEqual([doublePair2and8high], - poker([doublePair2and8high, doublePair2and8])) + self.assertEqual( + poker([doublePair2and8high, doublePair2and8]), + [doublePair2and8high]) def test_double_pair_vs_three(self): doublePair2and8 = '2S 8H 2S 8D JH'.split() threeOf4 = '4S 5H 4S 8D 4H'.split() - self.assertEqual([threeOf4], poker([doublePair2and8, threeOf4])) + self.assertEqual(poker([doublePair2and8, threeOf4]), [threeOf4]) def test_two_three(self): threeOf2 = '2S 2H 2S 8D JH'.split() threeOf1 = '4S AH AS 8D AH'.split() - self.assertEqual([threeOf1], poker([threeOf2, threeOf1])) + self.assertEqual(poker([threeOf2, threeOf1]), [threeOf1]) def test_three_vs_straight(self): threeOf4 = '4S 5H 4S 8D 4H'.split() straight = '3S 4H 2S 6D 5H'.split() - self.assertEqual([straight], poker([threeOf4, straight])) + self.assertEqual(poker([threeOf4, straight]), [straight]) def test_two_straights(self): straightTo8 = '4S 6H 7S 8D 5H'.split() straightTo9 = '5S 7H 8S 9D 6H'.split() - self.assertEqual([straightTo9], poker([straightTo8, straightTo9])) + self.assertEqual(poker([straightTo8, straightTo9]), [straightTo9]) straightTo1 = 'AS QH KS TD JH'.split() straightTo5 = '4S AH 3S 2D 5H'.split() - self.assertEqual([straightTo1], poker([straightTo1, straightTo5])) + self.assertEqual(poker([straightTo1, straightTo5]), [straightTo1]) def test_straight_vs_flush(self): straightTo8 = '4S 6H 7S 8D 5H'.split() flushTo7 = '2S 4S 5S 6S 7S'.split() - self.assertEqual([flushTo7], poker([straightTo8, flushTo7])) + self.assertEqual(poker([straightTo8, flushTo7]), [flushTo7]) def test_two_flushes(self): flushTo8 = '3H 6H 7H 8H 5H'.split() flushTo7 = '2S 4S 5S 6S 7S'.split() - self.assertEqual([flushTo8], poker([flushTo8, flushTo7])) + self.assertEqual(poker([flushTo8, flushTo7]), [flushTo8]) def test_flush_vs_full(self): flushTo8 = '3H 6H 7H 8H 5H'.split() full = '4S 5H 4S 5D 4H'.split() - self.assertEqual([full], poker([full, flushTo8])) + self.assertEqual(poker([full, flushTo8]), [full]) def test_two_fulls(self): fullOf4by9 = '4H 4S 4D 9S 9D'.split() fullOf5by8 = '5H 5S 5D 8S 8D'.split() - self.assertEqual([fullOf5by8], poker([fullOf4by9, fullOf5by8])) + self.assertEqual(poker([fullOf4by9, fullOf5by8]), [fullOf5by8]) def test_full_vs_square(self): full = '4S 5H 4S 5D 4H'.split() squareOf3 = '3S 3H 2S 3D 3H'.split() - self.assertEqual([squareOf3], poker([full, squareOf3])) + self.assertEqual(poker([full, squareOf3]), [squareOf3]) def test_two_square(self): squareOf2 = '2S 2H 2S 8D 2H'.split() squareOf5 = '4S 5H 5S 5D 5H'.split() - self.assertEqual([squareOf5], poker([squareOf2, squareOf5])) + self.assertEqual(poker([squareOf2, squareOf5]), [squareOf5]) def test_square_vs_straight_flush(self): squareOf5 = '4S 5H 5S 5D 5H'.split() straightFlushTo9 = '5S 7S 8S 9S 6S'.split() - self.assertEqual([straightFlushTo9], - poker([squareOf5, straightFlushTo9])) + self.assertEqual( + poker([squareOf5, straightFlushTo9]), [straightFlushTo9]) def test_two_straight_flushes(self): straightFlushTo8 = '4H 6H 7H 8H 5H'.split() straightFlushTo9 = '5S 7S 8S 9S 6S'.split() - self.assertEqual([straightFlushTo9], - poker([straightFlushTo8, straightFlushTo9])) + self.assertEqual( + poker([straightFlushTo8, straightFlushTo9]), [straightFlushTo9]) def test_three_hand_with_tie(self): - spadeStraightTo9 = "9S 8S 7S 6S 5S".split() - diamondStraightTo9 = "9D 8D 7D 6D 5D".split() - threeOf4 = "4D 4S 4H QS KS".split() - self.assertEqual([spadeStraightTo9, diamondStraightTo9], - poker([spadeStraightTo9, diamondStraightTo9, threeOf4])) + spadeStraightTo9 = '9S 8S 7S 6S 5S'.split() + diamondStraightTo9 = '9D 8D 7D 6D 5D'.split() + threeOf4 = '4D 4S 4H QS KS'.split() + self.assertEqual( + poker([spadeStraightTo9, diamondStraightTo9, threeOf4]), + [spadeStraightTo9, diamondStraightTo9]) if __name__ == '__main__': diff --git a/exercises/prime-factors/prime_factors_test.py b/exercises/prime-factors/prime_factors_test.py index 02524dce84..694ea09027 100644 --- a/exercises/prime-factors/prime_factors_test.py +++ b/exercises/prime-factors/prime_factors_test.py @@ -5,37 +5,37 @@ class PrimeFactorsTest(unittest.TestCase): def test_1(self): - self.assertEqual([], prime_factors(1)) + self.assertEqual(prime_factors(1), []) def test_2(self): - self.assertEqual([2], prime_factors(2)) + self.assertEqual(prime_factors(2), [2]) def test_3(self): - self.assertEqual([3], prime_factors(3)) + self.assertEqual(prime_factors(3), [3]) def test_4(self): - self.assertEqual([2, 2], prime_factors(4)) + self.assertEqual(prime_factors(4), [2, 2]) def test_6(self): - self.assertEqual([2, 3], prime_factors(6)) + self.assertEqual(prime_factors(6), [2, 3]) def test_8(self): - self.assertEqual([2, 2, 2], prime_factors(8)) + self.assertEqual(prime_factors(8), [2, 2, 2]) def test_9(self): - self.assertEqual([3, 3], prime_factors(9)) + self.assertEqual(prime_factors(9), [3, 3]) def test_27(self): - self.assertEqual([3, 3, 3], prime_factors(27)) + self.assertEqual(prime_factors(27), [3, 3, 3]) def test_625(self): - self.assertEqual([5, 5, 5, 5], prime_factors(625)) + self.assertEqual(prime_factors(625), [5, 5, 5, 5]) def test_901255(self): - self.assertEqual([5, 17, 23, 461], prime_factors(901255)) + self.assertEqual(prime_factors(901255), [5, 17, 23, 461]) def test_93819012551(self): - self.assertEqual([11, 9539, 894119], prime_factors(93819012551)) + self.assertEqual(prime_factors(93819012551), [11, 9539, 894119]) if __name__ == '__main__': diff --git a/exercises/proverb/proverb_test.py b/exercises/proverb/proverb_test.py index bd29c3998d..d4bdc3b77b 100644 --- a/exercises/proverb/proverb_test.py +++ b/exercises/proverb/proverb_test.py @@ -7,25 +7,25 @@ class ProverbTest(unittest.TestCase): def test_a_single_consequence(self): expected = 'For want of a nail the shoe was lost.\n'\ 'And all for the want of a nail.' - self.assertEqual(expected, proverb(['nail', 'shoe'])) + self.assertEqual(proverb(['nail', 'shoe']), expected) def test_short_list(self): expected = 'For want of a nail the shoe was lost.\n'\ 'For want of a shoe the horse was lost.\n'\ 'And all for the want of a nail.' - self.assertEqual(expected, proverb(['nail', 'shoe', 'horse'])) + self.assertEqual(proverb(['nail', 'shoe', 'horse']), expected) def test_long_list(self): expected = 'For want of a nail the shoe was lost.\n'\ 'For want of a shoe the horse was lost.\n'\ 'For want of a horse the rider was lost.\n'\ 'And all for the want of a nail.' - self.assertEqual(expected, proverb(['nail', 'shoe', 'horse', 'rider'])) + self.assertEqual(proverb(['nail', 'shoe', 'horse', 'rider']), expected) def test_new_itens(self): expected = 'For want of a key the value was lost.\n'\ 'And all for the want of a key.' - self.assertEqual(expected, proverb(['key', 'value'])) + self.assertEqual(proverb(['key', 'value']), expected) def test_whole_proverb(self): expected = 'For want of a nail the shoe was lost.\n'\ @@ -35,8 +35,11 @@ def test_whole_proverb(self): 'For want of a message the battle was lost.\n'\ 'For want of a battle the kingdom was lost.\n'\ 'And all for the want of a nail.' - self.assertEqual(expected, proverb(['nail', 'shoe', 'horse', 'rider', - 'message', 'battle', 'kingdom'])) + self.assertEqual( + proverb([ + 'nail', 'shoe', 'horse', 'rider', 'message', 'battle', + 'kingdom' + ]), expected) def test_qualifier(self): expected = 'For want of a nail the shoe was lost.\n'\ @@ -46,9 +49,13 @@ def test_qualifier(self): 'For want of a message the battle was lost.\n'\ 'For want of a battle the kingdom was lost.\n'\ 'And all for the want of a horseshoe nail.' - self.assertEqual(expected, proverb(['nail', 'shoe', 'horse', 'rider', - 'message', 'battle', 'kingdom'], - qualifier='horseshoe')) + self.assertEqual( + proverb( + [ + 'nail', 'shoe', 'horse', 'rider', 'message', 'battle', + 'kingdom' + ], + qualifier='horseshoe'), expected) if __name__ == '__main__': diff --git a/exercises/pythagorean-triplet/pythagorean_triplet_test.py b/exercises/pythagorean-triplet/pythagorean_triplet_test.py index d0d6bfbdcc..246bf0df63 100644 --- a/exercises/pythagorean-triplet/pythagorean_triplet_test.py +++ b/exercises/pythagorean-triplet/pythagorean_triplet_test.py @@ -35,47 +35,49 @@ import unittest -from pythagorean_triplet import (primitive_triplets, triplets_in_range, - is_triplet) +from pythagorean_triplet import ( + primitive_triplets, + triplets_in_range, + is_triplet +) class PythagoreanTripletTest(unittest.TestCase): - def test_triplet1(self): ans = set([(3, 4, 5)]) - self.assertEqual(ans, primitive_triplets(4)) + self.assertEqual(primitive_triplets(4), ans) def test_triplet2(self): ans = set([(13, 84, 85), (84, 187, 205), (84, 437, 445), (84, 1763, 1765)]) - self.assertEqual(ans, primitive_triplets(84)) + self.assertEqual(primitive_triplets(84), ans) def test_triplet3(self): ans = set([(29, 420, 421), (341, 420, 541), (420, 851, 949), (420, 1189, 1261), (420, 1739, 1789), (420, 4891, 4909), (420, 11021, 11029), (420, 44099, 44101)]) - self.assertEqual(ans, primitive_triplets(420)) + self.assertEqual(primitive_triplets(420), ans) def test_triplet4(self): ans = set([(175, 288, 337), (288, 20735, 20737)]) - self.assertEqual(ans, primitive_triplets(288)) + self.assertEqual(primitive_triplets(288), ans) def test_range1(self): ans = set([(3, 4, 5), (6, 8, 10)]) - self.assertEqual(ans, triplets_in_range(1, 10)) + self.assertEqual(triplets_in_range(1, 10), ans) def test_range2(self): ans = set([(57, 76, 95), (60, 63, 87)]) - self.assertEqual(ans, triplets_in_range(56, 95)) + self.assertEqual(triplets_in_range(56, 95), ans) def test_is_triplet1(self): - self.assertEqual(True, is_triplet((29, 20, 21))) + self.assertTrue(is_triplet((29, 20, 21))) def test_is_triplet2(self): - self.assertEqual(False, is_triplet((25, 25, 1225))) + self.assertFalse(is_triplet((25, 25, 1225))) def test_is_triplet3(self): - self.assertEqual(True, is_triplet((924, 43, 925))) + self.assertTrue(is_triplet((924, 43, 925))) def test_odd_number(self): self.assertRaises(ValueError, primitive_triplets, 5) diff --git a/exercises/queen-attack/queen_attack_test.py b/exercises/queen-attack/queen_attack_test.py index 84e7f43b68..7b7ec50033 100644 --- a/exercises/queen-attack/queen_attack_test.py +++ b/exercises/queen-attack/queen_attack_test.py @@ -13,7 +13,7 @@ def test_board1(self): '______B_', '________', '________'] - self.assertEqual(ans, board((2, 3), (5, 6))) + self.assertEqual(board((2, 3), (5, 6)), ans) def test_board2(self): ans = ['______W_', @@ -24,31 +24,31 @@ def test_board2(self): '________', '________', '________'] - self.assertEqual(ans, board((0, 6), (1, 7))) + self.assertEqual(board((0, 6), (1, 7)), ans) def test_attack_true1(self): - self.assertEqual(True, can_attack((2, 3), (5, 6))) + self.assertTrue(can_attack((2, 3), (5, 6))) def test_attack_true2(self): - self.assertEqual(True, can_attack((2, 6), (5, 3))) + self.assertTrue(can_attack((2, 6), (5, 3))) def test_attack_true3(self): - self.assertEqual(True, can_attack((2, 4), (2, 7))) + self.assertTrue(can_attack((2, 4), (2, 7))) def test_attack_true4(self): - self.assertEqual(True, can_attack((5, 4), (2, 4))) + self.assertTrue(can_attack((5, 4), (2, 4))) def test_attack_true5(self): - self.assertEqual(True, can_attack((1, 1), (6, 6))) + self.assertTrue(can_attack((1, 1), (6, 6))) def test_attack_true6(self): - self.assertEqual(True, can_attack((0, 6), (1, 7))) + self.assertTrue(can_attack((0, 6), (1, 7))) def test_attack_false1(self): - self.assertEqual(False, can_attack((4, 2), (0, 5))) + self.assertFalse(can_attack((4, 2), (0, 5))) def test_attack_false2(self): - self.assertEqual(False, can_attack((2, 3), (4, 7))) + self.assertFalse(can_attack((2, 3), (4, 7))) # If either board or can_attack are called with an invalid board position # they should raise a ValueError with a meaningful error message. diff --git a/exercises/rail-fence-cipher/rail_fence_cipher_test.py b/exercises/rail-fence-cipher/rail_fence_cipher_test.py index 55fc41cc88..f3eb8b96d6 100644 --- a/exercises/rail-fence-cipher/rail_fence_cipher_test.py +++ b/exercises/rail-fence-cipher/rail_fence_cipher_test.py @@ -4,31 +4,32 @@ class RailFenceTests(unittest.TestCase): - def test_encode_with_two_rails(self): - self.assertMultiLineEqual('XXXXXXXXXOOOOOOOOO', - encode('XOXOXOXOXOXOXOXOXO', 2)) + self.assertMultiLineEqual( + encode('XOXOXOXOXOXOXOXOXO', 2), 'XXXXXXXXXOOOOOOOOO') def test_encode_with_three_rails(self): - self.assertMultiLineEqual('WECRLTEERDSOEEFEAOCAIVDEN', - encode('WEAREDISCOVEREDFLEEATONCE', 3)) + self.assertMultiLineEqual( + encode('WEAREDISCOVEREDFLEEATONCE', 3), + 'WECRLTEERDSOEEFEAOCAIVDEN') def test_encode_with_middle_stop(self): - self.assertMultiLineEqual('ESXIEECSR', encode('EXERCISES', 4)) + self.assertMultiLineEqual(encode('EXERCISES', 4), 'ESXIEECSR') def test_decode_with_three_rails(self): - self.assertMultiLineEqual('THEDEVILISINTHEDETAILS', - decode('TEITELHDVLSNHDTISEIIEA', 3)) + self.assertMultiLineEqual( + decode('TEITELHDVLSNHDTISEIIEA', 3), 'THEDEVILISINTHEDETAILS') def test_decode_with_five_rails(self): - self.assertMultiLineEqual('EXERCISMISAWESOME', - decode('EIEXMSMESAORIWSCE', 5)) + self.assertMultiLineEqual( + decode('EIEXMSMESAORIWSCE', 5), 'EXERCISMISAWESOME') def test_decode_with_six_rails(self): self.assertMultiLineEqual( - '112358132134558914423337761098715972584418167651094617711286', - decode('133714114238148966225439541018335470986172518171757571896261', 6) - ) + decode( + '133714114238148966225439541018335470986172518171757571896261', + 6), + '112358132134558914423337761098715972584418167651094617711286') if __name__ == '__main__': diff --git a/exercises/raindrops/raindrops_test.py b/exercises/raindrops/raindrops_test.py index b592538e10..58f8afc72c 100644 --- a/exercises/raindrops/raindrops_test.py +++ b/exercises/raindrops/raindrops_test.py @@ -5,52 +5,52 @@ class RaindropsTest(unittest.TestCase): def test_1(self): - self.assertEqual("1", raindrops(1)) + self.assertEqual(raindrops(1), "1") def test_3(self): - self.assertEqual("Pling", raindrops(3)) + self.assertEqual(raindrops(3), "Pling") def test_5(self): - self.assertEqual("Plang", raindrops(5)) + self.assertEqual(raindrops(5), "Plang") def test_7(self): - self.assertEqual("Plong", raindrops(7)) + self.assertEqual(raindrops(7), "Plong") def test_6(self): - self.assertEqual("Pling", raindrops(6)) + self.assertEqual(raindrops(6), "Pling") def test_9(self): - self.assertEqual("Pling", raindrops(9)) + self.assertEqual(raindrops(9), "Pling") def test_10(self): - self.assertEqual("Plang", raindrops(10)) + self.assertEqual(raindrops(10), "Plang") def test_14(self): - self.assertEqual("Plong", raindrops(14)) + self.assertEqual(raindrops(14), "Plong") def test_15(self): - self.assertEqual("PlingPlang", raindrops(15)) + self.assertEqual(raindrops(15), "PlingPlang") def test_21(self): - self.assertEqual("PlingPlong", raindrops(21)) + self.assertEqual(raindrops(21), "PlingPlong") def test_25(self): - self.assertEqual("Plang", raindrops(25)) + self.assertEqual(raindrops(25), "Plang") def test_35(self): - self.assertEqual("PlangPlong", raindrops(35)) + self.assertEqual(raindrops(35), "PlangPlong") def test_49(self): - self.assertEqual("Plong", raindrops(49)) + self.assertEqual(raindrops(49), "Plong") def test_52(self): - self.assertEqual("52", raindrops(52)) + self.assertEqual(raindrops(52), "52") def test_105(self): - self.assertEqual("PlingPlangPlong", raindrops(105)) + self.assertEqual(raindrops(105), "PlingPlangPlong") def test_12121(self): - self.assertEqual("12121", raindrops(12121)) + self.assertEqual(raindrops(12121), "12121") if __name__ == '__main__': diff --git a/exercises/rectangles/rectangles_test.py b/exercises/rectangles/rectangles_test.py index 2034a487c6..1a1439b913 100644 --- a/exercises/rectangles/rectangles_test.py +++ b/exercises/rectangles/rectangles_test.py @@ -5,21 +5,21 @@ class WordTest(unittest.TestCase): def test_zero_area_1(self): - self.assertEqual(0, count()) + self.assertEqual(count(), 0) def test_zero_area_2(self): lines = "" - self.assertEqual(0, count(lines)) + self.assertEqual(count(lines), 0) def test_empty_area(self): lines = " " - self.assertEqual(0, count(lines)) + self.assertEqual(count(lines), 0) def test_one_rectangle(self): lines = ["+-+", "| |", "+-+"] - self.assertEqual(1, count(lines)) + self.assertEqual(count(lines), 1) def test_two_rectangles_no_shared_parts(self): lines = [" +-+", @@ -27,7 +27,7 @@ def test_two_rectangles_no_shared_parts(self): "+-+-+", "| | ", "+-+ "] - self.assertEqual(2, count(lines)) + self.assertEqual(count(lines), 2) def test_five_rectangles_three_regions(self): lines = [" +-+", @@ -35,7 +35,7 @@ def test_five_rectangles_three_regions(self): "+-+-+", "| | |", "+-+-+"] - self.assertEqual(5, count(lines)) + self.assertEqual(count(lines), 5) def test_incomplete_rectangles(self): lines = [" +-+", @@ -43,7 +43,7 @@ def test_incomplete_rectangles(self): "+-+-+", "| | -", "+-+-+"] - self.assertEqual(1, count(lines)) + self.assertEqual(count(lines), 1) def test_complicated(self): lines = ["+------+----+", @@ -51,7 +51,7 @@ def test_complicated(self): "+---+--+ |", "| | |", "+---+-------+"] - self.assertEqual(3, count(lines)) + self.assertEqual(count(lines), 3) def test_not_so_complicated(self): lines = ["+------+----+", @@ -59,7 +59,7 @@ def test_not_so_complicated(self): "+------+ |", "| | |", "+---+-------+"] - self.assertEqual(2, count(lines)) + self.assertEqual(count(lines), 2) if __name__ == '__main__': diff --git a/exercises/rna-transcription/rna_transcription_test.py b/exercises/rna-transcription/rna_transcription_test.py index 521e474b90..d0788494ae 100644 --- a/exercises/rna-transcription/rna_transcription_test.py +++ b/exercises/rna-transcription/rna_transcription_test.py @@ -3,31 +3,32 @@ from rna_transcription import to_rna -class DNATests(unittest.TestCase): +# test cases adapted from `x-common//canonical-data.json` @ version: 1.0.0 +class DNATests(unittest.TestCase): def test_transcribes_guanine_to_cytosine(self): - self.assertEqual('C', to_rna('G')) + self.assertEqual(to_rna('G'), 'C') def test_transcribes_cytosine_to_guanine(self): - self.assertEqual('G', to_rna('C')) + self.assertEqual(to_rna('C'), 'G') def test_transcribes_thymine_to_adenine(self): - self.assertEqual('A', to_rna('T')) + self.assertEqual(to_rna('T'), 'A') def test_transcribes_adenine_to_uracil(self): - self.assertEqual('U', to_rna('A')) + self.assertEqual(to_rna('A'), 'U') def test_transcribes_all_occurences(self): - self.assertMultiLineEqual('UGCACCAGAAUU', to_rna('ACGTGGTCTTAA')) + self.assertMultiLineEqual(to_rna('ACGTGGTCTTAA'), 'UGCACCAGAAUU') def test_correctly_handles_single_invalid_input(self): - self.assertEqual('', to_rna('U')) + self.assertEqual(to_rna('U'), '') def test_correctly_handles_completely_invalid_input(self): - self.assertMultiLineEqual('', to_rna('XXX')) + self.assertMultiLineEqual(to_rna('XXX'), '') def test_correctly_handles_partially_invalid_input(self): - self.assertMultiLineEqual('', to_rna('ACGTXXXCTTAA')) + self.assertMultiLineEqual(to_rna('ACGTXXXCTTAA'), '') if __name__ == '__main__': diff --git a/exercises/robot-name/robot_name_test.py b/exercises/robot-name/robot_name_test.py index bc234d5044..9af46eaafe 100644 --- a/exercises/robot-name/robot_name_test.py +++ b/exercises/robot-name/robot_name_test.py @@ -1,7 +1,7 @@ import unittest +import random from robot_name import Robot -import random class RobotTest(unittest.TestCase): diff --git a/exercises/robot-simulator/robot_simulator_test.py b/exercises/robot-simulator/robot_simulator_test.py index 1e0bc96a0c..024a3ab503 100644 --- a/exercises/robot-simulator/robot_simulator_test.py +++ b/exercises/robot-simulator/robot_simulator_test.py @@ -4,16 +4,15 @@ class RobotTests(unittest.TestCase): - def test_init(self): robot = Robot() - self.assertEqual((0, 0), robot.coordinates) - self.assertEqual(NORTH, robot.bearing) + self.assertEqual(robot.coordinates, (0, 0)) + self.assertEqual(robot.bearing, NORTH) def test_setup(self): robot = Robot(SOUTH, -1, 1) - self.assertEqual((-1, 1), robot.coordinates) - self.assertEqual(SOUTH, robot.bearing) + self.assertEqual(robot.coordinates, (-1, 1)) + self.assertEqual(robot.bearing, SOUTH) def test_turn_right(self): robot = Robot() @@ -30,44 +29,44 @@ def test_turn_left(self): def test_advance_positive_north(self): robot = Robot(NORTH, 0, 0) robot.advance() - self.assertEqual((0, 1), robot.coordinates) - self.assertEqual(NORTH, robot.bearing) + self.assertEqual(robot.coordinates, (0, 1)) + self.assertEqual(robot.bearing, NORTH) def test_advance_positive_east(self): robot = Robot(EAST, 0, 0) robot.advance() - self.assertEqual((1, 0), robot.coordinates) - self.assertEqual(EAST, robot.bearing) + self.assertEqual(robot.coordinates, (1, 0)) + self.assertEqual(robot.bearing, EAST) def test_advance_negative_south(self): robot = Robot(SOUTH, 0, 0) robot.advance() - self.assertEqual((0, -1), robot.coordinates) - self.assertEqual(SOUTH, robot.bearing) + self.assertEqual(robot.coordinates, (0, -1)) + self.assertEqual(robot.bearing, SOUTH) def test_advance_positive_west(self): robot = Robot(WEST, 0, 0) robot.advance() - self.assertEqual((-1, 0), robot.coordinates) - self.assertEqual(WEST, robot.bearing) + self.assertEqual(robot.coordinates, (-1, 0)) + self.assertEqual(robot.bearing, WEST) def test_simulate_prog1(self): robot = Robot(NORTH, 0, 0) robot.simulate("LAAARALA") - self.assertEqual((-4, 1), robot.coordinates) - self.assertEqual(WEST, robot.bearing) + self.assertEqual(robot.coordinates, (-4, 1)) + self.assertEqual(robot.bearing, WEST) def test_simulate_prog2(self): robot = Robot(EAST, 2, -7) robot.simulate("RRAAAAALA") - self.assertEqual((-3, -8), robot.coordinates) - self.assertEqual(SOUTH, robot.bearing) + self.assertEqual(robot.coordinates, (-3, -8)) + self.assertEqual(robot.bearing, SOUTH) def test_simulate_prog3(self): robot = Robot(SOUTH, 8, 4) robot.simulate("LAAARRRALLLL") - self.assertEqual((11, 5), robot.coordinates) - self.assertEqual(NORTH, robot.bearing) + self.assertEqual(robot.coordinates, (11, 5)) + self.assertEqual(robot.bearing, NORTH) if __name__ == '__main__': diff --git a/exercises/roman-numerals/roman_numerals_test.py b/exercises/roman-numerals/roman_numerals_test.py index a1fa82e155..825e164bd7 100644 --- a/exercises/roman-numerals/roman_numerals_test.py +++ b/exercises/roman-numerals/roman_numerals_test.py @@ -27,7 +27,7 @@ class RomanTest(unittest.TestCase): def test_numerals(self): for arabic, numeral in self.numerals.items(): - self.assertEqual(numeral, roman_numerals.numeral(arabic)) + self.assertEqual(roman_numerals.numeral(arabic), numeral) if __name__ == '__main__': diff --git a/exercises/run-length-encoding/run_length_encoding_test.py b/exercises/run-length-encoding/run_length_encoding_test.py index 0a2263cc1f..24fb6b57f2 100644 --- a/exercises/run-length-encoding/run_length_encoding_test.py +++ b/exercises/run-length-encoding/run_length_encoding_test.py @@ -4,49 +4,48 @@ class WordCountTests(unittest.TestCase): - def test_encode_empty_string(self): - self.assertMultiLineEqual('', encode('')) + self.assertMultiLineEqual(encode(''), '') def test_encode_single_characters_only_are_encoded_without_count(self): - self.assertMultiLineEqual('XYZ', encode('XYZ')) + self.assertMultiLineEqual(encode('XYZ'), 'XYZ') def test_encode_string_with_no_single_characters(self): - self.assertMultiLineEqual('2A3B4C', encode('AABBBCCCC')) + self.assertMultiLineEqual(encode('AABBBCCCC'), '2A3B4C') def test_encode_single_characters_mixed_with_repeated_characters(self): self.assertMultiLineEqual( - '12WB12W3B24WB', - encode('WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB')) + encode('WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB'), + '12WB12W3B24WB') def test_encode_multiple_whitespace_mixed_in_string(self): - self.assertMultiLineEqual('2 hs2q q2w2 ', encode(' hsqq qww ')) + self.assertMultiLineEqual(encode(' hsqq qww '), '2 hs2q q2w2 ') def test_encode_lowercase_characters(self): - self.assertMultiLineEqual('2a3b4c', encode('aabbbcccc')) + self.assertMultiLineEqual(encode('aabbbcccc'), '2a3b4c') def test_decode_empty_string(self): - self.assertMultiLineEqual('', decode('')) + self.assertMultiLineEqual(decode(''), '') def test_decode_single_characters_only(self): - self.assertMultiLineEqual('XYZ', decode('XYZ')) + self.assertMultiLineEqual(decode('XYZ'), 'XYZ') def test_decode_string_with_no_single_characters(self): - self.assertMultiLineEqual('AABBBCCCC', decode('2A3B4C')) + self.assertMultiLineEqual(decode('2A3B4C'), 'AABBBCCCC') def test_decode_single_characters_with_repeated_characters(self): self.assertMultiLineEqual( - 'WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB', - decode('12WB12W3B24WB')) + decode('12WB12W3B24WB'), + 'WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB') def test_decode_multiple_whitespace_mixed_in_string(self): - self.assertMultiLineEqual(' hsqq qww ', decode('2 hs2q q2w2 ')) + self.assertMultiLineEqual(decode('2 hs2q q2w2 '), ' hsqq qww ') def test_decode_lower_case_string(self): - self.assertMultiLineEqual('aabbbcccc', decode('2a3b4c')) + self.assertMultiLineEqual(decode('2a3b4c'), 'aabbbcccc') def test_combination(self): - self.assertMultiLineEqual('zzz ZZ zZ', decode(encode('zzz ZZ zZ'))) + self.assertMultiLineEqual(decode(encode('zzz ZZ zZ')), 'zzz ZZ zZ') if __name__ == '__main__': diff --git a/exercises/saddle-points/saddle_points_test.py b/exercises/saddle-points/saddle_points_test.py index 21f1b305ba..2579b05474 100644 --- a/exercises/saddle-points/saddle_points_test.py +++ b/exercises/saddle-points/saddle_points_test.py @@ -13,18 +13,18 @@ class SaddlePointTest(unittest.TestCase): def test_one_saddle(self): inp = [[9, 8, 7], [5, 3, 2], [6, 6, 7]] - self.assertEqual(set([(1, 0)]), saddle_points(inp)) + self.assertEqual(saddle_points(inp), set([(1, 0)])) def test_no_saddle(self): - self.assertEqual(set(), saddle_points([[2, 1], [1, 2]])) + self.assertEqual(saddle_points([[2, 1], [1, 2]]), set()) def test_mult_saddle(self): inp = [[5, 3, 5, 4], [6, 4, 7, 3], [5, 1, 5, 3]] ans = set([(0, 0), (0, 2), (2, 0), (2, 2)]) - self.assertEqual(ans, saddle_points(inp)) + self.assertEqual(saddle_points(inp), ans) def test_empty_matrix(self): - self.assertEqual(set(), saddle_points([])) + self.assertEqual(saddle_points([]), set()) def test_irregular_matrix(self): inp = [[3, 2, 1], [0, 1], [2, 1, 0]] diff --git a/exercises/say/say_test.py b/exercises/say/say_test.py index 1fd3775608..4f46905e01 100644 --- a/exercises/say/say_test.py +++ b/exercises/say/say_test.py @@ -4,51 +4,49 @@ class SayTest(unittest.TestCase): - def test_one(self): - self.assertEqual("one", say(1)) + self.assertEqual(say(1), "one") def test_fourteen(self): - self.assertEqual("fourteen", say(14)) + self.assertEqual(say(14), "fourteen") def test_twenty(self): - self.assertEqual("twenty", say(20)) + self.assertEqual(say(20), "twenty") def test_twenty_two(self): - self.assertEqual("twenty-two", say(22)) + self.assertEqual(say(22), "twenty-two") def test_one_hundred(self): - self.assertEqual("one hundred", say(100)) + self.assertEqual(say(100), "one hundred") def test_one_hundred_twenty(self): - self.assertEqual("one hundred and twenty", say(120)) + self.assertEqual(say(120), "one hundred and twenty") def test_one_hundred_twenty_three(self): - self.assertEqual("one hundred and twenty-three", say(123)) + self.assertEqual(say(123), "one hundred and twenty-three") def test_one_thousand(self): - self.assertEqual("one thousand", say(1000)) + self.assertEqual(say(1000), "one thousand") def test_one_thousand_two_hundred_thirty_four(self): - self.assertEqual("one thousand two hundred and thirty-four", - say(1234)) + self.assertEqual(say(1234), "one thousand two hundred and thirty-four") def test_eight_hundred_and_ten_thousand(self): - self.assertEqual("eight hundred and ten thousand", say(810000)) + self.assertEqual(say(810000), "eight hundred and ten thousand") def test_one_million(self): - self.assertEqual("one million", say(1e6)) + self.assertEqual(say(1e6), "one million") def test_one_million_two(self): - self.assertEqual("one million and two", say(1000002)) + self.assertEqual(say(1000002), "one million and two") def test_1002345(self): self.assertEqual( - "one million two thousand three hundred and forty-five", - say(1002345)) + say(1002345), + "one million two thousand three hundred and forty-five") def test_one_billion(self): - self.assertEqual("one billion", say(1e9)) + self.assertEqual(say(1e9), "one billion") def test_number_to_large(self): with self.assertRaises(AttributeError): @@ -59,14 +57,14 @@ def test_number_negative(self): say(-42) def test_zero(self): - self.assertEqual("zero", say(0)) + self.assertEqual(say(0), "zero") def test_987654321123(self): - self.assertEqual("nine hundred and eighty-seven billion " + - "six hundred and fifty-four million " + - "three hundred and twenty-one thousand " + - "one hundred and twenty-three", - say(987654321123)) + self.assertEqual( + say(987654321123), ("nine hundred and eighty-seven billion " + "six hundred and fifty-four million " + "three hundred and twenty-one thousand " + "one hundred and twenty-three")) if __name__ == '__main__': diff --git a/exercises/scrabble-score/scrabble_score_test.py b/exercises/scrabble-score/scrabble_score_test.py index 13dbbad22c..7cb9c9b24d 100644 --- a/exercises/scrabble-score/scrabble_score_test.py +++ b/exercises/scrabble-score/scrabble_score_test.py @@ -5,25 +5,25 @@ class WordTest(unittest.TestCase): def test_invalid_word_scores_zero(self): - self.assertEqual(0, score('')) - self.assertEqual(0, score(' \t\n')) - self.assertEqual(0, score('hous3')) - self.assertEqual(0, score('wo rd')) + self.assertEqual(score(''), 0) + self.assertEqual(score(' \t\n'), 0) + self.assertEqual(score('hous3'), 0) + self.assertEqual(score('wo rd'), 0) def test_scores_very_short_word(self): - self.assertEqual(1, score('a')) + self.assertEqual(score('a'), 1) def test_scores_other_very_short_word(self): - self.assertEqual(4, score('f')) + self.assertEqual(score('f'), 4) def test_simple_word_scores_the_number_of_letters(self): - self.assertEqual(6, score("street")) + self.assertEqual(score("street"), 6) def test_complicated_word_scores_more(self): - self.assertEqual(22, score("quirky")) + self.assertEqual(score("quirky"), 22) def test_scores_are_case_insensitive(self): - self.assertEqual(41, score("OxyphenButazone")) + self.assertEqual(score("OxyphenButazone"), 41) if __name__ == '__main__': diff --git a/exercises/secret-handshake/secret_handshake_test.py b/exercises/secret-handshake/secret_handshake_test.py index f55dd6b94e..e36be88bd3 100644 --- a/exercises/secret-handshake/secret_handshake_test.py +++ b/exercises/secret-handshake/secret_handshake_test.py @@ -5,44 +5,45 @@ class HandshakeTest(unittest.TestCase): def test_shake_int(self): - self.assertEqual(['wink', 'jump'], handshake(9)) + self.assertEqual(handshake(9), ['wink', 'jump']) def test_shake_bin1(self): - self.assertEqual(['close your eyes', 'double blink'], handshake('10110')) + self.assertEqual( + handshake('10110'), ['close your eyes', 'double blink']) def test_shake_bin2(self): - self.assertEqual(['wink', 'close your eyes'], handshake('101')) + self.assertEqual(handshake('101'), ['wink', 'close your eyes']) def test_shake_negative_int(self): - self.assertEqual([], handshake(-9)) + self.assertEqual(handshake(-9), []) def test_shake_bin_invalid(self): - self.assertEqual([], handshake('121')) + self.assertEqual(handshake('121'), []) def test_unknown_action(self): - self.assertEqual('0', code(['wink', 'sneeze'])) + self.assertEqual(code(['wink', 'sneeze']), '0') def test_code1(self): - self.assertEqual('1100', code(['close your eyes', 'jump'])) + self.assertEqual(code(['close your eyes', 'jump']), '1100') def test_code2(self): - self.assertEqual('11', code(['wink', 'double blink'])) + self.assertEqual(code(['wink', 'double blink']), '11') def test_code3(self): - self.assertEqual('11010', code(['jump', 'double blink'])) + self.assertEqual(code(['jump', 'double blink']), '11010') def test_composition1(self): - self.assertEqual('11011', code(handshake(27))) + self.assertEqual(code(handshake(27)), '11011') def test_composition2(self): - self.assertEqual('1', code(handshake(1))) + self.assertEqual(code(handshake(1)), '1') def test_composition3(self): - self.assertEqual('111', code(handshake('111'))) + self.assertEqual(code(handshake('111')), '111') def test_composition4(self): inp = ['wink', 'double blink', 'jump'] - self.assertEqual(inp, handshake(code(inp))) + self.assertEqual(handshake(code(inp)), inp) if __name__ == '__main__': diff --git a/exercises/series/series_test.py b/exercises/series/series_test.py index 7f9a3892f0..6bfd680e24 100644 --- a/exercises/series/series_test.py +++ b/exercises/series/series_test.py @@ -11,26 +11,30 @@ class SeriesTest(unittest.TestCase): def test_slices_of_one(self): - self.assertEqual([[0], [1], [2], [3], [4]], - slices("01234", 1)) + self.assertEqual( + slices("01234", 1), + [[0], [1], [2], [3], [4]], ) def test_slices_of_two(self): - self.assertEqual([[9, 7], [7, 8], [8, 6], [6, 7], - [7, 5], [5, 6], [6, 4]], - slices("97867564", 2)) + self.assertEqual( + slices("97867564", 2), + [[9, 7], [7, 8], [8, 6], [6, 7], [7, 5], [5, 6], [6, 4]], ) def test_slices_of_three(self): - self.assertEqual([[9, 7, 8], [7, 8, 6], [8, 6, 7], - [6, 7, 5], [7, 5, 6], [5, 6, 4]], - slices("97867564", 3)) + self.assertEqual( + slices("97867564", 3), + [[9, 7, 8], [7, 8, 6], [8, 6, 7], [6, 7, 5], [7, 5, 6], [5, 6, 4]], + ) def test_slices_of_four(self): - self.assertEqual([[0, 1, 2, 3], [1, 2, 3, 4]], - slices("01234", 4)) + self.assertEqual( + slices("01234", 4), + [[0, 1, 2, 3], [1, 2, 3, 4]], ) def test_slices_of_five(self): - self.assertEqual([[0, 1, 2, 3, 4]], - slices("01234", 5)) + self.assertEqual( + slices("01234", 5), + [[0, 1, 2, 3, 4]], ) def test_overly_long_slice(self): with self.assertRaises(ValueError): diff --git a/exercises/simple-cipher/simple_cipher_test.py b/exercises/simple-cipher/simple_cipher_test.py index 4bbed1078a..fb0d51f9a1 100644 --- a/exercises/simple-cipher/simple_cipher_test.py +++ b/exercises/simple-cipher/simple_cipher_test.py @@ -4,64 +4,66 @@ class CipherTest(unittest.TestCase): - def test_caesar_encode1(self): - self.assertEqual('lwlvdzhvrphsurjudpplqjlqsbwkrq', - Caesar().encode('itisawesomeprogramminginpython')) + self.assertEqual(Caesar().encode('itisawesomeprogramminginpython'), + 'lwlvdzhvrphsurjudpplqjlqsbwkrq') def test_caesar_encode2(self): - self.assertEqual('yhqlylglylfl', Caesar().encode('venividivici')) + self.assertEqual(Caesar().encode('venividivici'), 'yhqlylglylfl') def test_caesar_encode3(self): - self.assertEqual('wzdvwkhqljkwehiruhfkulvwpdv', - Caesar().encode('\'Twas the night before Christmas')) + self.assertEqual(Caesar().encode('\'Twas the night before Christmas'), + 'wzdvwkhqljkwehiruhfkulvwpdv') def test_caesar_encode_with_numbers(self): - self.assertEqual('jr', Caesar().encode('1, 2, 3, Go!')) + self.assertEqual(Caesar().encode('1, 2, 3, Go!'), 'jr') def test_caesar_decode(self): - self.assertEqual('venividivici', Caesar().decode('yhqlylglylfl')) + self.assertEqual(Caesar().decode('yhqlylglylfl'), 'venividivici') def test_cipher_encode1(self): c = Cipher('a') - self.assertEqual('itisawesomeprogramminginpython', - c.encode('itisawesomeprogramminginpython')) + self.assertEqual( + c.encode('itisawesomeprogramminginpython'), + 'itisawesomeprogramminginpython') def test_cipher_encode2(self): c = Cipher('aaaaaaaaaaaaaaaaaaaaaa') - self.assertEqual('itisawesomeprogramminginpython', - c.encode('itisawesomeprogramminginpython')) + self.assertEqual( + c.encode('itisawesomeprogramminginpython'), + 'itisawesomeprogramminginpython') def test_cipher_encode3(self): c = Cipher('dddddddddddddddddddddd') - self.assertEqual('yhqlylglylfl', c.encode('venividivici')) + self.assertEqual(c.encode('venividivici'), 'yhqlylglylfl') def test_cipher_encode4(self): key = ('duxrceqyaimciuucnelkeoxjhdyduucpmrxmaivacmybmsdrzwqxvbxsy' 'gzsabdjmdjabeorttiwinfrpmpogvabiofqexnohrqu') c = Cipher(key) - self.assertEqual('gccwkixcltycv', c.encode('diffiehellman')) + self.assertEqual(c.encode('diffiehellman'), 'gccwkixcltycv') def test_cipher_encode_short_key(self): c = Cipher('abcd') - self.assertEqual('abcdabcd', c.encode('aaaaaaaa')) + self.assertEqual(c.encode('aaaaaaaa'), 'abcdabcd') def test_cipher_compositiion1(self): key = ('duxrceqyaimciuucnelkeoxjhdyduucpmrxmaivacmybmsdrzwqxvbxsy' 'gzsabdjmdjabeorttiwinfrpmpogvabiofqexnohrqu') plaintext = 'adaywithoutlaughterisadaywasted' c = Cipher(key) - self.assertEqual(plaintext, c.decode(c.encode(plaintext))) + self.assertEqual(c.decode(c.encode(plaintext)), plaintext) def test_cipher_compositiion2(self): plaintext = 'adaywithoutlaughterisadaywasted' c = Cipher() - self.assertEqual(plaintext, c.decode(c.encode(plaintext))) + self.assertEqual(c.decode(c.encode(plaintext)), plaintext) def test_cipher_random_key(self): c = Cipher() - self.assertTrue(len(c.key) >= 100, - 'A random key must be generated when no key is given!') + self.assertTrue( + len(c.key) >= 100, + 'A random key must be generated when no key is given!') self.assertTrue(c.key.islower() and c.key.isalpha(), 'All items in the key must be chars and lowercase!') diff --git a/exercises/space-age/space_age_test.py b/exercises/space-age/space_age_test.py index 4e02683e21..7c97f30b07 100644 --- a/exercises/space-age/space_age_test.py +++ b/exercises/space-age/space_age_test.py @@ -6,46 +6,46 @@ class SpaceAgeTest(unittest.TestCase): def test_age_in_seconds(self): age = SpaceAge(1e6) - self.assertEqual(1e6, age.seconds) + self.assertEqual(age.seconds, 1e6) def test_age_in_earth_years(self): age = SpaceAge(1e9) - self.assertEqual(31.69, age.on_earth()) + self.assertEqual(age.on_earth(), 31.69) def test_age_in_mercury_years(self): age = SpaceAge(2134835688) - self.assertEqual(67.65, age.on_earth()) - self.assertEqual(280.88, age.on_mercury()) + self.assertEqual(age.on_earth(), 67.65) + self.assertEqual(age.on_mercury(), 280.88) def test_age_in_venus_years(self): age = SpaceAge(189839836) - self.assertEqual(6.02, age.on_earth()) - self.assertEqual(9.78, age.on_venus()) + self.assertEqual(age.on_earth(), 6.02) + self.assertEqual(age.on_venus(), 9.78) def test_age_on_mars(self): age = SpaceAge(2329871239) - self.assertEqual(73.83, age.on_earth()) - self.assertEqual(39.25, age.on_mars()) + self.assertEqual(age.on_earth(), 73.83) + self.assertEqual(age.on_mars(), 39.25) def test_age_on_jupiter(self): age = SpaceAge(901876382) - self.assertEqual(28.58, age.on_earth()) - self.assertEqual(2.41, age.on_jupiter()) + self.assertEqual(age.on_earth(), 28.58) + self.assertEqual(age.on_jupiter(), 2.41) def test_age_on_saturn(self): age = SpaceAge(3e9) - self.assertEqual(95.06, age.on_earth()) - self.assertEqual(3.23, age.on_saturn()) + self.assertEqual(age.on_earth(), 95.06) + self.assertEqual(age.on_saturn(), 3.23) def test_age_on_uranus(self): age = SpaceAge(3210123456) - self.assertEqual(101.72, age.on_earth()) - self.assertEqual(1.21, age.on_uranus()) + self.assertEqual(age.on_earth(), 101.72) + self.assertEqual(age.on_uranus(), 1.21) def test_age_on_neptune(self): age = SpaceAge(8210123456) - self.assertEqual(260.16, age.on_earth()) - self.assertEqual(1.58, age.on_neptune()) + self.assertEqual(age.on_earth(), 260.16) + self.assertEqual(age.on_neptune(), 1.58) if __name__ == '__main__': diff --git a/exercises/strain/strain_test.py b/exercises/strain/strain_test.py index 313db54ae1..9341ddb6ba 100644 --- a/exercises/strain/strain_test.py +++ b/exercises/strain/strain_test.py @@ -5,40 +5,41 @@ class StrainTest(unittest.TestCase): def test_empty_sequence(self): - self.assertEqual([], keep([], lambda x: x % 2 == 0)) + self.assertEqual(keep([], lambda x: x % 2 == 0), []) def test_empty_keep(self): inp = [2, 4, 6, 8, 10] out = [] - self.assertEqual(out, keep(inp, lambda x: x % 2 == 1)) + self.assertEqual(keep(inp, lambda x: x % 2 == 1), out) def test_empty_discard(self): inp = [2, 4, 6, 8, 10] out = [] - self.assertEqual(out, discard(inp, lambda x: x % 2 == 0)) + self.assertEqual(discard(inp, lambda x: x % 2 == 0), out) def test_keep_everything(self): inp = [2, 4, 6, 8, 10] - self.assertEqual(inp, keep(inp, lambda x: x % 2 == 0)) + self.assertEqual(keep(inp, lambda x: x % 2 == 0), inp) def test_discard_endswith(self): inp = ['dough', 'cash', 'plough', 'though', 'through', 'enough'] out = ['cash'] - self.assertEqual(out, discard(inp, lambda x: str.endswith(x, 'ough'))) + self.assertEqual(discard(inp, lambda x: str.endswith(x, 'ough')), out) def test_keep_z(self): inp = ['zebra', 'arizona', 'apple', 'google', 'mozilla'] out = ['zebra', 'arizona', 'mozilla'] - self.assertEqual(out, keep(inp, lambda x: 'z' in x)) + self.assertEqual(keep(inp, lambda x: 'z' in x), out) def test_keep_discard(self): inp = ['1,2,3', 'one', 'almost!', 'love'] - self.assertEqual([], discard(keep(inp, str.isalpha), str.isalpha)) + self.assertEqual(discard(keep(inp, str.isalpha), str.isalpha), []) def test_keep_plus_discard(self): inp = ['1,2,3', 'one', 'almost!', 'love'] out = ['one', 'love', '1,2,3', 'almost!'] - self.assertEqual(out, keep(inp, str.isalpha) + discard(inp, str.isalpha)) + self.assertEqual( + keep(inp, str.isalpha) + discard(inp, str.isalpha), out) if __name__ == '__main__': diff --git a/exercises/sublist/sublist_test.py b/exercises/sublist/sublist_test.py index 791101f22c..55806eb8c6 100644 --- a/exercises/sublist/sublist_test.py +++ b/exercises/sublist/sublist_test.py @@ -5,82 +5,81 @@ class SublistTest(unittest.TestCase): def test_unique_return_vals(self): - self.assertEqual(4, len(set([SUBLIST, SUPERLIST, EQUAL, UNEQUAL]))) + self.assertEqual(len(set([SUBLIST, SUPERLIST, EQUAL, UNEQUAL])), 4) def test_empty_lists(self): - self.assertEqual(EQUAL, check_lists([], [])) + self.assertEqual(check_lists([], []), EQUAL) def test_empty_list_within(self): - self.assertEqual(SUBLIST, check_lists([], [1, 2, 3])) + self.assertEqual(check_lists([], [1, 2, 3]), SUBLIST) def test_within_empty_list(self): - self.assertEqual(SUPERLIST, check_lists([1], [])) + self.assertEqual(check_lists([1], []), SUPERLIST) def test_equal_lists(self): l1 = [0, 1, 2] l2 = [0, 1, 2] - self.assertEqual(EQUAL, check_lists(l1, l2)) + self.assertEqual(check_lists(l1, l2), EQUAL) def test_different_lists(self): l1 = list(range(1000000)) l2 = list(range(1, 1000001)) - self.assertEqual(UNEQUAL, check_lists(l1, l2)) + self.assertEqual(check_lists(l1, l2), UNEQUAL) def test_false_start(self): l1 = [1, 2, 5] l2 = [0, 1, 2, 3, 1, 2, 5, 6] - self.assertEqual(SUBLIST, check_lists(l1, l2)) + self.assertEqual(check_lists(l1, l2), SUBLIST) def test_consecutive(self): l1 = [1, 1, 2] l2 = [0, 1, 1, 1, 2, 1, 2] - self.assertEqual(SUBLIST, check_lists(l1, l2)) + self.assertEqual(check_lists(l1, l2), SUBLIST) def test_sublist_at_start(self): l1 = [0, 1, 2] l2 = [0, 1, 2, 3, 4, 5] - self.assertEqual(SUBLIST, check_lists(l1, l2)) + self.assertEqual(check_lists(l1, l2), SUBLIST) def test_sublist_in_middle(self): l1 = [2, 3, 4] l2 = [0, 1, 2, 3, 4, 5] - self.assertEqual(SUBLIST, check_lists(l1, l2)) + self.assertEqual(check_lists(l1, l2), SUBLIST) def test_sublist_at_end(self): l1 = [3, 4, 5] l2 = [0, 1, 2, 3, 4, 5] - self.assertEqual(SUBLIST, check_lists(l1, l2)) + self.assertEqual(check_lists(l1, l2), SUBLIST) def test_at_start_of_superlist(self): l1 = [0, 1, 2, 3, 4, 5] l2 = [0, 1, 2] - self.assertEqual(SUPERLIST, check_lists(l1, l2)) + self.assertEqual(check_lists(l1, l2), SUPERLIST) def test_in_middle_of_superlist(self): l1 = [0, 1, 2, 3, 4, 5] l2 = [2, 3] - self.assertEqual(SUPERLIST, check_lists(l1, l2)) + self.assertEqual(check_lists(l1, l2), SUPERLIST) def test_at_end_of_superlist(self): l1 = [0, 1, 2, 3, 4, 5] l2 = [3, 4, 5] - self.assertEqual(SUPERLIST, check_lists(l1, l2)) + self.assertEqual(check_lists(l1, l2), SUPERLIST) def test_large_lists(self): l1 = list(range(1000)) * 1000 + list(range(1000, 1100)) l2 = list(range(900, 1050)) - self.assertEqual(SUPERLIST, check_lists(l1, l2)) + self.assertEqual(check_lists(l1, l2), SUPERLIST) def test_spread_sublist(self): multiples_of_3 = list(range(3, 200, 3)) multiples_of_15 = list(range(15, 200, 15)) - self.assertEqual(UNEQUAL, - check_lists(multiples_of_15, multiples_of_3)) + self.assertEqual(check_lists(multiples_of_15, multiples_of_3), UNEQUAL) def test_avoid_sets(self): - self.assertEqual(UNEQUAL, check_lists([1, 3], [1, 2, 3])) - self.assertEqual(UNEQUAL, check_lists([1, 2, 3], [1, 3])) - self.assertEqual(UNEQUAL, check_lists([1, 2, 3], [3, 2, 1])) + self.assertEqual(check_lists([1, 3], [1, 2, 3]), UNEQUAL) + self.assertEqual(check_lists([1, 2, 3], [1, 3]), UNEQUAL) + self.assertEqual(check_lists([1, 2, 3], [3, 2, 1]), UNEQUAL) if __name__ == '__main__': diff --git a/exercises/triangle/triangle_test.py b/exercises/triangle/triangle_test.py index c8e8a924c8..6566744f5c 100644 --- a/exercises/triangle/triangle_test.py +++ b/exercises/triangle/triangle_test.py @@ -5,63 +5,48 @@ class TriangleTests(unittest.TestCase): def test_equilateral_triangles_have_equal_sides(self): - self.assertEqual("equilateral", Triangle(2, 2, 2).kind()) + self.assertEqual(Triangle(2, 2, 2).kind(), "equilateral") def test_larger_equilateral_triangles_also_have_equal_sides(self): - self.assertEqual("equilateral", Triangle(10, 10, 10).kind()) + self.assertEqual(Triangle(10, 10, 10).kind(), "equilateral") def test_isosceles_triangles_have_last_two_sides_equal(self): - self.assertEqual("isosceles", Triangle(3, 4, 4).kind()) + self.assertEqual(Triangle(3, 4, 4).kind(), "isosceles") def test_isosceles_triangles_have_first_and_last_sides_equal(self): - self.assertEqual("isosceles", Triangle(4, 3, 4).kind()) + self.assertEqual(Triangle(4, 3, 4).kind(), "isosceles") def test_isosceles_triangles_have_two_first_sides_equal(self): - self.assertEqual("isosceles", Triangle(4, 4, 3).kind()) + self.assertEqual(Triangle(4, 4, 3).kind(), "isosceles") def test_isosceles_triangles_have_in_fact_exactly_two_sides_equal(self): - self.assertEqual("isosceles", Triangle(10, 10, 2).kind()) + self.assertEqual(Triangle(10, 10, 2).kind(), "isosceles") def test_scalene_triangles_have_no_equal_sides(self): - self.assertEqual("scalene", Triangle(3, 4, 5).kind()) + self.assertEqual(Triangle(3, 4, 5).kind(), "scalene") def test_scalene_triangles_have_no_equal_sides_at_a_larger_scale_too(self): - self.assertEqual("scalene", Triangle(10, 11, 12).kind()) + self.assertEqual(Triangle(10, 11, 12).kind(), "scalene") - self.assertEqual("scalene", Triangle(5, 4, 2).kind()) + self.assertEqual(Triangle(5, 4, 2).kind(), "scalene") def test_very_small_triangles_are_legal(self): - self.assertEqual("scalene", Triangle(0.4, 0.6, 0.3).kind()) + self.assertEqual(Triangle(0.4, 0.6, 0.3).kind(), "scalene") def test_triangles_with_no_size_are_illegal(self): - self.assertRaises( - TriangleError, - Triangle, 0, 0, 0 - ) + self.assertRaises(TriangleError, Triangle, 0, 0, 0) def test_triangles_with_negative_sides_are_illegal(self): - self.assertRaises( - TriangleError, - Triangle, 3, 4, -5 - ) + self.assertRaises(TriangleError, Triangle, 3, 4, -5) def test_triangles_violating_triangle_inequality_are_illegal(self): - self.assertRaises( - TriangleError, - Triangle, 1, 1, 3 - ) + self.assertRaises(TriangleError, Triangle, 1, 1, 3) def test_triangles_violating_triangle_inequality_are_illegal_2(self): - self.assertRaises( - TriangleError, - Triangle, 2, 4, 2 - ) + self.assertRaises(TriangleError, Triangle, 2, 4, 2) def test_triangles_violating_triangle_inequality_are_illegal_3(self): - self.assertRaises( - TriangleError, - Triangle, 7, 3, 2 - ) + self.assertRaises(TriangleError, Triangle, 7, 3, 2) if __name__ == '__main__': diff --git a/exercises/trinary/trinary_test.py b/exercises/trinary/trinary_test.py index 1ba7f10d30..3e9a46438a 100644 --- a/exercises/trinary/trinary_test.py +++ b/exercises/trinary/trinary_test.py @@ -5,25 +5,25 @@ class TrinaryTest(unittest.TestCase): def test_valid_trinary1(self): - self.assertEqual(0, trinary('0')) + self.assertEqual(trinary('0'), 0) def test_valid_trinary2(self): - self.assertEqual(1, trinary('1')) + self.assertEqual(trinary('1'), 1) def test_valid_trinary3(self): - self.assertEqual(3, trinary('10')) + self.assertEqual(trinary('10'), 3) def test_valid_trinary4(self): - self.assertEqual(307, trinary('102101')) + self.assertEqual(trinary('102101'), 307) def test_valid_trinary5(self): - self.assertEqual(242, trinary('22222')) + self.assertEqual(trinary('22222'), 242) def test_valid_trinary6(self): - self.assertEqual(81, trinary('10000')) + self.assertEqual(trinary('10000'), 81) def test_invalid_trinary(self): - self.assertEqual(0, trinary('13201')) + self.assertEqual(trinary('13201'), 0) if __name__ == '__main__': diff --git a/exercises/twelve-days/twelve_days_test.py b/exercises/twelve-days/twelve_days_test.py index ded3f3125e..aee340e73c 100644 --- a/exercises/twelve-days/twelve_days_test.py +++ b/exercises/twelve-days/twelve_days_test.py @@ -4,24 +4,23 @@ class TwelveDaysTests(unittest.TestCase): - def test_verse1(self): expected = ("On the first day of Christmas my true love gave to me, " "a Partridge in a Pear Tree.\n") - self.assertEqual(expected, verse(1)) + self.assertEqual(verse(1), expected) def test_verse2(self): expected = ("On the second day of Christmas my true love gave to me, " "two Turtle Doves, " "and a Partridge in a Pear Tree.\n") - self.assertEqual(expected, verse(2)) + self.assertEqual(verse(2), expected) def test_verse3(self): expected = ("On the third day of Christmas my true love gave to me, " "three French Hens, " "two Turtle Doves, " "and a Partridge in a Pear Tree.\n") - self.assertEqual(expected, verse(3)) + self.assertEqual(verse(3), expected) def test_verse4(self): expected = ("On the fourth day of Christmas my true love gave to me, " @@ -29,7 +28,7 @@ def test_verse4(self): "three French Hens, " "two Turtle Doves, " "and a Partridge in a Pear Tree.\n") - self.assertEqual(expected, verse(4)) + self.assertEqual(verse(4), expected) def test_verse5(self): expected = ("On the fifth day of Christmas my true love gave to me, " @@ -38,7 +37,7 @@ def test_verse5(self): "three French Hens, " "two Turtle Doves, " "and a Partridge in a Pear Tree.\n") - self.assertEqual(expected, verse(5)) + self.assertEqual(verse(5), expected) def test_verse6(self): expected = ("On the sixth day of Christmas my true love gave to me, " @@ -48,7 +47,7 @@ def test_verse6(self): "three French Hens, " "two Turtle Doves, " "and a Partridge in a Pear Tree.\n") - self.assertEqual(expected, verse(6)) + self.assertEqual(verse(6), expected) def test_verse7(self): expected = ("On the seventh day of Christmas my true love gave to me, " @@ -59,7 +58,7 @@ def test_verse7(self): "three French Hens, " "two Turtle Doves, " "and a Partridge in a Pear Tree.\n") - self.assertEqual(expected, verse(7)) + self.assertEqual(verse(7), expected) def test_verse8(self): expected = ("On the eighth day of Christmas my true love gave to me, " @@ -71,7 +70,7 @@ def test_verse8(self): "three French Hens, " "two Turtle Doves, " "and a Partridge in a Pear Tree.\n") - self.assertEqual(expected, verse(8)) + self.assertEqual(verse(8), expected) def test_verse9(self): expected = ("On the ninth day of Christmas my true love gave to me, " @@ -84,7 +83,7 @@ def test_verse9(self): "three French Hens, " "two Turtle Doves, " "and a Partridge in a Pear Tree.\n") - self.assertEqual(expected, verse(9)) + self.assertEqual(verse(9), expected) def test_verse10(self): expected = ("On the tenth day of Christmas my true love gave to me, " @@ -98,7 +97,7 @@ def test_verse10(self): "three French Hens, " "two Turtle Doves, " "and a Partridge in a Pear Tree.\n") - self.assertEqual(expected, verse(10)) + self.assertEqual(verse(10), expected) def test_verse11(self): expected = ("On the eleventh day of Christmas " @@ -114,7 +113,7 @@ def test_verse11(self): "three French Hens, " "two Turtle Doves, " "and a Partridge in a Pear Tree.\n") - self.assertEqual(expected, verse(11)) + self.assertEqual(verse(11), expected) def test_verse12(self): expected = ("On the twelfth day of Christmas my true love gave to me, " @@ -130,7 +129,7 @@ def test_verse12(self): "three French Hens, " "two Turtle Doves, " "and a Partridge in a Pear Tree.\n") - self.assertEqual(expected, verse(12)) + self.assertEqual(verse(12), expected) def test_multiple_verses(self): expected = ("On the first day of Christmas my true love gave to me, " @@ -142,7 +141,7 @@ def test_multiple_verses(self): "three French Hens, " "two Turtle Doves, " "and a Partridge in a Pear Tree.\n\n") - self.assertEqual(expected, verses(1, 3)) + self.assertEqual(verses(1, 3), expected) def test_the_whole_song(self): self.assertEqual(verses(1, 12), sing()) diff --git a/exercises/wordy/wordy_test.py b/exercises/wordy/wordy_test.py index c4a4f08f18..c35fe38529 100644 --- a/exercises/wordy/wordy_test.py +++ b/exercises/wordy/wordy_test.py @@ -4,50 +4,49 @@ class WordyTest(unittest.TestCase): - def test_simple_add_1(self): - self.assertEqual(18, calculate("What is 5 plus 13?")) + self.assertEqual(calculate("What is 5 plus 13?"), 18) def test_simple_add_2(self): - self.assertEqual(-8, calculate("What is 5 plus -13?")) + self.assertEqual(calculate("What is 5 plus -13?"), -8) def test_simple_sub_1(self): - self.assertEqual(6, calculate("What is 103 minus 97?")) + self.assertEqual(calculate("What is 103 minus 97?"), 6) def test_simple_sub_2(self): - self.assertEqual(-6, calculate("What is 97 minus 103?")) + self.assertEqual(calculate("What is 97 minus 103?"), -6) def test_simple_mult(self): - self.assertEqual(21, calculate("What is 7 multiplied by 3?")) + self.assertEqual(calculate("What is 7 multiplied by 3?"), 21) def test_simple_div(self): - self.assertEqual(9, calculate("What is 45 divided by 5?")) + self.assertEqual(calculate("What is 45 divided by 5?"), 9) def test_add_negative_numbers(self): - self.assertEqual(-11, calculate("What is -1 plus -10?")) + self.assertEqual(calculate("What is -1 plus -10?"), -11) def test_add_more_digits(self): - self.assertEqual(45801, calculate("What is 123 plus 45678?")) + self.assertEqual(calculate("What is 123 plus 45678?"), 45801) def test_add_twice(self): - self.assertEqual(4, calculate("What is 1 plus 2 plus 1?")) + self.assertEqual(calculate("What is 1 plus 2 plus 1?"), 4) def test_add_then_subtract(self): - self.assertEqual(14, calculate("What is 1 plus 5 minus -8?")) + self.assertEqual(calculate("What is 1 plus 5 minus -8?"), 14) def test_subtract_twice(self): - self.assertEqual(-7, calculate("What is 20 minus 14 minus 13?")) + self.assertEqual(calculate("What is 20 minus 14 minus 13?"), -7) def test_multiply_twice(self): - self.assertEqual(-12, calculate("What is 2 multiplied by -2 " - "multiplied by 3?")) + self.assertEqual( + calculate("What is 2 multiplied by -2 multiplied by 3?"), -12) def test_add_then_multiply(self): - self.assertEqual(-8, calculate("What is -3 plus 7 multiplied by -2?")) + self.assertEqual(calculate("What is -3 plus 7 multiplied by -2?"), -8) def test_divide_twice(self): self.assertEqual( - 16, calculate("What is -12000 divided by 25 divided by -30?")) + calculate("What is -12000 divided by 25 divided by -30?"), 16) def test_invalid_operation(self): self.assertRaises(ValueError, calculate, "What is 4 xor 7?") @@ -56,8 +55,8 @@ def test_missing_operation(self): self.assertRaises(ValueError, calculate, "What is 2 2 minus 3?") def test_missing_number(self): - self.assertRaises(ValueError, calculate, "What is 7 plus " - "multiplied by -2?") + self.assertRaises(ValueError, calculate, + "What is 7 plus multiplied by -2?") def test_irrelevant_question(self): self.assertRaises(ValueError, calculate, "Which is greater, 3 or 2?") diff --git a/exercises/zebra-puzzle/zebra_puzzle_test.py b/exercises/zebra-puzzle/zebra_puzzle_test.py index a5abe2173b..48dbaca8d0 100644 --- a/exercises/zebra-puzzle/zebra_puzzle_test.py +++ b/exercises/zebra-puzzle/zebra_puzzle_test.py @@ -5,9 +5,9 @@ class ZebraPuzzleTest(unittest.TestCase): def test_solution(self): - self.assertEqual(("It is the Norwegian who drinks the water.\n" - "The Japanese keeps the zebra."), - solution()) + self.assertEqual(solution(), + ("It is the Norwegian who drinks the water.\n" + "The Japanese keeps the zebra.")) if __name__ == '__main__':