From 0eca07289eb5eebefd5fe471c2be766004c8a88b Mon Sep 17 00:00:00 2001 From: Dirk Kok Date: Fri, 20 May 2022 16:51:26 +0200 Subject: [PATCH] Fixed unit tests if user code throws an AssertionError with no message. Please enter the commit message for your changes. Lines starting --- bonusvraag_vier_kwadraten_student.py | 9 +++++++-- faculteit_student.py | 9 +++++++-- insertion_sort_student.py | 10 ++++++++-- practicum_1_getallen_student.py | 7 +++++-- practicum_2_algoritmiek_student.py | 6 +++++- practicum_3_statistiek_student.py | 6 +++++- practicum_4_herkansing_student.py | 6 +++++- recursie_student.py | 9 +++++++-- search_student.py | 21 +++++++++++++-------- selection_sort_student.py | 11 ++++++++--- 10 files changed, 70 insertions(+), 24 deletions(-) diff --git a/bonusvraag_vier_kwadraten_student.py b/bonusvraag_vier_kwadraten_student.py index 2c35c74..c1db387 100644 --- a/bonusvraag_vier_kwadraten_student.py +++ b/bonusvraag_vier_kwadraten_student.py @@ -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 diff --git a/faculteit_student.py b/faculteit_student.py index aba0faa..97fbbe8 100644 --- a/faculteit_student.py +++ b/faculteit_student.py @@ -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 diff --git a/insertion_sort_student.py b/insertion_sort_student.py index 6c33070..4ff2b5e 100644 --- a/insertion_sort_student.py +++ b/insertion_sort_student.py @@ -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 @@ -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 diff --git a/practicum_1_getallen_student.py b/practicum_1_getallen_student.py index d929a77..3410cee 100644 --- a/practicum_1_getallen_student.py +++ b/practicum_1_getallen_student.py @@ -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 diff --git a/practicum_2_algoritmiek_student.py b/practicum_2_algoritmiek_student.py index 4bb8cbe..05f8b54 100644 --- a/practicum_2_algoritmiek_student.py +++ b/practicum_2_algoritmiek_student.py @@ -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 diff --git a/practicum_3_statistiek_student.py b/practicum_3_statistiek_student.py index dc590b5..a3bdde7 100644 --- a/practicum_3_statistiek_student.py +++ b/practicum_3_statistiek_student.py @@ -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 diff --git a/practicum_4_herkansing_student.py b/practicum_4_herkansing_student.py index 5ba8d55..2fca2fa 100644 --- a/practicum_4_herkansing_student.py +++ b/practicum_4_herkansing_student.py @@ -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 diff --git a/recursie_student.py b/recursie_student.py index 6e797a4..63ec8dd 100644 --- a/recursie_student.py +++ b/recursie_student.py @@ -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 diff --git a/search_student.py b/search_student.py index 8079ce7..e7e5d19 100644 --- a/search_student.py +++ b/search_student.py @@ -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 @@ -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 diff --git a/selection_sort_student.py b/selection_sort_student.py index 47357e5..2573851 100644 --- a/selection_sort_student.py +++ b/selection_sort_student.py @@ -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)}" @@ -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