Best Python code snippet using avocado_python
test_solver.py
Source:test_solver.py  
...12        constraints = {((0, 0), (2, 0)), ((0, 1), (1, 1)), ((1, 0), (2, 0))}13        solver = Solver([], [])14        solver.data = parameters15        solver.constraints = constraints16        solver.read_constraints()17        solver.compute_constraints()18        self.assertEqual(solver.constraints, constraints, "compute_constraints change constraints without secret "19                                                          "constraint")20    def test_compute_constraints_new_constraint_with_more_than_one_value_for_one_parameter(self):21        """22        Test that, function shouldn't change constraints. It founds new constraint,23        but the constraint has one parameter with two values. This means that it isn't secreted constraint.24        """25        parameters = [3, 3, 3]26        constraints = {((0, 0), (1, 0)), ((0, 1), (1, 1)), ((1, 2), (2, 0))}27        solver = Solver([], [])28        solver.data = parameters29        solver.constraints = constraints30        solver.read_constraints()31        solver.compute_constraints()32        self.assertEqual(solver.constraints, constraints, "compute_constraints change constraints without secret "33                                                          "constraint")34    def test_compute_constraints_detect_invalid_constraints(self):35        """36        Test that, function should raise an exception, if there is invalid_constraints37        """38        parameters = [3, 3, 3]39        constraints = {((0, 0),), ((0, 1),), ((0, 2),)}40        solver = Solver([], [])41        solver.data = parameters42        solver.constraints = constraints43        solver.read_constraints()44        self.assertRaises(ValueError, solver.compute_constraints)45    def test_compute_constraints_with_one_secrete_constraint(self):46        """47        Test that, function should find new constraint48        """49        parameters = [3, 3, 3, 3]50        constraints = {((0, 0), (2, 0)), ((0, 1), (1, 1), (2, 0)), ((0, 2), (3, 2))}51        solver = Solver([], [])52        solver.data = parameters53        solver.constraints = constraints54        solver.read_constraints()55        solver.compute_constraints()56        expectation = {((0, 0), (2, 0)), ((0, 1), (1, 1), (2, 0)), ((0, 2), (3, 2)),57                       ((1, 1), (2, 0), (3, 2))}58        self.assertEqual(solver.constraints, expectation, "compute_constraints didn't find secret constraints")59    # Test for simplify_constraints function60    def test_simplify_constraints_constraints_without_simplification(self):61        """62        Test that, function do not delete important constraints63        """64        parameters = [3, 3, 3, 3]65        constraints = {((0, 0), (2, 0)), ((0, 1), (1, 1), (2, 0)), ((0, 2), (3, 2))}66        solver = Solver([], [])67        solver.data = parameters68        solver.constraints = constraints69        solver.read_constraints()70        solver.simplify_constraints()71        self.assertEqual(solver.constraints, constraints, "simplify_constraints deleted some important constraints")72    def test_simplify_constraints_constraints_with_simplification(self):73        """74        Test that, function do not delete important constraints75        """76        parameters = [3, 3, 3, 3]77        constraints = {((0, 0), (2, 0)), ((0, 1), (2, 0), (1, 1)),78                       ((0, 2), (2, 0)), ((2, 0),)}79        solver = Solver([], [])80        solver.data = parameters81        solver.constraints = constraints82        solver.read_constraints()83        solver.simplify_constraints()84        expectation = {((2, 0),)}85        self.assertEqual(solver.constraints, expectation, "simplify_constraints deleted some important constraints")86    # Test of Minimum forbidden tuple algorithm87    def test_solver_without_secrete_constraints(self):88        """89        Test that, solver didn't change constraints if there isn't any secret constraint90        """91        parameters = [3, 3, 3]92        constraints = {((0, 0), (2, 0)), ((0, 1), (1, 1)), ((1, 0), (2, 0))}93        solver = Solver(parameters, constraints)94        self.assertEqual(solver.constraints, constraints, "solver change constraints without secret "95                                                          "constraint")96    def test_solver_constraints_without_simplification(self):...universes-smt.py
Source:universes-smt.py  
1#!/usr/bin/python2import sys3def read_constraints(file):4    lines = file.readlines()5    nodes = set()6    edges = set()7    last = None8    for ln in lines:9        ln = ln.replace(';', '')10        parts = ln.split()11        if len(parts) == 3:12            last = parts[0]13        elif len(parts) == 2:14            parts = [last, parts[0], parts[1]]15        else:16            assert False17            18        st = parts[0].strip()19        en = parts[2].strip()20        nodes.add(st)21        nodes.add(en)22        edges.add((st,en,parts[1].strip()))23    return (nodes, edges)24def dump_smt(nodes, edges, out=sys.stdout):25    def name_of(n):26        return n.replace('.', '_')27    for n in nodes:28        out.write("(define %s::int)\n" % name_of(n))29    out.write("\n")30    for (st, en, op) in edges:31        out.write("(assert (%s %s %s))\n" % (op, name_of(st), name_of(en)))32        33    out.write("(exit)\n")34if __name__ == '__main__':35    (nodes, edges) = read_constraints(sys.stdin)...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!!
