コード例 #1
0
  public void testConjunctionVariable() {
    PrologEngine engine = setupConjunction();

    Variable variableX = new Variable("X");
    Variable variableY = new Variable("Y");
    Variable variableZ = new Variable("Z");

    Predicate question = new Predicate("three", 3, variableX, variableY, variableZ);
    Result answer = engine.askQuestion(question);
    assertTrue(answer.hasAnswer());
    assertEquals(new Constant("one"), variableX.getBinding());
    assertEquals(new Constant("two"), variableY.getBinding());
    assertEquals(new Constant("two"), variableZ.getBinding());
    answer.next();
    assertFalse(answer.hasAnswer());
  }
コード例 #2
0
  public void testDisjunctionVariable() {
    PrologEngine engine = setupDisjunction();

    Variable variableY = new Variable("Y");
    Result result3 = engine.askQuestion(new Predicate("hello", 1, variableY));

    assertTrue(result3.hasAnswer());
    assertEquals(new Constant("world"), variableY.getBinding());

    result3.next();
    assertTrue(result3.hasAnswer());
    assertEquals(new Constant("mars"), variableY.getBinding());

    result3.next();
    assertTrue(result3.hasAnswer());
    assertEquals(new Constant("venus"), variableY.getBinding());
  }
コード例 #3
0
  public void testConjunctionBacktrackingVariable() {
    PrologEngine engine = setupConjunctionBacktracking();

    Variable variableX = new Variable("X");

    Predicate question = new Predicate("suitable", 1, variableX);
    Result answer = engine.askQuestion(question);
    assertTrue(answer.hasAnswer());
    assertEquals(new Constant("Eric"), variableX.getBinding());
    answer.next();
    assertFalse("Only one answer expected", answer.hasAnswer());
  }