-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new tests for the bubble sort and utils file
- Loading branch information
Showing
8 changed files
with
222 additions
and
88 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,66 @@ | ||
import pytest | ||
from pysorting import bubble_sort | ||
from pysorting import bubble_sort, InvalidElementTypeError, NonUniformTypeError | ||
|
||
|
||
def test_sorted_list(text_data_sorted): | ||
def test_sorted_list(test_data_sorted): | ||
"""Test if a pre-sorted list remains unchanged.""" | ||
expected = [1, 2, 3, 4, 5, 6, 7, 8] | ||
actual = bubble_sort(text_data_sorted) | ||
actual = bubble_sort(test_data_sorted) | ||
|
||
assert isinstance(actual, list) | ||
assert actual == expected | ||
|
||
|
||
def test_reverse_sorted_list(text_data1): | ||
def test_reverse_sorted_list(test_data1): | ||
"""Test if a reverse sorting works properly.""" | ||
expected = [8, 7, 6, 5, 4, 3, 2, 1] | ||
actual = bubble_sort(text_data1, ascending=False) | ||
actual = bubble_sort(test_data1, ascending=False) | ||
|
||
assert isinstance(actual, list) | ||
assert actual == expected | ||
|
||
|
||
def test_unsorted_list(text_data1): | ||
def test_unsorted_list(test_data1): | ||
"""Test if an unsorted list is sorted correctly.""" | ||
expected = [1, 2, 3, 4, 5, 6, 7, 8] | ||
actual = bubble_sort(text_data1) | ||
actual = bubble_sort(test_data1) | ||
|
||
assert isinstance(actual, list) | ||
assert actual == expected | ||
|
||
|
||
def test_single_element_list(text_data_single_element): | ||
def test_single_element_list(test_data_single_element): | ||
"""Test if a single-element list is handled correctly.""" | ||
expected = [5] | ||
actual = bubble_sort(text_data_single_element, ascending=False) | ||
actual = bubble_sort(test_data_single_element, ascending=False) | ||
|
||
assert isinstance(actual, list) | ||
assert len(actual) == 1 | ||
assert actual == expected | ||
|
||
|
||
def test_empty_list(text_data_empty): | ||
def test_empty_list(test_data_empty): | ||
"""Test if an empty list is handled correctly.""" | ||
|
||
actual = bubble_sort(text_data_empty) | ||
actual = bubble_sort(test_data_empty) | ||
|
||
assert isinstance(actual, list) | ||
assert len(actual) == 0 | ||
|
||
|
||
def test_value_error(text_data_error): | ||
def test_type_error(test_data_error2): | ||
"""Test if a TypeError is raised for non-list inputs.""" | ||
with pytest.raises(ValueError): | ||
bubble_sort(text_data_error) | ||
with pytest.raises(TypeError): | ||
bubble_sort(test_data_error2) | ||
|
||
|
||
def test_type_error(text_data_error2): | ||
def test_invalid_type_error(test_invalid_error): | ||
"""Test if a TypeError is raised for non-list inputs.""" | ||
with pytest.raises(TypeError): | ||
bubble_sort(text_data_error2) | ||
with pytest.raises(InvalidElementTypeError): | ||
bubble_sort(test_invalid_error) | ||
|
||
|
||
def test_non_uniform_error(test_nonuniform_error): | ||
"""Test if a TypeError is raised for non-list inputs.""" | ||
with pytest.raises(NonUniformTypeError): | ||
bubble_sort(test_nonuniform_error) |
Oops, something went wrong.