Пример #1
0
    def test_all(self):
        for i in tqdm(range(2, 100)):
            for j in range(1, i - 1):
                with self.assertRaises(ValueError):
                    generate_list(i, j)

            max_cost = int(i * (i + 1) / 2 - 1)
            _test_generate_for_size(i, i - 1, max_cost)

            for j in range(max_cost + 1, 1000):
                with self.assertRaises(ValueError):
                    generate_list(i, j)
Пример #2
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}"
Пример #3
0
 def test_generate_list_example_one(self):
     l = generate_list(4, 6)
     self.assertEqual(6, calculate_cost(l))
Пример #4
0
 def test_min_cost(self):
     for i in range(2, 100):
         expected = [j for j in range(1, i + 1)]
         self.assertEqual(expected, generate_list(i, i - 1))
Пример #5
0
 def test_generate_list_too_high_cost(self):
     for i in range(2, 100):
         with self.assertRaises(ValueError):
             generate_list(size=i, cost=i * (i + 1) / 2)
Пример #6
0
 def test_generate_list_example_three(self):
     self.assertEqual(12, calculate_cost(generate_list(7, 12)))
Пример #7
0
 def test_generate_list_example_two(self):
     self.assertEqual(2, calculate_cost(generate_list(2, 2)))