def test_many_oneitem_list(self): self.assertEqual( [6], unique([6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6])) self.assertEqual( ['doc'], unique(['doc', 'doc', 'doc', 'doc', 'doc', 'doc', 'doc', 'doc']))
def test_more_than_one_items_list(self): self.assertEqual(['b', 'a'], unique(['b', 'a', 'a', 'b', 'b', 'b', 'a', 'a'])) self.assertEqual(['apple', 'bat', 'cat'], unique(['apple', 'bat', 'cat', 'cat', 'apple'])) self.assertEqual(['1', '2', '3', '4', '5'], unique(['1', '2', '3', '4', '5']))
def test_one_duplicate_item_list(self): self.assertListEqual(['a'], unique(['a', 'a', 'a', 'a', 'a', 'a'])) self.assertListEqual([1], unique([1, 1, 1, 1, 1, 1, 1, 1, 1])) self.assertListEqual([0.4], unique([0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4, 0.4])) self.assertListEqual([[2, 'q']], unique([[2, 'q']] * 10000)) # Extreme case
def test_two_items_many_times_list(self): self.assertEqual(['SKE', 'CPE'], unique(['SKE', 'CPE', 'CPE', 'SKE'])) self.assertEqual( [33243, 88.6], unique([33243, 88.6, 33243, 88.6, 33243, 88.6, 33243, 88.6])) self.assertEqual([888, '1st'], unique([888, 888, '1st', 888, '1st', '1st', 888]))
def test_list_in_list(self): self.assertEqual([['b'], 'a', 'b'], unique([['b'], 'a', 'a', 'b', 'b', 'b', 'a', 'a'])) self.assertEqual(['apple', 'bat', ['cat'], 'cat'], unique(['apple', 'bat', ['cat'], 'cat', 'apple'])) self.assertEqual(['1', '2', ['3'], '4', ['5']], unique(['1', '2', ['3'], '4', ['5']]))
def test_one_nest_list(self): """ Check did funtion return one nested list (no matter how much items in deeper list) """ self.assertListEqual([[]], unique([[]])) self.assertListEqual([[3, 3, 0]], unique([[3, 3, 0]])) self.assertListEqual([['Cat', 'Bat']], unique([['Cat', 'Bat']]))
def test_two_items_with_duplication_and_order_list(self): self.assertListEqual([-2, -1], sorted(unique([-1, -1, -1, -2]))) self.assertListEqual([1, 3], sorted(unique([3, 3, 3, 1]))) self.assertListEqual([2.00, 2.01], sorted(unique([2.00, 2.00, 2.01, 2.01]))) self.assertListEqual(['x', 'y'], sorted(unique(['y', 'y', 'y', 'x', 'x'])))
def test_string(self): self.assertListEqual(['h', 'e', 'l', 'o'], unique('hello')) self.assertListEqual(['m', 'o'], unique('mom')) self.assertListEqual(['t', 'h', 'a', 'i', 'l', 'n', 'd'], unique('thailand')) self.assertListEqual(['d', 'i', 's', 'c', 'r', 'e', 't'], unique('discrete'))
def test_many_items_str_and_int_list(self): self.assertListEqual([1, 2, 3, 4], unique([1, 2, 2, 3, 4, 4])) self.assertListEqual(['abd', 'cba', 'opc', 'o', 'a', 'b'], unique(['abd', 'cba', 'opc', 'o', 'o', 'a', 'b'])) self.assertListEqual(['op', 4, 5, 6, 'ab'], unique(['op', 4, 4, 5, 6, 5, 'ab', 'op'])) self.assertListEqual(['lol', 'uni', 78], unique(['lol', 'lol', 'uni', 78, 78]))
def test_many_lists_in_list(self): self.assertEqual([4000, [4], [900, 8]], unique([4000, [4], [900, 8]])) self.assertEqual([[[[]]], [1, 2, [3]]], unique([[[[]]], [1, 2, [3]]])) self.assertEqual( ['STAR', [10000, ['WATERMALON', 'LEMON']], [3.00, 'I', ['U']]], unique( ['STAR', [10000, ['WATERMALON', 'LEMON']], [3.00, 'I', ['U']]]))
def test_multiple_item_list(self): #Return only one duplicates of each same element. self.assertEqual(['h', 'd'], unique(['h', 'h', 'd', 'd', 'd'])) self.assertEqual(['hello'], unique(['hello', 'hello', 'hello', 'hello', 'hello'])) self.assertEqual([1, 2, [3, 3], 4], unique([1, 2, 2, [3, 3], 4, 4])) self.assertEqual(['bear', 'apple'], unique(['bear', 'bear', 'apple', 'bear']))
def test_two_duplicate_item_list(self): self.assertListEqual(['a', 1], unique(['a', 1, 1, 'a', 'a', 1])) self.assertListEqual([2, 7], unique([2, 7, 7, 7, 2, 7, 7])) self.assertListEqual([False, True], unique([False, False, False, True, False])) # Extreme case self.assertListEqual([[2, 'q'], ['w', 3]], unique([[2, 'q'], ['w', 3], [2, 'q'], [2, 'q']] * 10000))
def test_one_item_many_times(self): ''' Test function unique with same multiple item in list. 'typical cases' :return: list with 1 item ''' self.assertListEqual(['a'], unique(['a', 'a', 'a'])) self.assertListEqual([5], unique([5, 5, 5, 5, 5, 5, 5, 5, 5, 5])) self.assertListEqual([[1, 2, 3]], unique([[1, 2, 3], [1, 2, 3], [1, 2, 3]]))
def test_single_item_list(self): """ Test function unique with only 1 item in list. 'Borderline cases' :return: list with 1 item. """ self.assertListEqual(['hi'], unique(['hi'])) self.assertListEqual([5], unique([5])) self.assertListEqual([True], unique([True]))
def test_two_item_many_times_orders(self): """ Check is funtion return list of two element that is not the same element """ self.assertListEqual([1, 2], unique([1, 2, 1, 2, 1])) self.assertListEqual([1, 2], unique([1, 1, 1, 2, 2])) self.assertListEqual([1, 2], unique([1, 2, 2, 2, 1])) self.assertListEqual([1, 2], unique([1, 1, 1, 2, 1])) self.assertListEqual([2, 1], unique([2, 2, 1, 1, 2]))
def test_single_item_list_with_duplication(self): """test f(x) unique on typical case (1 item with duplicates) and check whether unique do a recursive scan at the same time """ self.assertListEqual(['hi'], unique(['hi', 'hi'])) self.assertListEqual([1], unique([1, 1])) self.assertListEqual([0.5], unique([0.5, 0.5, 0.5])) self.assertListEqual([1], unique([1, 1, 1, 1, 1, 1])) self.assertListEqual([[1, 2, 3]], unique([[1, 2, 3], [1, 2, 3]]))
def test_unique_two_item_many_times(self): self.assertEqual(["a", "b"], unique(["a", "b", "a", "b", "b", "a", "a", "b"])) self.assertEqual(["Andy", "Boba"], unique( ["Andy", "Boba", "Boba", "Andy", "Andy", "Boba"])) self.assertEqual(["NY", "LA"], unique( ["NY", "NY", "LA", "LA", "NY", "LA", "NY", "LA"]))
def test_many_item(self): self.assertEqual([2, 3, 4, 5], unique([2, 2, 2, 3, 3, 3, 2, 3, 4, 4, 5, 5, 5, 4])) self.assertEqual(["b", "a", "A", "B"], unique(["b", "a", "A", "b", "A", "B", "b", "a", "A"])) self.assertEqual([2, "2", 3, "3", 4, "4"], unique([ 2, 2, "2", 3, "3", "3", 4, "4", 3, 3, 4, 4, "4", "3", "2", 2, 2, 4 ]))
def test_many_item_many_times_many_orders(self): """ Test function with many item, many times ,many orders 'typical cases' :return: """ lst = [1, 2, 2, 4, [1, 2, 3], 1, [1, 2, 2, 3], [1, 2, 3]] self.assertListEqual([1, 2, 4, [1, 2, 3], [1, 2, 2, 3]], unique(lst)) lst = [1, 2, {'fruit': 'Banana'}, 3, 4, 5, 6, 4, {'fruit': 'Banana'}, 3, 2, 1, {'fruit': 'Banana'}, 5, 6, 3, 4] self.assertListEqual([1, 2, {'fruit': 'Banana'}, 3, 4, 5, 6], unique(lst))
def test_argument_not_a_list(self): """ Use another type of input 'Impossible case' :return: """ with self.assertRaises(TypeError): unique(5) with self.assertRaises(TypeError): unique('w')
def test_unique_many_items_many_times(self): self.assertEqual( ["a", "b", "c", "d"], unique(["a", "b", "c", "a", "b", "b", "a", "a", "b", "d"])) self.assertEqual(["Anne", "Aura", "Opal"], unique( ["Anne", "Aura", "Opal", "Aura", "Opal", "Anne"])) self.assertEqual(["Anne", "Aura", "Opal"], unique( ["Anne", "Aura", "Opal", "Aura", "Opal", "Anne"]))
def test_multiple_items_list_with_duplication(self): """test f(x) unique on typical case (multiple item with duplicates) and check whether unique do a recursive scan at the same time """ self.assertListEqual(['hi', 'ho'], unique(['hi', 'hi', 'ho'])) self.assertListEqual([1, 2], unique([1, 1, 2, 2])) self.assertListEqual([0.5, 5], unique([0.5, 0.5, 0.5, 5, 5, 5])) self.assertListEqual([1, [1]], unique([1, 1, 1, 1, 1, 1, [1], [1]])) self.assertListEqual([[1, 2, 3], 1, 2, 3], unique( [[1, 2, 3], [1, 2, 3], 1, 2, 3, 1, 2, 3]))
def test_multiple_nested_list(self): self.assertListEqual([[1], [2], 1.99], unique([[1], [2], 1.99])) self.assertListEqual([ 'q', 'w', ['banana', 'apple', 'orange'], ['python', 'java'], ['hello'] ], unique([ 'q', 'w', ['banana', 'apple', 'orange'], ['python', 'java'], ['hello'] ]))
def test_unique_mixed_list(self): self.assertEqual([5, 2, 'Digger', 4, 'Farmer', 6, 7], unique([ 5, 2, 'Digger', 4, 'Farmer', 5, 6, 7, 'Digger', 'Digger', 2, 5 ])) self.assertEqual( [[1, 2, 3], [3, 2, 1], 1, 8, [5], 6, 7, 'test', 4, [4, 5, 67]], unique([[1, 2, 3], [3, 2, 1], 1, 8, [5], [3, 2, 1], 6, 7, 8, 'test', 1, 4, [4, 5, 67], [3, 2, 1]]))
def test_many_items_list(self): self.assertEqual(['GOOD', 13.555, 10, []], unique(['GOOD', 13.555, 10, [], 10, 'GOOD', 13.555])) self.assertEqual([1122, 43454, 675, 213, 88655, 1435], unique([ 1122, 43454, 675, 213, 88655, 1435, 88655, 1122, 675, 1435 ])) self.assertEqual( ['PYTHON', 'IS', 'FUN', '?????'], unique(['PYTHON', 'IS', 'FUN', '?????', 'FUN', '?????', 'PYTHON']))
def test_multiple_items_with_duplication_and_order_list(self): self.assertListEqual([-2, -1, 0], sorted(unique([-1, 0, 0, -1, -1, -2]))) self.assertListEqual([1, 3, 5], sorted(unique([5, 5, 3, 3, 3, 1]))) self.assertListEqual([0.19, 2.00, 2.01], sorted( unique([2.00, 2.00, 2.01, 0.19, 0.19, 2.01]))) self.assertListEqual(['A', 'B', 'E'], sorted(unique(['E', 'E', 'B', 'A', 'A']))) self.assertListEqual(['A', 'B', 'a', 'b'], sorted(unique(['a', 'b', 'B', 'A', 'A'])))
def test_list(self): lst = unique(['d', 'f', 'f', 't']) self.assertEqual(['d', 'f', 't'], lst) lst = unique(['a', 's', 's', 'a', 'a', 'f']) self.assertEqual(['a', 's', 'f'], lst) lst = unique([]) self.assertEqual([], lst) lst = unique([1, 2, 2, 3, 4]) self.assertEqual([1, 2, 3, 4], lst) lst = unique([1, 2, 2, [1, 2, 3]]) self.assertEqual([1, 2, [1, 2, 3]], lst)
def test_many_duplicate_item_list(self): self.assertListEqual([1, 2, 'y', 4.1], unique([1, 2, 'y', 4.1, 'y', 2, 1])) self.assertListEqual(['w', 'x', 'y'], unique(['w', 'w', 'x', 'w', 'y', 'x'])) self.assertListEqual([1, 'b', [1, 'b']], unique( [1, 1, 'b', 1, 'b', [1, 'b'], 'b', [1, 'b']])) # Extreme case self.assertListEqual([[7, 'x'], [5, 'y'], 9], unique([[7, 'x'], [7, 'x'], [5, 'y'], 9] * 10000))
def test_integer(self): with self.assertRaises(TypeError): lst = unique(1) with self.assertRaises(TypeError): lst = unique(99) with self.assertRaises(TypeError): lst = unique(256) with self.assertRaises(TypeError): lst = unique(346) with self.assertRaises(TypeError): lst = unique(999)
def test_many_nested_list(self): self.assertListEqual([[1, 2, 3], [1, 2, 4], [4, 5, 6]], unique([[1, 2, 3], [1, 2, 4], [4, 5, 6]])) self.assertListEqual([[1, 2, 4], [4, 5, 6]], unique([[1, 2, 4], [4, 5, 6]])) self.assertListEqual([[9, 8, 7], [4, 3, 6]], unique([[9, 8, 7], [9, 8, 7], [4, 3, 6]])) self.assertListEqual( [[1, 2, 3], [1, 2, 4], [4, 5, 6], [9, 8, 7], [4, 3, 6]], unique([[1, 2, 3], [1, 2, 4], [4, 5, 6], [9, 8, 7], [4, 3, 6], [4, 3, 6]]))