def test_nonnested_list(self): obj1 = [2, 4, 6, 8, 10] obj2 = [1, 3, 5, 7, 9] obj3 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] self.assertEqual(count_even(obj1), 5) self.assertEqual(count_even(obj2), 0) self.assertEqual(count_even(obj3), 5)
def test_nested_list(self): lst1 = [1, [2], 6, [9, 7], 10, 23, [65, 79], 24] self.assertEqual(count_even(lst1), 4) lst2 = [3, 1, [43, 55], [127535, [127535, 4323]], 5] self.assertEqual(count_even(lst2), 0) lst3 = [0, 0, 0, [[0, [[0, 0], 0], 0], 0], 0] self.assertEqual(count_even(lst3), 10) lst4 = [[[[]]], [[]], []] self.assertEqual(count_even(lst4), 0)
def test_object(self, obj): if obj % 2 == 0: self.assertEqual(count_even(obj), 1) else: self.assertEqual(count_even(obj), 0)
def test_empty_list(self): obj = [] self.assertEqual(count_even(obj), 0)