Esempio n. 1
0
 def test(self):
     self.assertEqual(remove_smallest([1, 2, 3, 4, 5]), [2, 3, 4, 5],
                      "Wrong result for [1, 2, 3, 4, 5]")
     self.assertEqual(remove_smallest([1, 2, 3, 4]), [2, 3, 4],
                      "Wrong result for [1, 2, 3, 4]")
     self.assertEqual(remove_smallest([5, 3, 2, 1, 4]), [5, 3, 2, 4],
                      "Wrong result for [5, 3, 2, 1, 4]")
     self.assertEqual(remove_smallest([1, 2, 3, 1, 1]), [2, 3, 1, 1],
                      "Wrong result for [1, 2, 3, 1, 1]")
     self.assertEqual(remove_smallest([]), [], "Wrong result for []")
Esempio n. 2
0
 def test_remove_smallest(self):
     self.assertEqual(remove_smallest([1, 2, 3, 4, 5]), [2, 3, 4, 5])
     self.assertEqual(remove_smallest([5, 3, 2, 1, 4]), [5, 3, 2, 4])
     self.assertEqual(remove_smallest([2, 2, 1, 2, 1]), [2, 2, 2, 1])
     self.assertEqual(remove_smallest([3, 1, 6, 7, 3, 7, 6]), [3, 6, 7, 3, 7, 6])
     self.assertEqual(remove_smallest([4, 4, 4, 1]), [4, 4, 4])
     self.assertEqual(remove_smallest([5, 4, 5, 3, 1, 1]), [5, 4, 5, 3, 1])
     self.assertEqual(remove_smallest([1, 5, 3]), [5, 3])
     self.assertEqual(remove_smallest([]), [])
     self.assertEqual(remove_smallest([6, 2, 5, 4, 8, 6, 3, 2, 7]), [6, 5, 4, 8, 6, 3, 2, 7])
     self.assertEqual(remove_smallest([3]), [])
Esempio n. 3
0
    def test_rand(self):
        from numpy.random import randint
        from random import choice

        def randlist():
            return list(randint(400, size=randint(1, 10)))

        def solution(numbers):
            if not numbers: return numbers

            numbers = numbers[:]
            numbers.remove(min(numbers))
            return numbers

        for _ in range(10):
            x = randint(1, 400)
            self.assertEqual(remove_smallest([x]), [],
                             "Wrong result for [{}]".format(x))

        for _ in range(10):
            arr = randlist()
            if randint(0, 1): arr[randint(0, len(arr) - 1)] = min(arr)
            self.assertEqual(len(remove_smallest(arr[:])),
                             len(arr) - 1,
                             "Wrong sized result for {}".format(arr))

        a = randlist()  # generates the list
        b = list(a)  # makes a swallow copy
        remove_smallest(a)  # uses the original list with the function
        self.assertEqual(a, b,
                         "You've mutated input list")  # test the list match

        for _ in range(20):
            arr = randlist()
            self.assertEqual(remove_smallest(arr[:]), solution(arr),
                             "Wrong result for {}".format(arr))
def test_simple_ones():
    assert remove_smallest([1, 2, 3, 4, 5]) == [2, 3, 4, 5]
    assert remove_smallest([1, 2, 3, 4]) == [2, 3, 4]
    assert remove_smallest([5, 3, 2, 1, 4]) == [5, 3, 2, 4]
    assert remove_smallest([1, 2, 3, 1, 1]) == [2, 3, 1, 1]
    assert remove_smallest([]) == []
def test_returns_list_that_misses_only_one_element():
    for i in range(10):
        arr = randlist()
        assert len(remove_smallest(arr[:])) == len(arr) - 1
def test_returns_empty_list_if_only_one_element():
    for i in range(10):
        x = randint(1, 400)
        assert remove_smallest([x]) == []