Example #1
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);
  }
Example #2
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());
  }
Example #3
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);
  }
Example #4
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);
  }
Example #5
0
  @Test
  public void testDistributeListWithSeveralSetsWithDifferentMultiplicity2() {
    SubstitutionBag content1a = new SubstitutionBag();
    content1a.tryAddSubstitution(variableX, zero);
    SubstitutionBag content1b = new SubstitutionBag();
    content1b.tryAddSubstitution(variableX, one);

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

    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);

    Unification tmp = new Unification();
    tmp.add(new SubstitutionBag());
    tmp.add(new SubstitutionBag());
    tmp.add(new SubstitutionBag());

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

    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, zero);
    res2.tryAddSubstitution(variableY, one);

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

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

    Unification result = Unification.distribute(bags);
    assertTrue(result.isSuccess());
    assertEquals(result, expectedResult);
  }