def test_symbolic_bool(self):
     # Arrange
     name = 'TestVar1'
     vsort = z3.BoolSort()
     value = True
     # Act
     var = SMTVar(name, vsort)
     var_before = var.var
     get_var_before = var.get_var()
     with self.assertRaises(RuntimeError):
         self.assertEquals(var.get_value(), value)
     # Concertize the value
     solver = z3.Solver()
     solver.add(var.var == value)
     self.assertEquals(solver.check(), z3.sat)
     model = solver.model()
     var.eval(model)
     # Assert
     self.assertEquals(var.name, name)
     self.assertEquals(var.vsort, vsort)
     self.assertTrue(is_symbolic(var_before))
     self.assertTrue(is_symbolic(get_var_before))
     self.assertEquals(var.name, name)
     self.assertEquals(var.vsort, vsort)
     self.assertEquals(var.var, value)
     self.assertEquals(var.get_value(), value)
     self.assertTrue(is_symbolic(var.get_var()))
    def test_symbolic_enum(self):
        # Arrange
        values = ['A', 'B', 'C']
        sort_name = 'TestType'
        name = 'TestVar1'
        value = 'A'
        z3_ctx = z3.Context()
        vsort = EnumType(sort_name, values, z3_ctx=z3_ctx)
        # Act
        var = SMTVar(name, vsort)
        # Assert
        self.assertEquals(var.name, name)
        self.assertEquals(var.vsort, vsort)
        self.assertTrue(is_symbolic(var.var))
        self.assertTrue(is_symbolic(var.get_var()))
        with self.assertRaises(RuntimeError):
            self.assertEquals(var.get_value(), 10)

        # Concertize the value
        solver = z3.Solver(ctx=z3_ctx)
        solver.add(var.var == vsort.get_symbolic_value(value))
        self.assertEquals(solver.check(), z3.sat)
        model = solver.model()
        var.eval(model)
        self.assertEquals(var.name, name)
        self.assertEquals(var.vsort, vsort)
        self.assertEquals(var.var, vsort.get_symbolic_value(value))
        self.assertEquals(var.get_value(), value)
        self.assertTrue(is_symbolic(var.get_var()))
 def test_concrete_int(self):
     # Arrange
     name = 'TestVar1'
     value = 10
     vsort = z3.IntSort()
     # Act
     var = SMTVar(name, vsort, value)
     # Assert
     self.assertEquals(var.name, name)
     self.assertEquals(var.vsort, vsort)
     self.assertEquals(var.var, value)
     self.assertEquals(var.get_value(), value)
     self.assertTrue(is_symbolic(var.get_var()))
 def test_concrete_enum(self):
     # Arrange
     values = ['A', 'B', 'C']
     sort_name = 'TestType'
     name = 'TestVar1'
     value = 'A'
     z3_ctx = z3.Context()
     vsort = EnumType(sort_name, values, z3_ctx=z3_ctx)
     # Act
     var = SMTVar(name, vsort, value)
     # Assert
     self.assertEquals(var.name, name)
     self.assertEquals(var.vsort, vsort)
     self.assertEquals(var.var, vsort.get_symbolic_value(value))
     self.assertEquals(var.get_value(), value)
     self.assertTrue(is_symbolic(var.get_var()))
 def test_create(self):
     # Arrange
     values = ['A', 'B', 'C']
     name = 'TestType'
     # Act
     z3_ctx = z3.Context()
     enum_type = EnumType(name, values, z3_ctx=z3_ctx)
     # Assert
     self.assertEquals(enum_type.name, name)
     self.assertEquals(enum_type.concrete_values, values)
     self.assertEquals(len(enum_type.symbolic_values), len(values))
     for value in values:
         symb = enum_type.get_symbolic_value(value)
         self.assertEquals(str(symb), value)
         self.assertTrue(is_symbolic(symb))
         concrete = enum_type.get_concrete_value(symb)
         self.assertEquals(concrete, value)
     with self.assertRaises(ValueError):
         enum_type.get_symbolic_value('D')
     with self.assertRaises(Exception):
         enum_type.get_concrete_value('D')
 def test_check_eq_int(self):
     # Arrange
     name1 = 'TestVar1'
     value1 = 10
     name2 = 'TestVar2'
     value2 = 15
     name3 = 'TestVar3'
     value3 = 10
     name4 = 'TestVar4'
     vsort = z3.IntSort()
     var1 = SMTVar(name1, vsort, value1)
     var2 = SMTVar(name2, vsort, value2)
     var3 = SMTVar(name3, vsort, value3)
     var4 = SMTVar(name4, vsort)
     # Act
     eq1 = var1.check_eq(var1)
     eq2 = var1.check_eq(var2)
     eq3 = var1.check_eq(var3)
     eq4 = var1.check_eq(var4)
     # Assert
     self.assertTrue(eq1)
     self.assertFalse(eq2)
     self.assertTrue(eq3)
     self.assertTrue(is_symbolic(eq4))