Beispiel #1
0
    def test_complicated_array_assignment(self):
        tst_ast = AssignExp(ArrExp(VarNode("x"), NumNode(0)), ArrExp(VarNode("x"), NumNode(3)))
        q = ag.BinExp(ag.ArrExp(ag.VarNode("x"), ag.NumNode(0)), '<', ag.NumNode(10))

        self.assertEqual("(x{0:=x[3]}[0] < 10)", ag.tree_to_str(WeakestPrecondition(tst_ast, q, []).get()))

        tst_ast = AssignExp(ArrExp(VarNode("x"), VarNode("i")), ArrExp(VarNode("x"), NumNode(3)))
        q = ag.BinExp(ag.ArrExp(ag.VarNode("x"), ag.NumNode(0)), '<', ag.NumNode(10))

        self.assertEqual("(x{i:=x[3]}[0] < 10)", ag.tree_to_str(WeakestPrecondition(tst_ast, q, []).get()))

        tst_ast = AssignExp(ArrExp(VarNode("x"), VarNode("i")), ArrExp(VarNode("y"), VarNode("i")))
        q = ag.BinExp(ag.ArrExp(ag.VarNode("x"), ag.NumNode(0)), '<', ag.NumNode(10))

        self.assertEqual("(x{i:=y[i]}[0] < 10)", ag.tree_to_str(WeakestPrecondition(tst_ast, q, []).get()))
Beispiel #2
0
    def test_loop(self):
        print "in test_loop."
        tst_ast = Block([AssignExp(VarNode("i"), NumNode(1)),
                        WhileLoop(VarNode("i"), BinExp(VarNode("i"), '<', NumNode(3)),
                                  Block([AssignExp(ArrExp(VarNode("a"), VarNode("i")), 
                                                   ArrExp(VarNode("a"), BinExp(VarNode("i"), '+', NumNode(1)))),
                                         AssignExp(VarNode("i"), BinExp(VarNode("i"), '+', NumNode(1)))]))])
        #print tree_to_str(tst_ast)
        q = ag.CallExp(ag.VarNode("postcondition"), [ag.VarNode("a")])

        precon = WeakestPrecondition(tst_ast, q, [])

        print "HMMM:", precon.additional_conditions
        print "====="
        print ag.tree_to_str(precon.get_with_additional_conditions())
        print "====="
Beispiel #3
0
 def test_conditional(self):
     tst_ast = IfExp(BinExp(VarNode("i"), '<', NumNode(1)),
                     Block([AssignExp(VarNode("i"), NumNode(3))]),
                     Block([NumNode(1)]))
     q = ag.BinExp(ag.VarNode("i"), '<', ag.NumNode(10))
     wp = WeakestPrecondition(tst_ast, q, [])
     allcond = ag.tree_to_str(wp.get_with_additional_conditions())
     print "COND", allcond
     self.assertEqual("((!((i < 1))) -> ((i < 10)) && ((i < 1)) -> ((3 < 10)))", allcond)
Beispiel #4
0
 def test_conditional_in_loop(self):
     tst_ast = Block([AssignExp(VarNode("i"), NumNode(1)),
                    WhileLoop(VarNode("i"), BinExp(VarNode("i"), '<', NumNode(3)),
                              Block([IfExp(BinExp(VarNode("i"), '<', NumNode(2)),
                                           Block([AssignExp(ArrExp(VarNode("a"), VarNode("i")), 
                                           ArrExp(VarNode("b"), BinExp(VarNode("i"), '+', NumNode(1))))]),
                                           Block([AssignExp(ArrExp(VarNode("a"), VarNode("i")), 
                                           ArrExp(VarNode("b"), BinExp(VarNode("i"), '-', NumNode(1))))])),
                                     AssignExp(VarNode("i"), BinExp(VarNode("i"), '+', NumNode(1)))]))])
     q = ag.BinExp(ag.VarNode("i"), '<', ag.NumNode(10))
     wp = WeakestPrecondition(tst_ast, q, [])
     allcond = ag.tree_to_str(wp.get_with_additional_conditions())
     print tree_to_str(tst_ast)
     print "BIGCOND", allcond
Beispiel #5
0
    def test_block(self):
        tst_ast = Block(body=[AssignExp(VarNode("i"), NumNode(3)),
                              VarNode("i")])
        q = ag.BinExp(ag.VarNode("i"), '<', ag.NumNode(10))

        self.assertEqual("(3 < 10)", ag.tree_to_str(WeakestPrecondition(tst_ast, q, []).get()))
Beispiel #6
0
 def test_sequence_array_assignment(self):
     tst_ast = Block([AssignExp(ArrExp(VarNode("x"), NumNode(0)), NumNode(3)),
                      AssignExp(ArrExp(VarNode("y"), VarNode("i")), ArrExp(VarNode("x"), NumNode(0)))])
     q = ag.BinExp(ag.ArrExp(ag.VarNode("y"), ag.NumNode(0)), '<', ag.NumNode(10))
     self.assertEqual("(y{i:=x{0:=3}[0]}[0] < 10)", ag.tree_to_str(WeakestPrecondition(tst_ast, q, []).get()))
Beispiel #7
0
    def test_array_assignment(self):
        tst_ast = AssignExp(ArrExp(VarNode("i"), NumNode(0)), NumNode(3))
        q = ag.BinExp(ag.ArrExp(ag.VarNode("i"), ag.NumNode(0)), '<', ag.NumNode(10))

        self.assertEqual("(i{0:=3}[0] < 10)", ag.tree_to_str(WeakestPrecondition(tst_ast, q, []).get()))