Skip to content

Commit

Permalink
Fixed unit tests if user code throws an AssertionError with no message.
Browse files Browse the repository at this point in the history
 Please enter the commit message for your changes. Lines starting
  • Loading branch information
Foxite authored and tijmenjoppe committed May 20, 2022
1 parent e94c432 commit 0eca072
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 24 deletions.
9 changes: 7 additions & 2 deletions bonusvraag_vier_kwadraten_student.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,10 @@ def test_vier_kwadraten_tijd():
print(f"Totale tijd: {delta_time*1000:.0f}ms")

except AssertionError as ae:
print("\x1b[31m")
print(ae)
print("\x1b[31m") # Rode tekstkleur
if not ae:
print("Je code veroorzaakt onderstaande AssertionError:")
raise ae
else:
print(ae)
print("\x1b[0m") # Reset tekstkleur
9 changes: 7 additions & 2 deletions faculteit_student.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,10 @@ def test_faculteit_iteratief():
print(f"{getal}! = {faculteit_iteratief(getal)}")

except AssertionError as ae:
print("\x1b[31m")
print(ae)
print("\x1b[31m") # Rode tekstkleur
if not ae:
print("Je code veroorzaakt onderstaande AssertionError:")
raise ae
else:
print(ae)
print("\x1b[0m") # Reset tekstkleur
10 changes: 8 additions & 2 deletions insertion_sort_student.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def insertion_sort(lst):
Returns:
list: Een nieuwe, gesorteerde variant van lijst `lst`.
"""
# Kopieer de lijst, zodat de originele lijst niet verandert
return


Expand Down Expand Up @@ -107,5 +108,10 @@ def test_insertion_sort():
print(f"is na sortering met jouw algoritme: \n\t{gesorteerde_lijst}")

except AssertionError as ae:
print("\x1b[31m")
print(str(ae))
print("\x1b[31m") # Rode tekstkleur
if not ae:
print("Je code veroorzaakt onderstaande AssertionError:")
raise ae
else:
print(ae)
print("\x1b[0m") # Reset tekstkleur
7 changes: 5 additions & 2 deletions practicum_1_getallen_student.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,13 @@ def __main():
print("\nGefeliciteerd, alles lijkt te werken!")
print("Lever je werk nu in op Canvas...")


except AssertionError as ae:
print("\x1b[31m") # Rode tekstkleur
print(ae)
if not ae:
print("Je code veroorzaakt onderstaande AssertionError:")
raise ae
else:
print(ae)

print("\x1b[0m") # Reset tekstkleur

Expand Down
6 changes: 5 additions & 1 deletion practicum_2_algoritmiek_student.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,11 @@ def __main():

except AssertionError as ae:
print("\x1b[31m") # Rode tekstkleur
print(ae)
if not ae:
print("Je code veroorzaakt onderstaande AssertionError:")
raise ae
else:
print(ae)

print("\x1b[0m") # Reset tekstkleur

Expand Down
6 changes: 5 additions & 1 deletion practicum_3_statistiek_student.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,11 @@ def hist(freqs):

except AssertionError as ae:
print("\x1b[31m") # Rode tekstkleur
print(ae)
if not ae:
print("Je code veroorzaakt onderstaande AssertionError:")
raise ae
else:
print(ae)

print("\x1b[0m") # Reset tekstkleur

Expand Down
6 changes: 5 additions & 1 deletion practicum_4_herkansing_student.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,11 @@ def __main():

except AssertionError as ae:
print("\x1b[31m") # Rode tekstkleur
print(ae)
if not ae:
print("Je code veroorzaakt onderstaande AssertionError:")
raise ae
else:
print(ae)

print("\x1b[0m") # Reset tekstkleur

Expand Down
9 changes: 7 additions & 2 deletions recursie_student.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,10 @@ def test_palindroom():
print(f"'{x}' is {'' if palindroom(x) else 'g'}een palindroom!")

except AssertionError as ae:
print("\x1b[31m")
print(ae)
print("\x1b[31m") # Rode tekstkleur
if not ae:
print("Je code veroorzaakt onderstaande AssertionError:")
raise ae
else:
print(ae)
print("\x1b[0m") # Reset tekstkleur
21 changes: 13 additions & 8 deletions search_student.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ def binary_search(lst, target):
Returns:
bool: Of het gezochte element voorkomt in de lijst.
"""
# stap 1
# Stap 1.
mini = 0

# stap 6(!)
# Stap 6. (!)
while False: # hoelang ga je door met zoeken?
# stap 2
# stap 3
# Stap 2.
# Stap 3.
return True
# stap 4
# stap 5
# Stap 4.
# Stap 5.

return False

Expand Down Expand Up @@ -222,5 +222,10 @@ def test_binary_search_index_steps():
print(f"Het binair zoekalgoritme vond '{tgt}' op index '{idx}' na {cnt} stappen.")

except AssertionError as ae:
print("\x1b[31m")
print(ae)
print("\x1b[31m") # Rode tekstkleur
if not ae:
print("Je code veroorzaakt onderstaande AssertionError:")
raise ae
else:
print(ae)
print("\x1b[0m") # Reset tekstkleur
11 changes: 8 additions & 3 deletions selection_sort_student.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_selection_sort():
lst_copy = lst_test.copy()
lst_output = selection_sort(lst_test)

assert lst_copy == lst_test, "Fout: my_sort(lst) verandert de inhoud van lijst lst"
assert lst_copy == lst_test, "Fout: selection_sort(lst) verandert de inhoud van lijst lst"
assert lst_output == sorted(lst_test), \
f"Fout: selection_sort({lst_test}) geeft {lst_output} in plaats van {sorted(lst_test)}"

Expand All @@ -116,5 +116,10 @@ def test_selection_sort():
print(f"is na sortering: \n\t{gesorteerde_lijst}")

except AssertionError as ae:
print("\x1b[31m")
print(ae)
print("\x1b[31m") # Rode tekstkleur
if not ae:
print("Je code veroorzaakt onderstaande AssertionError:")
raise ae
else:
print(ae)
print("\x1b[0m") # Reset tekstkleur

0 comments on commit 0eca072

Please sign in to comment.