def testK_mixedTypeElements(self):
     self.assertEqual(
         getCommonElements(['ba', 'a', 3, 2, 'k', 'c'], ['a', 2, 'l', 'c']),
         ['a', 2, 'c'])
     self.assertEqual(
         getCommonElements(['ba', 'a', [1, 2, 3], 2, 'k', 'c'],
                           ['a', 2, [1, 2, 3], 'l', 'c']),
         ['a', [1, 2, 3], 2, 'c'])
     print("+ Test testK_mixedTypeElements Passed")
 def testI_listsWithRepeatedElements(self):
     self.assertEqual(getCommonElements([1, 1, 2, 2, 3, 3], [1, 2, 2, 3]),
                      [1, 2, 3])
     self.assertEqual(getCommonElements([1, 2, 2, 3], [1, 1, 2, 2, 3, 3]),
                      [1, 2, 3])
     print("+ Test testH_invalidEntries Passed")
 def testJ_randomListsReceived(self):
     lists = generateRandomLists()
     self.assertTrue(isinstance(getCommonElements(lists[0], lists[1]),
                                list))
     print("+ Test testJ_randomListsReceived Passed")
 def testG_unOrderedLists(self):
     self.assertEqual(getCommonElements([5, 3, 6, 1, 23, 2], [3, 1, 2]),
                      [3, 1, 2])
     self.assertEqual(getCommonElements([3, 1, 2], [5, 3, 6, 1, 23, 2]),
                      [3, 1, 2])
     print("+ Test testG_unOrderedLists Passed")
 def testH_invalidEntries(self):
     with self.assertRaises(Exception) as context:
         getCommonElements(1, "s")
         getCommonElements([1, 2], [1, 2, 3])
     self.assertTrue(context.exception)
     print("+ Test testH_invalidEntries Passed")
 def testE_secondListEmpty(self):
     self.assertEqual(getCommonElements([1, 2, 3], []), [])
     print("+ Test testE_secondListEmpty Passed")
 def testF_bothListsEmpty(self):
     self.assertEqual(getCommonElements([], []), [])
     print("+ Test testF_bothListsEmpty Passed")
 def testD_firstListEmtpy(self):
     self.assertEqual(getCommonElements([], [1, 2, 3]), [])
     print("+ Test test_firstListEmtpy Passed")
 def testC_secondListLarger(self):
     self.assertEqual(getCommonElements([1, 2, 3], [1, 2, 3, 4]), [1, 2, 3])
     print("+ Test test_secondListLarger Passed")
示例#10
0
 def testB_firstListLarger(self):
     self.assertEqual(getCommonElements([1, 2, 3, 4], [1, 2, 3]), [1, 2, 3])
     print("+ Test test_firstListLarger Passed")
示例#11
0
 def testA_orderedLists(self):
     self.assertEqual(getCommonElements([1, 2, 3], [1, 2, 3]), [1, 2, 3])
     """Documentation for a method."""
     print(".+ Test test_orderedLists Passed")
示例#12
0

from list_confusion import getCommonElements
from list_confusion import generateRandomLists
import random

#Lists
#a = [1,1,2,3,4,8,13,21,34,55,89]
#b = [1,2,3,4,5,6,7,8,9,10,11,12,13]


print("-"*30)
print("List of common items:")

print(getCommonElements(random.sample(range(random.randrange(30,35)),random.randrange(10)),random.sample(range(random.randrange(30,35)),random.randrange(10))))