001    package aima.test.probabilitytest;
002    
003    import aima.probability.BayesNetNode;
004    import junit.framework.TestCase;
005    
006    /**
007     * @author Ravi Mohan
008     * 
009     */
010    
011    public class BayesNetNodeTest extends TestCase {
012            private BayesNetNode a, b, c, d, e;
013    
014            @Override
015            public void setUp() {
016                    a = new BayesNetNode("A");
017                    b = new BayesNetNode("B");
018                    c = new BayesNetNode("C");
019                    d = new BayesNetNode("D");
020                    e = new BayesNetNode("E");
021    
022                    c.influencedBy(a, b);
023                    d.influencedBy(c);
024                    e.influencedBy(c);
025            }
026    
027            public void testInfluenceSemantics() {
028                    assertEquals(1, a.getChildren().size());
029                    assertTrue(a.getChildren().contains(c));
030                    assertEquals(0, a.getParents().size());
031    
032                    assertEquals(1, b.getChildren().size());
033                    assertTrue(b.getChildren().contains(c));
034                    assertEquals(0, b.getParents().size());
035    
036                    assertEquals(2, c.getChildren().size());
037                    assertTrue(c.getChildren().contains(d));
038                    assertTrue(c.getChildren().contains(e));
039                    assertEquals(2, c.getParents().size());
040                    assertTrue(c.getParents().contains(a));
041                    assertTrue(c.getParents().contains(b));
042    
043                    assertEquals(0, d.getChildren().size());
044                    assertEquals(1, d.getParents().size());
045                    assertTrue(d.getParents().contains(c));
046    
047                    assertEquals(0, e.getChildren().size());
048                    assertEquals(1, e.getParents().size());
049                    assertTrue(e.getParents().contains(c));
050            }
051    
052    }