def test_different_length_lists(self): in1 = [1, 2, 3] in2 = [4, 5, 6, 7, 8] out1 = [1, 4, 2, 5, 3, 6, 7, 8] self.assertIterableEqual(interleave(in1, in2), out1) out2 = [1, 4, 6, 2, 5, 7, 3, 8, 9] self.assertIterableEqual(interleave(in1, [4, 5], [6, 7, 8, 9]), out2)
def test_different_length_lists(self): in1 = [1, 2, 3] in2 = [4, 5, 6, 7, 8] in3 = [9] out1 = [1, 4, 9, 2, 5, 3, 6, 7, 8] self.assertIterableEqual(interleave(in1, in2, in3), out1) self.assertIterableEqual( interleave([1, 2], [3], [4, 5, 6], [7, 8], [9]), [1, 3, 4, 7, 9, 2, 5, 8, 6])
def test_response_is_iterator(self): in1 = [1, 2, 3] in2 = [4, 5, 6] output = interleave(in1, in2) self.assertEqual(iter(output), iter(output)) list(output) self.assertEqual(list(output), []) iterator = interleave(count(), count()) self.assertEqual(next(iterator), next(iterator))
def test_response_is_iterator(self): in1 = [1, 2, 3] in2 = [4, 5, 6] squares = (n**2 for n in in1) output = interleave(in1, in2) self.assertIs(iter(output), iter(output)) output = interleave(squares, squares) self.assertEqual(next(output), 1) self.assertEqual(next(output), 4) self.assertEqual(next(squares), 9) iterator = interleave(count(), count()) self.assertEqual(next(iterator), next(iterator))
def test_more_than_two_arguments(self): in1 = [1, 2, 3] in2 = [4, 5, 6] in3 = [7, 8, 9] out = [1, 4, 7, 2, 5, 8, 3, 6, 9] self.assertIterableEqual(interleave(in1, in2, in3), out)
def test_non_sequences(self): in1 = [1, 2, 3, 4] in2 = (n**2 for n in in1) out = [1, 1, 2, 4, 3, 9, 4, 16] self.assertIterableEqual(interleave(in1, in2), out)
def test_none_value(self): in1 = [1, 2, 3, None] in2 = [4, 5, 6, 7] out = [1, 4, 2, 5, 3, 6, None, 7] self.assertIterableEqual(interleave(in1, in2), out)
def test_four_items_each(self): in1 = [1, 2, 3, 4] in2 = [5, 6, 7, 8] out = [1, 5, 2, 6, 3, 7, 4, 8] self.assertIterableEqual(interleave(in1, in2), out)
def test_two_items_each(self): self.assertIterableEqual(interleave([1, 2], [3, 4]), [1, 3, 2, 4])
def test_single_item_each(self): self.assertIterableEqual(interleave([1], [2]), [1, 2])
def test_empty_lists(self): self.assertIterableEqual(interleave([], []), [])