Ejemplo n.º 1
0
  @Test
  public void testDistributeListWithSeveralBagsWithDifferentContents() {
    SubstitutionBag content1 = new SubstitutionBag();
    content1.tryAddSubstitution(variableX, zero);

    Unification tmp1 = new Unification();
    tmp1.add(content1);

    SubstitutionBag content2 = new SubstitutionBag();
    content2.tryAddSubstitution(variableY, zero);

    Unification tmp2 = new Unification();
    tmp2.add(content2);

    bags.add(new Unification());
    bags.add(tmp1);
    bags.add(tmp2);

    SubstitutionBag res = new SubstitutionBag();
    expectedResult.add(res);
    res.tryAddSubstitutions(content1);
    res.tryAddSubstitutions(content2);

    Unification result = Unification.distribute(bags);
    assertTrue(result.isSuccess());
    assertEquals(result, expectedResult);
  }
Ejemplo n.º 2
0
 @Test
 public void test6() throws SymbolFormatException, GdlFormatException {
   Substitution s = null;
   Gdl a, b;
   a = GdlFactory.create("(move ?x 1)");
   b = GdlFactory.create("(fact a 1)");
   s = Unification.unify((GdlSentence) a, (GdlSentence) b);
   assertTrue(s == null);
 }
Ejemplo n.º 3
0
 @Test
 public void test3() throws SymbolFormatException, GdlFormatException {
   Substitution s = null;
   Gdl a, b;
   a = GdlFactory.create("(role ?p)");
   b = GdlFactory.create("(role white)");
   s = Unification.unify((GdlSentence) a, (GdlSentence) b);
   assertEquals("test", s.toString(), "{?p=white}");
 }
Ejemplo n.º 4
0
 @Test
 public void test2() throws SymbolFormatException, GdlFormatException {
   Substitution s = null;
   Gdl a, b;
   a = GdlFactory.create("(fact ?x)");
   b = GdlFactory.create("(fact ?y)");
   s = Unification.unify((GdlSentence) a, (GdlSentence) b);
   assertEquals("test", s.toString(), "{?x=?y}");
 }
Ejemplo n.º 5
0
  @Test
  public void testDistributeListWithExclustiveBags() {
    SubstitutionBag content1a = new SubstitutionBag();
    content1a.tryAddSubstitution(variableX, zero);

    SubstitutionBag content1b = new SubstitutionBag();
    content1b.tryAddSubstitution(variableX, one);

    Unification tmp1 = new Unification();
    tmp1.add(content1a);
    tmp1.add(content1b);

    SubstitutionBag content2a = new SubstitutionBag();
    content2a.tryAddSubstitution(variableX, one);

    SubstitutionBag content2b = new SubstitutionBag();
    content2b.tryAddSubstitution(variableY, zero);

    Unification tmp2 = new Unification();
    tmp2.add(content2a);
    tmp2.add(content2b);

    bags.add(tmp1);
    bags.add(tmp2);

    SubstitutionBag res1 = new SubstitutionBag();
    expectedResult.add(res1);
    res1.tryAddSubstitution(variableX, zero);
    res1.tryAddSubstitution(variableY, zero);

    SubstitutionBag res2 = new SubstitutionBag();
    expectedResult.add(res2);
    res2.tryAddSubstitution(variableX, one);

    SubstitutionBag res3 = new SubstitutionBag();
    expectedResult.add(res3);
    res3.tryAddSubstitution(variableX, one);
    res3.tryAddSubstitution(variableY, zero);

    Unification result = Unification.distribute(bags);
    assertTrue(result.isSuccess());
    assertEquals(result, expectedResult);
  }
