def test_zip_with_infinite_sequence(self): first_names = ['John', 'Miles'] last_names = ['Coltrane', 'Davis'] spaces = repeat(' ') expected = ['John Coltrane', 'Miles Davis'] actual = solution.zip_with(lambda x, y, z: x + y + z, first_names, spaces, last_names) self.assertEqual(expected, list(actual))
def test_zip_with_one_element(self): first = [1, 2] second = [3] expected = [(1, 3)] actual = solution.zip_with(lambda x, y: (x, y), first, second) self.assertEqual(expected, list(actual))
def test_zip_with_three_iterables(self): first = ('a', 'b', 'c', 'd') second = ['e', 'f', 'g'] third = ('h', 'i', 'j', 'k', 'l') expected = ['aeh', 'bfi', 'cgj'] actual = solution.zip_with(lambda x, y, z: x + y + z, first, second, third) self.assertEqual(expected, list(actual))
def test_zip_with_empty(self): first_names = ['Charlie', 'Dizzy'] last_names = [] expected = [] actual = solution.zip_with(str.__add__, first_names, last_names) self.assertEqual(expected, list(actual))
def test_zip_with_simple(self): first_names = ['Charlie', 'Dizzy'] last_names = ['Parker', 'Gillespie'] expected = ['CharlieParker', 'DizzyGillespie'] actual = solution.zip_with(str.__add__, first_names, last_names) self.assertEqual(expected, list(actual))
def test_zip_with_nonequalty(self): numbers1 = [1, 3] numbers2 = [2, 4] actual = solution.zip_with(int.__add__, numbers1, numbers2) self.assertNotEquals([3, 5, 8], list(actual))
def test_zip_with_vargs_function(self): expected = [1 + 2 + 3 + 5 + 8] actual = solution.zip_with(lambda *x: sum(x), [1], [2], [3], [5], [8]) self.assertEqual(expected, list(actual))
def test_zip_with_empty(self): expected = [] actual = solution.zip_with(lambda x: x) self.assertEqual(expected, list(actual))
def test_zip_with(fn, a1, a2, result): assert zip_with(fn, a1, a2) == result