001    package aima.test.probreasoningtest;
002    
003    import java.util.Arrays;
004    import java.util.List;
005    
006    import junit.framework.TestCase;
007    import aima.probability.RandomVariable;
008    import aima.probability.reasoning.HmmConstants;
009    
010    /**
011     * @author Ravi Mohan
012     * 
013     */
014    public class RandomVariableTest extends TestCase {
015    
016            private RandomVariable aDistribution;
017    
018            @Override
019            public void setUp() {
020                    List<String> states = Arrays.asList(new String[] {
021                                    HmmConstants.DOOR_OPEN, HmmConstants.DOOR_CLOSED });
022                    aDistribution = new RandomVariable("HiddenState", states);
023            }
024    
025            public void testSettingValuesOnInvalidStateThrowsException() {
026                    try {
027                            aDistribution.setProbabilityOf("invalid", 0.5);
028                            fail("exception not thrown on invalid state being set");
029                    } catch (RuntimeException e) {
030    
031                    }
032            }
033    
034            public void testGettingValuesOnInvalidStateThrowsException() {
035                    try {
036                            double d = aDistribution.getProbabilityOf("invalid");
037                            fail("exception not thrown on trying to get probability value of invalid state ");
038                    } catch (RuntimeException e) {
039    
040                    }
041            }
042    }