Ejemplo n.º 6
0
 @Test
 public void test4() throws SymbolFormatException, GdlFormatException {
   Substitution s = null;
   Gdl a, b;
   a = GdlFactory.create("(f1 ?x 3 ?y)");
   b = GdlFactory.create("(f1 (f2 ?y (f3 ?z (f4 (f5 ?y 42) 1 ?z) 7)) ?z a)");
   s = Unification.unify((GdlSentence) a, (GdlSentence) b);
   assertEquals(
       "test", s.toString(), "{?z=3, ?y=a, ?x=( f2 a ( f3 3 ( f4 ( f5 a 42 ) 1 3 ) 7 ) )}");
 }
Ejemplo n.º 7
0
  @Test
  public void testDistributeListWithSeveralSetsWithDifferentMultiplicity() {
    SubstitutionBag content1a = new SubstitutionBag();
    content1a.tryAddSubstitution(variableX, zero);

    Unification content = new Unification();
    content.add(content1a);

    SubstitutionBag content2a = new SubstitutionBag();
    content2a.tryAddSubstitution(variableY, zero);

    SubstitutionBag content2b = new SubstitutionBag();
    content2b.tryAddSubstitution(variableY, one);

    Unification content2 = new Unification();
    content2.add(content2a);
    content2.add(content2b);

    bags.add(new Unification());
    bags.add(content);
    bags.add(content2);

    SubstitutionBag res1 = new SubstitutionBag();
    expectedResult.add(res1);
    res1.tryAddSubstitutions(content1a);
    res1.tryAddSubstitution(variableY, zero);

    SubstitutionBag res2 = new SubstitutionBag();
    expectedResult.add(res2);
    res2.tryAddSubstitutions(content1a);
    res2.tryAddSubstitution(variableY, one);

    Unification result = Unification.distribute(bags);
    assertTrue(result.isSuccess());
    assertEquals(result, expectedResult);
  }
Ejemplo n.º 8
0
  @Test
  public void testDistributeListWithOneBag() {
    SubstitutionBag content = new SubstitutionBag();
    content.tryAddSubstitution(variableX, zero);

    Unification tmp = new Unification();
    tmp.add(content);
    bags.add(tmp);

    expectedResult.add(content);

    Unification result = Unification.distribute(bags);
    assertTrue(result.isSuccess());
    assertEquals(result, expectedResult);
  }
Ejemplo n.º 9
0
  @Test
  public void testDistributeListWithSeveralEmptyBags() {
    Unification tmp = new Unification();
    tmp.add(new SubstitutionBag());
    tmp.add(new SubstitutionBag());

    bags.add(new Unification());
    bags.add(tmp);
    bags.add(new Unification());

    expectedResult.add(new SubstitutionBag());
    Unification result = Unification.distribute(bags);
    assertTrue(result.isSuccess());
    assertEquals(result, expectedResult);
  }
Ejemplo n.º 10
0
  @Test
  public void testDistributeListWithExclusiveSets() {
    SubstitutionBag content1 = new SubstitutionBag();
    content1.tryAddSubstitution(variableX, zero);

    Unification tmp1 = new Unification();
    tmp1.add(content1);

    SubstitutionBag content2 = new SubstitutionBag();
    content2.tryAddSubstitution(variableX, one);

    Unification tmp2 = new Unification();
    tmp2.add(content2);

    bags.add(new Unification());
    bags.add(tmp1);
    bags.add(tmp2);

    Unification result = Unification.distribute(bags);
    assertFalse(result.isSuccess());
  }
Ejemplo n.º 11
0
 @Test
 public void testDistributeEmptyList() {
   Unification result = Unification.distribute(bags);
   assertTrue(result.isSuccess());
   assertEquals(result, expectedResult);
 }
Ejemplo n.º 12
0
 @Test(expected = IllegalArgumentException.class)
 public void testDistributeSomeBagsAreNull() {
   bags.add(new Unification());
   bags.add(null);
   Unification.distribute(bags);
 }
Ejemplo n.º 13
0
 @Test(expected = IllegalArgumentException.class)
 public void testDistributeNullList() {
   Unification.distribute(null);
 }