def all_conditions_failed(CG): """A specific data set that invalidates the criteria""" #A requirement to pass the test is to have X=-1 as initial value T = [{'X': -5}] L = [[1, 2, 4, 5, "exit"], [1, 3, 4, 6, "exit"]] all_conditions(CG, L, T) def generate_data_set(CG): L = [[1, 2, 4, 5, "exit"], [1, 3, 4, 6, "exit"]] for path in L: print(test_generation(CG, path)) if __name__ == "__main__": print("Criteria 1 - all assigned") print("Control Graph is CG_Project_Example") print("\n") CG1 = CG_Project_Example() CG2 = CG_Project_Example() all_conditions_passed(CG1) print("\n") all_conditions_failed(CG2) print("\n") print("Automatic generation of data set that validate the criteria:") generate_data_set(CG1)
P = CSP(variables_domains) # We add to the probelm binary constraint for (x, y), constraints_x_y in constraints.items(): P.addConstraint(x, y, constraints_x_y) # We return the solution of our problem return P.solve() def possible_variables(variables_domains, constraints): """compute the possible values of our variables in a given state and a set of constraints""" result = [] variable_names = list(variables_domains.keys()) for possible_values in product(*(variables_domains.values())): buffer_vars = dict() for i, var in enumerate(variable_names): buffer_vars[var] = possible_values[i] if all((buffer_vars[var1], buffer_vars[var2]) in constraint for (var1, var2), constraint in constraints.items()): result.append(buffer_vars) return result if __name__ == "__main__": CG = CG_Project_Example() print(test_generation(CG, [1, 2, 4, 5, 'exit'])) print(test_generation(CG, [1, 2, 4, 6, 'exit']))