Пример #1
0
def test_original_unchanged():
    """
    Test that sorting leaves the original data unchanged.

    Consider

    data = [3, 2, 1]
    sorted_data = bubble_sort(data)

    Now data shall still contain [3, 2, 1].
    """
    data = [3, 2, 1]
    bubble_sort(data)
    assert data == [3, 2, 1]
    pass
Пример #2
0
def test_integer():
    data = []
    for i in range(1000):  # Testing integers
        data.append(random.randint(1, 1000))

    new_data = bubble_sort(data)

    for index in range(len(new_data) - 1):
        assert new_data[index] <= new_data[index + 1]
Пример #3
0
def test_sorted_is_not_original():
    """
    Test that the sorting function returns a new object.

    Now sorted_data shall be a different object than data,
    not just another name for the same object.
    """
    data = [3, 2, 1]
    assert bubble_sort(data) is not data
Пример #4
0
def test_list_of_strings():
    list_of_strings = ('aaa', 'ii', 'bb', 'qwr')
    assert bubble_sort(list_of_strings) == ['aaa', 'bb', 'ii', 'qwr']
Пример #5
0
def test_single_string():
    string_for_test = 'afdebc'
    assert bubble_sort(string_for_test) == ['a', 'b', 'c', 'd', 'e', 'f']
Пример #6
0
def test_floats():
    data = np.random.random(100)  # Testing floats
    new_data = bubble_sort(data)

    for index in range(len(new_data) - 1):
        assert new_data[index] <= new_data[index + 1]
Пример #7
0
def test_sort_all_equal():
    """Test that sorting handles data with identical elements."""
    assert bubble_sort([1, 5, 3, 2, 3, 4, 1]) == [1, 1, 2, 3, 3, 4, 5]
Пример #8
0
def test_sort_reversed():
    """Test that sorting works on reverse-sorted data."""
    assert bubble_sort([3, 2, 1]) == [1, 2, 3]
Пример #9
0
def test_sort_sorted():
    """Test that sorting works on sorted data."""
    assert bubble_sort([1, 2, 3]) == [1, 2, 3]
Пример #10
0
def test_single():
    """Test that the sorting function works for single-element list"""
    assert bubble_sort([1]) == [1]
Пример #11
0
def test_empty():
    """Test that the sorting function works for empty list"""
    assert bubble_sort([]) == []