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}"
def test_generate_list_example_one(self): l = generate_list(4, 6) self.assertEqual(6, calculate_cost(l))
def test_generate_list_example_three(self): self.assertEqual(12, calculate_cost(generate_list(7, 12)))
def test_generate_list_example_two(self): self.assertEqual(2, calculate_cost(generate_list(2, 2)))
def test_reversort_example_2(self): self.assertEqual(1, calculate_cost([1, 2]))
def test_reversort_example_1(self): self.assertEqual(6, calculate_cost([4, 2, 1, 3]))
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))
def test_reversort_example_3(self): self.assertEqual(12, calculate_cost([7, 6, 5, 4, 3, 2, 1]))