예제 #1
0
파일: Types.py 프로젝트: c00w/PrologPlus
def test_hasVariables():
    import Parser
    pred = "A(X,a,b,c)"
    predf = "A(a,d,e)"
    pred = Parser._parse_pred(pred)
    predf = Parser._parse_pred(predf)
    assert pred.hasVariables() == True
    assert predf.hasVariables() == False
예제 #2
0
파일: Search.py 프로젝트: c00w/PrologPlus
def test_search():
    import Parser
    source = "A(a):."
    CE = Parser._parse(source)
    assert search(CE, Parser._parse_pred('A(a)')) == True
    
    source = "A(X):."
    CE = Parser._parse(source)
    assert search(CE, Parser._parse_pred('A(a)')) == True
예제 #3
0
파일: Search.py 프로젝트: c00w/PrologPlus
def test_search_unknown_not_true():
    import Parser
    source = "A(X):B(X).\n A(c):."
    Pred = Parser._parse_pred('A(a)')
    CE = Parser._parse(source)
    assert search(CE, Pred) == 'Unknown'
    
    source = "A(a):B(X).\n A(c):."
    Pred = Parser._parse_pred('A(a)')
    CE = Parser._parse(source)
    assert search(CE, Pred) == 'Unknown'
예제 #4
0
파일: Search.py 프로젝트: c00w/PrologPlus
def test_search_and_unify():
    import Parser
    source = "A(a):B(X),C(X).\nB(c):.\nC(d):."
    Pred = Parser._parse_pred('A(a)')
    CE = Parser._parse(source)
    assert search(CE, Pred) is not True
    assert search(CE, Pred) is not False
    assert search(CE, Pred) == 'Unknown'
    
    source = "A(a):B(X),C(X).\nB(c):.\nC(c):."
    Pred = Parser._parse_pred('A(a)')
    CE = Parser._parse(source)
    assert search(CE, Pred) is True
예제 #5
0
파일: Types.py 프로젝트: c00w/PrologPlus
def test_unify():
    import Parser
    source = "A(X):."
    CE = Parser._parse(source)
    for state in CE:
        mapping = state.determines(Parser._parse_pred('A(a)'))
        assert len(mapping) > 0
        for item in mapping:
            assert state.unify(item) != state
예제 #6
0
파일: Search.py 프로젝트: c00w/PrologPlus
def test_search_compl_neg():
    import Parser
    source = "A(X):!B(b).\n!B(b):."
    Pred = Parser._parse_pred('A(a)')
    b = Parser._parse_pred('!B(b)')
    CE = Parser._parse(source)
    
    assert search(CE, b) == True
    
    count_det = 0
    for state in CE:
        if state.determines(Pred) is not None:
            count_det += 1
            mapping = state.determines(Pred)
            new_state = state.unify(mapping[0])
    assert count_det == 1
    assert new_state.true(CE) == True
    
    assert search(CE, Pred) == True
예제 #7
0
 def default(self, line):
     if len(line) == 0:
         return
         
     if line[-1] == '?':
         print Search.search(self.CE, Parser._parse_pred(line[:-1]))
         return
         
     try:
         self.CE.update(Parser._parse(line))
         print 'Accepted'
     except:
         print traceback.format_exc()
예제 #8
0
파일: Search.py 프로젝트: c00w/PrologPlus
def test_search_chaining_sub():
    import Parser
    source = "A(a):.\nB(X):A(X).\nC(X),D(X):A(X)."
    
    CE = Parser._parse(source)
    
    count_det = 0
    for state in CE:
        if state.determines(Parser._parse_pred('C(a)')) is not None:
            count_det += 1
            mapping = state.determines(Parser._parse_pred('C(a)'))
            new_state = state.unify(mapping[0])
            #print mapping
            #print new_state
    
    assert search(CE, Parser._parse_pred('B(a)')) == True
    assert search(CE, Parser._parse_pred('!B(a)')) == False
    assert search(CE, Parser._parse_pred('C(a)')) == True
    assert search(CE, Parser._parse_pred('!C(a)')) == False
    assert search(CE, Parser._parse_pred('C(b)')) == 'Unknown'
    assert search(CE, Parser._parse_pred('!C(b)')) == 'Unknown'
예제 #9
0
파일: Search.py 프로젝트: c00w/PrologPlus
def test_recurse():
    import Parser
    source = "A(a):A(a)."
    CE = Parser._parse(source)
    assert search(CE, Parser._parse_pred('A(a)')) == 'Unknown'
예제 #10
0
파일: Types.py 프로젝트: c00w/PrologPlus
def test_determines():
    import Parser
    source = "A(a):."
    CE = Parser._parse(source)
    for state in CE:
        assert state.determines(Parser._parse_pred('A(a)')) == [{}]