@Test
 public void testParseMultiArityFunction() {
   parser.setUpToParse("LegsOf(John,Saladin,Richard)");
   Term f = parser.parseFunction();
   Assert.assertEquals(f, getLegsOfFunction());
   Assert.assertEquals(3, ((Function) f).getTerms().size());
 }
 @Test
 public void testNotSentence() {
   NotSentence ns = (NotSentence) parser.parse("NOT BrotherOf(John) = EnemyOf(Saladin)");
   Assert.assertEquals(
       ns.getNegated(),
       new TermEquality(getBrotherOfFunction(new Constant("John")), getEnemyOfFunction()));
 }
 @Test
 public void testQuantifiedSentenceWithSingleVariable() {
   Sentence qs = parser.parse("FORALL x  King(x)");
   List<Variable> vars = new ArrayList<Variable>();
   vars.add(new Variable("x"));
   Assert.assertEquals(
       qs, new QuantifiedSentence("FORALL", vars, getKingPredicate(new Variable("x"))));
 }
 @Test
 public void testParseComplexParanthizedSentence() {
   Sentence ps = parser.parse("(NOT BrotherOf(John) = EnemyOf(Saladin))");
   Assert.assertEquals(
       ps,
       new NotSentence(
           new TermEquality(getBrotherOfFunction(new Constant("John")), getEnemyOfFunction())));
 }
 @Test
 public void testTermEquality2() {
   try {
     TermEquality te = (TermEquality) parser.parse("BrotherOf(John) = x)");
     Assert.assertEquals(
         te, new TermEquality(getBrotherOfFunction(new Constant("John")), new Variable("x")));
   } catch (RuntimeException e) {
     Assert.fail("RuntimeException thrown");
   }
 }
  @Test
  public void testParseSimpleConnectedSentence() {
    Sentence ps = parser.parse("(King(John) AND NOT King(Richard))");

    Assert.assertEquals(
        ps,
        new ConnectedSentence(
            "AND",
            getKingPredicate(new Constant("John")),
            new NotSentence(getKingPredicate(new Constant("Richard")))));

    ps = parser.parse("(King(John) AND King(Saladin))");
    Assert.assertEquals(
        ps,
        new ConnectedSentence(
            "AND",
            getKingPredicate(new Constant("John")),
            getKingPredicate(new Constant("Saladin"))));
  }
 @Test
 public void testQuantifiedSentenceWithPathologicalParanthising() {
   Sentence qs = parser.parse("(( (EXISTS x,y  (King(x) AND (BrotherOf(x) = y)) ) ))");
   List<Variable> vars = new ArrayList<Variable>();
   vars.add(new Variable("x"));
   vars.add(new Variable("y"));
   ConnectedSentence cse =
       new ConnectedSentence(
           "AND",
           getKingPredicate(new Variable("x")),
           new TermEquality(getBrotherOfFunction(new Variable("x")), new Variable("y")));
   Assert.assertEquals(qs, new QuantifiedSentence("EXISTS", vars, cse));
 }
 @Test
 public void testPredicate() {
   // parser.setUpToParse("King(John)");
   Predicate p = (Predicate) parser.parse("King(John)");
   Assert.assertEquals(p, getKingPredicate(new Constant("John")));
 }
 @Test
 public void testParseFunction() {
   parser.setUpToParse("BrotherOf(John)");
   Term f = parser.parseFunction();
   Assert.assertEquals(f, getBrotherOfFunction(new Constant("John")));
 }
Exemplo n.º 10
0
 @Test
 public void testParseSimpleConstant() {
   parser.setUpToParse("John");
   Term c = parser.parseConstant();
   Assert.assertEquals(c, new Constant("John"));
 }
Exemplo n.º 11
0
 @Test(expected = RuntimeException.class)
 public void testNotAllowedParseLeadingIndexedVariable() {
   parser.setUpToParse("1x");
   parser.parseVariable();
 }
Exemplo n.º 12
0
 @Test
 public void testParseIndexedVariable() {
   parser.setUpToParse("x1");
   Term v = parser.parseVariable();
   Assert.assertEquals(v, new Variable("x1"));
 }
Exemplo n.º 13
0
 @Test
 public void testConnectedImplication() {
   parser = new FOLParser(DomainFactory.weaponsDomain());
   parser.parse("((Missile(m) AND Owns(Nono,m)) => Sells(West , m ,Nono))");
 }
Exemplo n.º 14
0
 @Test
 public void testExtraParanthizedSentence() {
   Sentence ps = parser.parse("(((NOT King(John))))");
   Assert.assertEquals(ps, new NotSentence(getKingPredicate(new Constant("John"))));
 }