Skip to content

Refactor assertEqual(actual,expected) param order #449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions exercises/accumulate/accumulate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down
15 changes: 8 additions & 7 deletions exercises/acronym/acronym_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down
11 changes: 5 additions & 6 deletions exercises/allergies/allergies_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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__':
Expand Down
38 changes: 16 additions & 22 deletions exercises/atbash-cipher/atbash_cipher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__':
Expand Down
22 changes: 12 additions & 10 deletions exercises/binary-search/binary_search_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
15 changes: 7 additions & 8 deletions exercises/binary/binary_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
33 changes: 16 additions & 17 deletions exercises/circular-buffer/circular_buffer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@


class CircularBufferTest(unittest.TestCase):

def test_read_empty_buffer(self):
buf = CircularBuffer(1)
with self.assertRaises(BufferEmptyException):
Expand All @@ -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()

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -71,17 +70,17 @@ 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()

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()

Expand All @@ -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()

Expand Down
Loading