Ejemplo n.º 1
0
 def test_random_operator(self):
     operator = self.operator
     random.seed("Tara ra ra ta")
     for _ in xrange(100):
         N = random.randint(2, self.topN)
         M = 2 ** N
         a = Integer(N)
         b = Integer(N)
         c = operator(a, b)
         va = random.randint(0, M - 1)
         vb = random.randint(0, M - 1)
         try:
             vc = operator(va, vb) % M
         except ZeroDivisionError:
             continue
         assign = {}
         assign.update(a.build_assignment(va))
         assign.update(b.build_assignment(vb))
         assign.update(c.build_assignment(vc))
         formula = c.get_propositional_formula()
         self.assertNotEqual(solve(formula, assign), None,
                   "Model is UNSAT for a={} b={} c={}\n".format(va, vb, vc))
         a.make_constant(va)
         b.make_constant(vb)
         c.make_constant(vc)
         formula = c.get_propositional_formula()
         self.assertNotEqual(solve(formula), None)
Ejemplo n.º 2
0
 def test_random_wrong_operator(self):
     operator = self.operator
     random.seed("Tara ra ra ta ta ra ra ra ta")
     N = 5
     M = 2 ** N
     for _ in xrange(10):
         a = Integer(N)
         b = Integer(N)
         c = operator(a, b)
         va = random.randint(0, M - 1)
         vb = random.randint(0, M - 1)
         try:
             correct = operator(va, vb) % M
         except ZeroDivisionError:
             continue
         a.make_constant(va)
         b.make_constant(vb)
 
         for vc in xrange(M):
             if vc == correct:
                 continue
             c.make_constant(vc)
             formula = c.get_propositional_formula()
             model = solve(formula)
             self.assertEqual(model, None,
                     "Model is SAT for a={} b={} c={}\n".format(va, vb, vc))