Best Python code snippet using avocado_python
Cit.py
Source:Cit.py  
...23        # Combinations which do not match to the constraints are disabled24        self.solver.clean_hash_table(self.combination_matrix, t_value)25        self.final_matrix = []26        self.__throbber = Throbber()27    def final_matrix_init(self):28        """29        Creation of the first solution. This solution is the start of searching30        for the best solution31        :return: solution matrix (list(list))32        """33        self.final_matrix = [self.create_random_row_with_constraints()]34        self.combination_matrix.cover_solution_row(self.final_matrix[0])35        while self.combination_matrix.total_uncovered != 0:36            if self.combination_matrix.total_uncovered < self.combination_matrix.total_covered_more_than_ones:37                new_row = self.compute_row()38            else:39                new_row = self.compute_row_using_hamming_distance()40            self.combination_matrix.cover_solution_row(new_row)41            self.final_matrix.append(new_row)42        return self.final_matrix43    def compute(self):44        """45        Searching for the best solution. It creates one solution and from that,46        it tries to create smaller solution. This searching process is limited47        by ITERATIONS_SIZE. When ITERATIONS_SIZE is 0 the last found solution is48        the best solution.49        :return: The best solution50        """51        self.final_matrix = self.final_matrix_init()52        matrix = [x[:] for x in self.final_matrix]53        iterations = ITERATIONS_SIZE54        step_size = 155        deleted_rows = []56        while step_size != 0:57            for i in range(step_size):58                delete_row = matrix.pop(random.randint(0, len(matrix) - 1))59                self.combination_matrix.uncover_solution_row(delete_row)60                deleted_rows.append(delete_row)61            LOG.debug("I'm trying solution with size %s and %s iterations",62                      len(matrix), iterations)63            matrix, is_better_solution = self.find_better_solution(iterations, matrix)64            if is_better_solution:65                self.final_matrix = matrix[:]...test_cit.py
Source:test_cit.py  
...30        self.cit.final_matrix.append([2, 1, 1, 0])31        row = [2, 0, 3, 2]32        expected_distance = 533        self.assertEqual(expected_distance, self.cit.compute_hamming_distance(row), "Wrong hamming distance")34    def test_final_matrix_init(self):35        combination_matrix = copy(self.cit.combination_matrix)36        final_matrix = self.cit.final_matrix_init()37        expected_total_uncovered = 038        expected_uncovered_rows = {}39        self.assertEqual(expected_total_uncovered, self.cit.combination_matrix.total_uncovered,40                         "Final matrix don't cover all combinations")41        self.assertEqual(expected_uncovered_rows, self.cit.combination_matrix.uncovered_rows,42                         "Final matrix don't cover all combination rows")43        for row in final_matrix:44            combination_matrix.cover_solution_row(row)45        self.assertEqual(expected_total_uncovered, self.cit.combination_matrix.total_uncovered,46                         "Final matrix don't cover all combinations but CIT thinks it does")47        self.assertEqual(expected_uncovered_rows, self.cit.combination_matrix.uncovered_rows,48                         "Final matrix don't cover all combination rows but CIT thinks it does")49    def test_change_one_value_random(self):50        final_matrix = self.cit.final_matrix_init()51        row, row_index, column_index = self.cit.change_one_value(final_matrix)52        self.assertNotEqual(final_matrix[row_index][column_index[0]], row[column_index[0]], "Value did not change")53        row[column_index[0]] = final_matrix[row_index][column_index[0]]54        self.assertEqual(final_matrix[row_index], row, "Different value was changed")55    def test_change_one_value_with_index(self):56        final_matrix = self.cit.final_matrix_init()57        expected_row_index = 258        expected_column_index = 059        function_state = True60        row, row_index, column_index = (None, None, None)61        try:62            row, row_index, column_index = self.cit.change_one_value(final_matrix, row_index=expected_row_index,63                                                                     column_index=expected_column_index)64        except ValueError:65            function_state = False66        if function_state:67            self.assertEqual(expected_column_index, column_index[0], "Column index is wrong")68            self.assertEqual(expected_row_index, row_index, "Row index is wrong")69            self.assertNotEqual(final_matrix[row_index][column_index[0]], row[column_index[0]], "Value did not change")70            row[column_index[0]] = final_matrix[row_index][column_index[0]]71            self.assertEqual(final_matrix[row_index], row, "Different value was changed")72        else:73            self.assertIsNone(row)74            self.assertIsNone(row_index)75            self.assertIsNone(column_index)76    def test_change_one_column(self):77        final_matrix = self.cit.final_matrix_init()78        while self.cit.combination_matrix.total_uncovered == 0:79            delete_row = final_matrix.pop(random.randint(0, len(final_matrix) - 1))80            self.cit.combination_matrix.uncover_solution_row(delete_row)81        expected_total_covered_more_than_ones = self.cit.combination_matrix.total_covered_more_than_ones82        expected_total_uncovered = self.cit.combination_matrix.total_uncovered83        expected_uncovered_rows = copy(self.cit.combination_matrix.uncovered_rows)84        row, row_index, column_index = self.cit.change_one_column(final_matrix)85        self.assertEqual(expected_total_uncovered, self.cit.combination_matrix.total_uncovered, "Coverage was change")86        self.assertEqual(expected_total_covered_more_than_ones,87                         self.cit.combination_matrix.total_covered_more_than_ones,88                         "Coverage was change")89        self.assertEqual(expected_uncovered_rows, self.cit.combination_matrix.uncovered_rows, "Coverage was change")90        self.assertNotEqual(final_matrix[row_index][column_index[0]], row[column_index[0]], "Value did not change")91        row[column_index[0]] = final_matrix[row_index][column_index[0]]92        self.assertEqual(final_matrix[row_index], row, "Different value was changed")93    def test_get_missing_combination_random(self):94        final_matrix = self.cit.final_matrix_init()95        while self.cit.combination_matrix.total_uncovered == 0:96            delete_row = final_matrix.pop(random.randint(0, len(final_matrix) - 1))97            self.cit.combination_matrix.uncover_solution_row(delete_row)98        combination_parameters, combination = self.cit.get_missing_combination_random()99        self.assertEqual(0, self.cit.combination_matrix.hash_table[combination_parameters].hash_table[combination],100                         "Combination is already covered")101    def test_cover_missing_combination(self):102        final_matrix = self.cit.final_matrix_init()103        while self.cit.combination_matrix.total_uncovered == 0:104            delete_row = final_matrix.pop(random.randint(0, len(final_matrix) - 1))105            self.cit.combination_matrix.uncover_solution_row(delete_row)106        expected_total_covered_more_than_ones = self.cit.combination_matrix.total_covered_more_than_ones107        expected_total_uncovered = self.cit.combination_matrix.total_uncovered108        expected_uncovered_rows = copy(self.cit.combination_matrix.uncovered_rows)109        row, row_index, parameters = self.cit.cover_missing_combination(final_matrix)110        self.assertEqual(expected_total_uncovered, self.cit.combination_matrix.total_uncovered, "Coverage was change")111        self.assertEqual(expected_total_covered_more_than_ones,112                         self.cit.combination_matrix.total_covered_more_than_ones,113                         "Coverage was change")114        self.assertEqual(expected_uncovered_rows, self.cit.combination_matrix.uncovered_rows, "Coverage was change")115        self.assertTrue(final_matrix[row_index][parameters[0]] != row[parameters[0]] or116                        final_matrix[row_index][parameters[1]] != row[parameters[1]], "Value did not change")...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
