From 8ef9b97a36fd5bcda7c07feb93be03c19b457f80 Mon Sep 17 00:00:00 2001 From: Gert-Ludwig Ingold Date: Tue, 27 Aug 2024 16:59:22 +0200 Subject: [PATCH 1/3] empty list returned without sorting --- src/listwiz/sorting.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/listwiz/sorting.py b/src/listwiz/sorting.py index 0d379f8..b7a77a3 100644 --- a/src/listwiz/sorting.py +++ b/src/listwiz/sorting.py @@ -21,7 +21,7 @@ def merge_sort(l): sorted_list """ # If there is a single item, the list is already sorted, return. - if len(l) == 1: + if 0 <= len(l) <= 1: return l split = len(l) // 2 @@ -53,4 +53,4 @@ def bubble_sort(l): def selection_sort(l): # We should provide selection sort. - raise NotImplementedError \ No newline at end of file + raise NotImplementedError From b8ecb63f032d61bb33e85aa570a9f2bc3fd9727b Mon Sep 17 00:00:00 2001 From: Gert-Ludwig Ingold Date: Tue, 27 Aug 2024 17:14:38 +0200 Subject: [PATCH 2/3] comparison with 0 removed --- src/listwiz/sorting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/listwiz/sorting.py b/src/listwiz/sorting.py index b7a77a3..2b5349d 100644 --- a/src/listwiz/sorting.py +++ b/src/listwiz/sorting.py @@ -21,7 +21,7 @@ def merge_sort(l): sorted_list """ # If there is a single item, the list is already sorted, return. - if 0 <= len(l) <= 1: + if len(l) <= 1: return l split = len(l) // 2 From 54e832d607e903acd7e069432004bd88733d34d5 Mon Sep 17 00:00:00 2001 From: Gert-Ludwig Ingold Date: Tue, 27 Aug 2024 17:25:33 +0200 Subject: [PATCH 3/3] added test for sorting an empty list --- tests/test_sorting.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/test_sorting.py b/tests/test_sorting.py index f7d41d1..a19d517 100644 --- a/tests/test_sorting.py +++ b/tests/test_sorting.py @@ -16,9 +16,10 @@ def test_mergesort(): def test_mergesort_empty(): - # Stub for a test with empty lists, see issue #8 - pass - + # Test with empty list: + l = [] + res = lws.merge_sort(l) + assert res == [] def test_bubble_sort(): # Stub for basic bubble sort tests, see issue #9