示例#1
0
文件: test_qtype.py 项目: cap/cheqed
def test_str():
    assert str(qobj()) == 'obj'
    assert str(qbool()) == 'bool'
    assert str(qfun(qobj(), qbool())) == '(obj->bool)'
    assert str(qfun(qobj(), qbool())) == '(obj->bool)'
    assert (str(qfun(qfun(qobj(), qobj()), qbool()))
            == '((obj->obj)->bool)')
示例#2
0
文件: test_parser.py 项目: cap/cheqed
    def test_parse_typed_variable(self):
        var = self.parser.parse('var:bool')
        assert var.name == 'var'
        assert var.qtype == qbool()

        var = self.parser.parse('var:bool->obj')
        assert var.name == 'var'
        assert var.qtype == qfun(qbool(), qobj())
示例#3
0
文件: test_parser.py 项目: cap/cheqed
    def test_parse_constant_type(self):
        matches = [
            ('bool', qbool()),
            ('(bool)', qbool()),
            ('obj', qobj()),
            ('obj->obj', qfun(qobj(), qobj())),
            ('obj->obj->obj', qfun(qobj(), qfun(qobj(), qobj()))),
            ('(obj->obj)->obj', qfun(qfun(qobj(), qobj()), qobj())),        
            ('obj->bool', qfun(qobj(), qbool())),
            ]

        for string, obj in matches:
            assert self.parser.parse_type(string) == obj
示例#4
0
文件: test_parser.py 项目: cap/cheqed
 def test_parse_operator(self):
     assert (self.parser.parse('not a')
             == term_builder.build_combination(self.not_,
                                qterm.Variable('a', qbool())))
     
     assert (self.parser.parse('a:obj = b:obj')
             == term_builder.build_binary_op(self.equals,
                                qterm.Variable('a', qobj()),
                                qterm.Variable('b', qobj())))
示例#5
0
文件: test_qtype.py 项目: cap/cheqed
def test_unify():
    assert_raises(UnificationError, unify, [qobj(), qbool()])
    assert_equal(unify([qobj(), qobj()]), qobj())
    assert_equal(unify([qvar(), qobj()]), qobj())
    assert_equal(unify([qobj(), qvar()]), qobj())

    v1 = qvar()
    v2 = qvar()
    uni = unify([v1, v2])
    assert_true(uni == v1 or uni == v2)

    f1 = qfun(qobj(), qbool())
    f2 = qfun(qobj(), qobj())
    f3 = qfun(qvar(), qobj())
    f4 = qfun(qvar(), qvar())

    assert_raises(UnificationError, unify, [f1, f2])
    assert_equal(unify([f2, f3]), f2)
    assert_equal(unify([f2, f4]), f2)
    assert_equal(unify([f3, f4]), f3)
示例#6
0
文件: test_parser.py 项目: cap/cheqed
 def setup_class(cls):
     cls.for_all = Constant('for_all', qfun(qfun(qobj(), qbool()), qbool()))
     cls.exists = Constant('exists',  qfun(qfun(qobj(), qbool()), qbool()))
     cls.not_ = Constant('not', qfun(qbool(), qbool()))
     eqvar = qvar()
     cls.equals = Constant('=', qfun(eqvar, qfun(eqvar, qbool())))
     
     extensions = [
         Type(qbool, 'bool'),
         Type(qobj, 'obj'),
         Binder(cls.for_all),
         Binder(cls.exists),
         Operator(cls.not_, 1, 'right', 100),
         Operator(cls.equals, 2, 'left', 200),
         ]
         
     cls.parser = parser.Parser(Syntax(extensions), term_builder)
示例#7
0
文件: test_parser.py 项目: cap/cheqed
 def test_parse_binder(self):
     assert (self.parser.parse('for_all x phi')
             == term_builder.build_binder(self.for_all,
                             qterm.Variable('x', qobj()),
                             qterm.Variable('phi', qbool())))
示例#8
0
文件: test_parser.py 项目: cap/cheqed
 def test_parse_abstraction(self):
     f = qterm.Variable('f', qfun(qbool(), qbool()))
     x = qterm.Variable('x', qbool())
     y = qterm.Variable('y', qbool())