def testSumLists(): ''' test for sumLists method ''' lst1 = createRandomList(4, 8) lst2 = createRandomList(5, 8) slist = sumLists(lst1, lst2) res1, res2, ress = map(listToNum, [lst1, lst2, slist]) assert res1 + res2 == ress print "test passed"
def test_remDupes(func): ''' test for remove duplicates method ''' print 'Testing %s... ' % func.__name__, lst = createRandomList(100, 100) ndupes = numDupes(lst) while ndupes == 0: lst = createRandomList(100, 100) ndupes = numDupes(lst) assert ndupes != 0 func(lst) assert numDupes(lst) == 0 print 'Passed.'
def test_getKthLastElem(func): ''' test for getKthLastElem method ''' print 'Testing %s... ' % func.__name__, lst = createRandomList(10, 100) nodes = [n.data for n in lst] nodes2 = list(reversed([func(lst, x).data for x in range(1, 11)])) assert nodes == nodes2 print "Passed."
def test_deleteMiddle(func): ''' test for deleteMiddle method ''' print 'Testing %s... ' % func.__name__, lst = createRandomList(6, 1000) nodes = list(lst) node3data = nodes[3].data func(nodes[3]) assert nodes[2].next.data != node3data print 'Passed.'
def test_partition(func): ''' test for list partition methods ''' print 'Testing %s... ' % func.__name__, lst = createRandomList(20, 20) func(lst, 10) nlst = list(x for x in lst) # make sure the list is partitioned correctly index = 0 while index < len(nlst): if nlst[index] >= 10: break index += 1 while index < len(nlst): assert nlst[index] >= 10 index += 1 print 'Passed'