|
|
@ -35,26 +35,28 @@ import random |
|
|
|
|
|
|
|
|
|
|
|
def test_insert(): |
|
|
|
lst_test = [3, 5, 7, 11, 13, 2, 9, 14] |
|
|
|
|
|
|
|
insert(lst_test, 4, 2) |
|
|
|
lst_res = [3, 5, 7, 11, 13, 2, 9, 14] |
|
|
|
lst_test = lst_res.copy() |
|
|
|
insert(lst_res, 4, 2) |
|
|
|
lst_correct = [2, 3, 5, 7, 11, 13, 9, 14] |
|
|
|
assert lst_test == lst_correct, "Fout: insert(lst_test, 4, 2) geeft {} in plaats van {}".format(lst_test, lst_correct) |
|
|
|
assert lst_res == lst_correct, n">f"Fout: insert({lst_test}, 4, 2) geeft {lst_res} in plaats van {lst_correct}" |
|
|
|
|
|
|
|
insert(lst_test, 5, 9) |
|
|
|
lst_test = lst_res.copy() |
|
|
|
insert(lst_res, 5, 9) |
|
|
|
lst_correct = [2, 3, 5, 7, 9, 11, 13, 14] |
|
|
|
assert lst_test == lst_correct, "Fout: insert(lst_test, 5, 9) geeft {} in plaats van {}".format(lst_test, lst_correct) |
|
|
|
assert lst_res == lst_correct, n">f"Fout: insert({lst_test}, 5, 9) geeft {lst_res} in plaats van {lst_correct}" |
|
|
|
|
|
|
|
insert(lst_test, 6, 14) |
|
|
|
lst_test = lst_res.copy() |
|
|
|
insert(lst_res, 6, 14) |
|
|
|
lst_correct = [2, 3, 5, 7, 9, 11, 13, 14] |
|
|
|
assert lst_test == lst_correct, "Fout: insert(lst_test, 6, 14) geeft {} in plaats van {}".format(lst_test, lst_correct) |
|
|
|
assert lst_res == lst_correct, n">f"Fout: insert({lst_test}, 6, 14) geeft {lst_res} in plaats van {lst_correct}" |
|
|
|
|
|
|
|
|
|
|
|
def test_insertion_sort(): |
|
|
|
lst_test = random.sample(range(-99, 100), 6) |
|
|
|
lst_copy = lst_test.copy() |
|
|
|
insertion_sort(lst_test) |
|
|
|
assert lst_test == sorted(lst_copy), sa">"Fout: insertion_sort({}) geeft {} in plaats van {}".format(lst_copy, lst_test, sorted(lst_copy)) |
|
|
|
assert lst_test == sorted(lst_copy), n">f"Fout: insertion_sort({lst_copy}) geeft {lst_test} in plaats van {sorted(lst_copy)}" |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|