def test_insertion_sort(self): values = [5, 3, 6] sorteddata = [3, 5, 6] insertion(values) print(values) self.assertListEqual(values, sorteddata)
from insertionsort import insertion import random from time import time import matplotlib.pyplot as plt x, y = [], [] for n in range(2000, 20000, 2000): randomvalues = list(range(n))[::-1] start_time = time() i = insertion(randomvalues) end_time = time() total_time = end_time - start_time x.append(n) y.append(total_time) print(x) print(y) plt.plot(x, y) plt.show()
import time import random from insertionsort import insertion A = [6, 7, 8, 4, 2] print(A) start = time.time() insertion(A) end = time.time() print(A) print("execution time", start - end)