# test_lab10.py # Lillian Lee (LJL2) and Walker White (wmw2) # November 5, 2013 """Test cases for lab7.py""" from cornelltest import * from lab10 import * def test_numberof(): mylist = [5, 3, 3455, 74, 74, 74, 3] assert_equals(3, numberof(mylist,74)) assert_equals(2, numberof(mylist,3)) assert_equals(0, numberof(mylist,4)) assert_equals(1, numberof([4],4)) assert_equals(0, numberof([],4)) print ' numberof looks okay' def test_replace_copy(): assert_equals([4], replace_copy([5],5,4)) assert_equals([], replace_copy([], 1, 2)) mylist = [5, 3, 3455, 74, 74, 74, 3] assert_equals([5, 20, 3455, 74, 74, 74, 20], replace_copy(mylist,3, 20)) assert_equals([5, 3, 3455, 74, 74, 74, 3], replace_copy(mylist, 1, 3)) print ' replace_copy looks okay' def test_replace(): mylist = [5] replace(mylist,5,4) assert_equals([4], mylist) mylist = [] replace(mylist,1,2) assert_equals([], mylist) mylist = [5, 3, 3455, 74, 74, 74, 3] replace(mylist, 3, 20) assert_equals([5, 20, 3455, 74, 74, 74, 20], mylist) replace(mylist, 1, 3) assert_equals([5, 20, 3455, 74, 74, 74, 20], mylist) print ' replace looks okay' def test_cuberoot(): assert_equals(2.0,round(cuberoot(8,1e-12),5)) assert_equals(2.0,round(cuberoot(8,1e-12),11)) assert_equals(2.0,round(cuberoot(8,1e-1),0)) assert_equals(3.0,round(cuberoot(27,1e-12),11)) assert_equals(3.0,round(cuberoot(27,1e-1),0)) assert_equals(2.08008,round(cuberoot(9),5)) assert_equals(2.0800838231,round(cuberoot(9,1e-11),10)) print ' cuberoot looks okay' # Script Code if __name__ == '__main__': print 'Testing while loops' test_numberof() test_replace_copy() test_replace() test_cuberoot() print "Module lab10.py is working correctly"