未验证 提交 20efad4b 编写于 作者: C Cleber Rosa

Merge remote-tracking branch 'richtja/cit_bug'

Signed-off-by: NCleber Rosa <crosa@redhat.com>
......@@ -101,6 +101,7 @@ class Cit:
while self.combination_matrix.total_uncovered != 0:
LOG.debug(self.__throbber.render(), extra={"skip_newline": True})
solution, row_index, _ = self.use_random_algorithm(matrix)
if len(solution) != 0:
self.combination_matrix.uncover_solution_row(matrix[row_index])
self.combination_matrix.cover_solution_row(solution)
matrix[row_index] = solution
......@@ -197,8 +198,6 @@ class Cit:
self.combination_matrix.cover_combination(matrix[row_index], parameters)
if best_uncover == 0:
break
if len(best_solution) == 0:
return self.change_one_column(matrix)
return best_solution, best_row_index, parameters
def get_missing_combination_random(self):
......@@ -229,7 +228,10 @@ class Cit:
best_solution = []
best_row_index = 0
for row_index in range(len(matrix)):
try:
solution, row_index, parameters = self.change_one_value(matrix, row_index, column_index)
except ValueError:
continue
self.combination_matrix.uncover_combination(matrix[row_index], parameters)
self.combination_matrix.cover_combination(solution, parameters)
if self.combination_matrix.total_uncovered < best_uncover:
......@@ -251,10 +253,13 @@ class Cit:
:param column_index: column inside matrix. If it's None it is chosen randomly
:return: solution, index of solution inside matrix and parameters which has been changed
"""
is_cell_chosen = True
if row_index is None:
is_cell_chosen = False
row_index = random.randint(0, len(matrix) - 1)
row = [x for x in matrix[row_index]]
if column_index is None:
is_cell_chosen = False
column_index = random.randint(0, len(row) - 1)
possible_numbers = list(range(0, row[column_index])) + list(
range(row[column_index] + 1, self.data[column_index]))
......@@ -262,6 +267,8 @@ class Cit:
while not self.combination_matrix.is_valid_combination(row, [column_index]):
possible_numbers.remove(row[column_index])
if len(possible_numbers) == 0:
if is_cell_chosen:
raise ValueError("Selected cell can't be changed")
column_index = random.randint(0, len(row) - 1)
row_index = random.randint(0, len(matrix) - 1)
row = [x for x in matrix[row_index]]
......
......@@ -71,13 +71,23 @@ class CitTests(unittest.TestCase):
final_matrix = self.cit.final_matrix_init()
expected_row_index = 2
expected_column_index = 0
function_state = True
row, row_index, column_index = (None, None, None)
try:
row, row_index, column_index = self.cit.change_one_value(final_matrix, row_index=expected_row_index,
column_index=expected_column_index)
except ValueError:
function_state = False
if function_state:
self.assertEqual(expected_column_index, column_index[0], "Column index is wrong")
self.assertEqual(expected_row_index, row_index, "Row index is wrong")
self.assertNotEqual(final_matrix[row_index][column_index[0]], row[column_index[0]], "Value did not change")
row[column_index[0]] = final_matrix[row_index][column_index[0]]
self.assertEqual(final_matrix[row_index], row, "Different value was changed")
else:
self.assertIsNone(row)
self.assertIsNone(row_index)
self.assertIsNone(column_index)
def test_change_one_column(self):
final_matrix = self.cit.final_matrix_init()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册