assertfaculteit_iteratief(x)==math.factorial(x),"Fout: faculteit_iteratief({}) geeft {} in plaats van {}".format(x,faculteit_iteratief(x),math.factorial(x))
assertlinear_search(lst_test,target)==(targetinlst_test),"e">\x1b[0;31mFout: linear_search({}, {}) geeft {} in plaats van {}".format(lst_test,target,linear_search(lst_test,target),targetinlst_test)
assertlinear_search(lst_test,target)==(targetinlst_test),"Fout: linear_search({}, {}) geeft {} in plaats van {}".format(lst_test,target,linear_search(lst_test,target),targetinlst_test)
deftest_linear_search_index():
foriinrange(10):
lst_test=random.sample(range(20),10)
target=random.choice(lst_test)
assertlinear_search_index(lst_test,target)==lst_test.index(target),"e">\x1b[0;31mFout: linear_search_index({}, {}) geeft {} in plaats van {}".format(lst_test,target,linear_search_index(lst_test,target),lst_test.index(target))
assertlinear_search_index(lst_test,target)==lst_test.index(target),"Fout: linear_search_index({}, {}) geeft {} in plaats van {}".format(lst_test,target,linear_search_index(lst_test,target),lst_test.index(target))
lst_test=[0,1,2]
assertlinear_search_index(lst_test,3)==-1,"e">\x1b[0;31mFout: linear_search_index({}, {}) geeft {} in plaats van {}".format(lst_test,3,linear_search_index(lst_test,3),-1)
assertlinear_search_index(lst_test,3)==-1,"Fout: linear_search_index({}, {}) geeft {} in plaats van {}".format(lst_test,3,linear_search_index(lst_test,3),-1)
deftest_linear_search_index_steps():
foriinrange(10):
lst_test=random.sample(range(20),10)
target=random.choice(lst_test)
assertlinear_search_index_steps(lst_test,target)[0]==lst_test.index(target),"e">\x1b[0;31mFout: linear_search_index_steps({}, {}) geeft {} in plaats van {}".format(lst_test,target,linear_search_index_steps(lst_test,target)[0],lst_test.index(target))
assertlinear_search_index_steps(lst_test,target)[0]==lst_test.index(target),"Fout: linear_search_index_steps({}, {}) geeft {} in plaats van {}".format(lst_test,target,linear_search_index_steps(lst_test,target)[0],lst_test.index(target))
deftest_binary_search():
foriinrange(10):
lst_test=sorted(random.sample(range(20),10))
target=random.randrange(20)
assertbinary_search(lst_test,target)==(targetinlst_test),"e">\x1b[0;31mFout: binary_search({}, {}) geeft {} in plaats van {}".format(lst_test,target,binary_search(lst_test,target),targetinlst_test)
assertbinary_search(lst_test,target)==(targetinlst_test),"Fout: binary_search({}, {}) geeft {} in plaats van {}".format(lst_test,target,binary_search(lst_test,target),targetinlst_test)
deftest_binary_search_index():
foriinrange(10):
lst_test=sorted(random.sample(range(20),10))
target=random.choice(lst_test)
assertbinary_search_index(lst_test,target)==lst_test.index(target),"e">\x1b[0;31mFout: binary_search_index({}, {}) geeft {} in plaats van {}".format(lst_test,target,binary_search_index(lst_test,target),lst_test.index(target))
assertbinary_search_index(lst_test,target)==lst_test.index(target),"Fout: binary_search_index({}, {}) geeft {} in plaats van {}".format(lst_test,target,binary_search_index(lst_test,target),lst_test.index(target))
lst_test=[0,1,2]
assertbinary_search_index(lst_test,3)==-1,"e">\x1b[0;31mFout: binary_search_index({}, {}) geeft {} in plaats van {}".format(lst_test,3,binary_search_index(lst_test,3),-1)
assertbinary_search_index(lst_test,3)==-1,"Fout: binary_search_index({}, {}) geeft {} in plaats van {}".format(lst_test,3,binary_search_index(lst_test,3),-1)
deftest_binary_search_index_steps():
foriinrange(10):
lst_test=sorted(random.sample(range(20),10))
target=random.choice(lst_test)
assertbinary_search_index_steps(lst_test,target)[0]==lst_test.index(target),"e">\x1b[0;31mFout: binary_search_index_steps({}, {}) geeft {} in plaats van {}".format(lst_test,target,binary_search_index_steps(lst_test,target)[0],lst_test.index(target))
assertbinary_search_index_steps(lst_test,target)[0]==lst_test.index(target),"Fout: binary_search_index_steps({}, {}) geeft {} in plaats van {}".format(lst_test,target,binary_search_index_steps(lst_test,target)[0],lst_test.index(target))
assertlst_test==[9,4,7],"e">\x1b[0;31mFout: swap([4, 9, 7], 0, 1) geeft {} in plaats van {}".format(lst_test,[9,4,7])
assertlst_test==[9,4,7],"Fout: swap([4, 9, 7], 0, 1) geeft {} in plaats van {}".format(lst_test,[9,4,7])
lst_test=[4,9,7]
swap(lst_test,1,2)
assertlst_test==[4,7,9],"e">\x1b[0;31mFout: swap([4, 9, 7], 1, 2) geeft {} in plaats van {}".format(lst_test,[4,7,9])
assertlst_test==[4,7,9],"Fout: swap([4, 9, 7], 1, 2) geeft {} in plaats van {}".format(lst_test,[4,7,9])
lst_test=[4,9,7]
swap(lst_test,0,2)
assertlst_test==[7,9,4],"e">\x1b[0;31mFout: swap([4, 9, 7], 0, 2) geeft {} in plaats van {}".format(lst_test,[7,9,4])
assertlst_test==[7,9,4],"Fout: swap([4, 9, 7], 0, 2) geeft {} in plaats van {}".format(lst_test,[7,9,4])
deftest_find_index_of_minimum():
lst_test=[18,6,21,44,9,14]
assertfind_index_of_minimum(lst_test,0)==1,"e">\x1b[0;31mFout: find_index_of_minimum({}, 0) geeft {} in plaats van 1".format(lst_test,find_index_of_minimum(lst_test,0))
assertfind_index_of_minimum(lst_test,2)==4,"e">\x1b[0;31mFout: find_index_of_minimum({}, 2) geeft {} in plaats van 4".format(lst_test,find_index_of_minimum(lst_test,2))
assertfind_index_of_minimum(lst_test,3)==4,"e">\x1b[0;31mFout: find_index_of_minimum({}, 3) geeft {} in plaats van 4".format(lst_test,find_index_of_minimum(lst_test,3))
assertfind_index_of_minimum(lst_test,0)==1,"Fout: find_index_of_minimum({}, 0) geeft {} in plaats van 1".format(lst_test,find_index_of_minimum(lst_test,0))
assertfind_index_of_minimum(lst_test,2)==4,"Fout: find_index_of_minimum({}, 2) geeft {} in plaats van 4".format(lst_test,find_index_of_minimum(lst_test,2))
assertfind_index_of_minimum(lst_test,3)==4,"Fout: find_index_of_minimum({}, 3) geeft {} in plaats van 4".format(lst_test,find_index_of_minimum(lst_test,3))
deftest_selection_sort():
lst_test=random.sample(range(-99,100),6)
lst_copy=lst_test.copy()
selection_sort(lst_test)
assertlst_test==sorted(lst_copy),"e">\x1b[0;31mFout: selection_sort({}) geeft {} in plaats van {}".format(lst_copy,lst_test,sorted(lst_copy))
assertlst_test==sorted(lst_copy),"Fout: selection_sort({}) geeft {} in plaats van {}".format(lst_copy,lst_test,sorted(lst_copy))