Beispiel #1
0
def _test_generate_for_size(size, min_cost, max_cost):
    for cost in range(min_cost, max_cost + 1):
        l = generate_list(size, cost)
        assert size == len(l)
        assert cost == calculate_cost(l)

        expected = set(list(range(1, size + 1)))
        actual = set(l)
        assert actual == expected, f"{expected} \n {actual}"
Beispiel #2
0
 def test_generate_list_example_one(self):
     l = generate_list(4, 6)
     self.assertEqual(6, calculate_cost(l))
Beispiel #3
0
 def test_generate_list_example_three(self):
     self.assertEqual(12, calculate_cost(generate_list(7, 12)))
Beispiel #4
0
 def test_generate_list_example_two(self):
     self.assertEqual(2, calculate_cost(generate_list(2, 2)))
Beispiel #5
0
 def test_reversort_example_2(self):
     self.assertEqual(1, calculate_cost([1, 2]))
Beispiel #6
0
 def test_reversort_example_1(self):
     self.assertEqual(6, calculate_cost([4, 2, 1, 3]))
Beispiel #7
0
    def test_reversort_random_sorted_is_zero(self):
        random.seed(0)

        for i in range(2, 100):
            xs = list(range(1, i))
            self.assertEqual(len(xs) - 1, calculate_cost(xs))
Beispiel #8
0
 def test_reversort_example_3(self):
     self.assertEqual(12, calculate_cost([7, 6, 5, 4, 3, 2, 1]))