Beispiel #1
0
    def test_sort_on_lists_of_random_integers_with_duplicates(self):
        # Generate list of 20 random integers from range [1...10]
        items1 = random_ints(20, 1, 10)
        sorted_items1 = sorted(items1)  # Create a copy of list in sorted order
        sort(items1)  # Call mutative sort function to sort list items in place
        assert items1 == sorted_items1

        # Generate list of 50 random integers from range [1...20]
        items2 = random_ints(50, 1, 20)
        sorted_items2 = sorted(items2)  # Copy
        sort(items2)  # Mutate
        assert items2 == sorted_items2

        # Generate list of 100 random integers from range [1...30]
        items3 = random_ints(100, 1, 30)
        sorted_items3 = sorted(items3)  # Copy
        sort(items3)  # Mutate
        assert items3 == sorted_items3
Beispiel #2
0
def test_sort_on_lists_of_random_integers():
    # Generate list of 10 random integers from range [1...20]
    items1 = random_ints(10, 1, 20)
    sorted_items1 = sorted(items1)  # Create a copy of list in sorted order
    sort(items1)  # Call mutative sort function to sort list items in place
    assert items1 == sorted_items1

    # Generate list of 20 random integers from range [1...50]
    items2 = random_ints(20, 1, 50)
    sorted_items2 = sorted(items2)  # Copy
    sort(items2)  # Mutate
    assert items2 == sorted_items2

    # Generate list of 30 random integers from range [1...100]
    items3 = random_ints(30, 1, 100)
    sorted_items3 = sorted(items3)  # Copy
    sort(items3)  # Mutate
    assert items3 == sorted_items3
Beispiel #3
0
 def test_sort_with_reverse_true(self):
     # this allows me to check if sort has a 'reverse' argument
     arguments = getfullargspec(sort).args
     if 'reverse' not in arguments:
         return
     items = random_ints(50, 1, 20)
     reverse_sorted_items = sorted(items, reverse=True)
     sort(items, reverse=True)
     assert items == reverse_sorted_items
Beispiel #4
0
    def test_sort_on_lists_of_random_integers(self):
        # Generate list of 10 random integers from range [1...20]
        items1 = random_ints(10, 1, 20)
        sorted_items1 = sorted(items1)  # Create a copy of list in sorted order
        sort(items1)  # Call mutative sort function to sort list items in place
        assert items1 == sorted_items1

        # Generate list of 20 random integers from range [1...50]
        items2 = random_ints(20, 1, 50)
        sorted_items2 = sorted(items2)  # Copy
        sort(items2)  # Mutate
        assert items2 == sorted_items2

        # Generate list of 30 random integers from range [1...100]
        items3 = random_ints(30, 1, 100)
        sorted_items3 = sorted(items3)  # Copy
        sort(items3)  # Mutate
        assert items3 == sorted_items3

        # Check descending monotonic
        items6 = list(reversed(range(10000)))
        sort(items6)
        assert items6 == list(range(10000))
Beispiel #5
0
    def test_sort_on_lists_of_random_integers(self):
        # Generate list of 10 random integers from range [1...20]
        items1 = random_ints(10, 1, 20)
        sorted_items1 = sorted(items1)  # Create a copy of list in sorted order
        sort(items1)  # Call mutative sort function to sort list items in place
        assert items1 == sorted_items1
        for _ in range(10):
            items5 = random.sample(range(1, 100), 10)
            new = sort(items5)
            items5.sort()
            assert new == items5

        # Generate list of 20 random integers from range [1...50]
        items2 = random_ints(20, 1, 50)
        sorted_items2 = sorted(items2)  # Copy
        sort(items2)  # Mutate
        assert items2 == sorted_items2

        # Generate list of 30 random integers from range [1...100]
        items3 = random_ints(30, 1, 100)
        sorted_items3 = sorted(items3)  # Copy
        sort(items3)  # Mutate
        assert items3 == sorted_items3