def testSort(n): #input random int n #make sure n is an int start = time.perf_counter() listofints = [] for x in range(0,n): listofints.append(random.randint(0,n)) #Creates a list of n random ints #for y in listofints: # print(y) #Sorts the list by calling sort from insertionsort module insertionsort.sort(listofints) #checks to see if the resulting list is sorted into nondecreasing order, reporting an error if any elements are out of sequence. #print(" ") #for y in listofints: # print(y) if not all(listofints[y] <= listofints[y+1] for y in range(len(listofints)-1)): #something returned false print("ERROR SOMETHING IS OUT OF SEQUENCE") return elapsed = time.perf_counter() - start #Also, time this return elapsed
def test_sort1(self): testcase = [3] expected = [3] self.assertEqual(sort(testcase), expected)
def test_mergesort1(self): testcase = [1, 3, 8, 2, 9, 2, 5, 6] expected = [1, 2, 2, 3, 5, 6, 8, 9] self.assertEqual(sort(testcase), expected)
def test_mergesort6(self): testcase = [3, 2, 1] expected = [1, 2, 3] self.assertEqual(sort(testcase), expected)
def test_sort5(self): testcase = [5, 1, 3, 0] expected = [0, 1, 3, 5] self.assertEqual(sort(testcase), expected)
def test_sort3(self): testcase = [5, 1] expected = [1, 5] self.assertEqual(sort(testcase), expected)
def test_sort2(self): testcase = [3, 2] expected = [2, 3] self.assertEqual(sort(testcase), expected)
def test_random_data(self): data = [ random.randint(0,100) for _ in range(0, 50) ] sorted_data = copy.copy(data) sorted_data.sort() insertionsort.sort(data) self.assertEqual(data,sorted_data)