@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); }
@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); }
@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}"); }
@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}"); }
@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); }
@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 ) )}"); }
@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); }
@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); }
@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); }
@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()); }
@Test public void testDistributeEmptyList() { Unification result = Unification.distribute(bags); assertTrue(result.isSuccess()); assertEquals(result, expectedResult); }
@Test(expected = IllegalArgumentException.class) public void testDistributeSomeBagsAreNull() { bags.add(new Unification()); bags.add(null); Unification.distribute(bags); }
@Test(expected = IllegalArgumentException.class) public void testDistributeNullList() { Unification.distribute(null); }