001    package aima.test.utiltest;
002    
003    import java.util.ArrayList;
004    import java.util.List;
005    
006    import junit.framework.TestCase;
007    import aima.util.Util;
008    
009    public class MeanStDevTests extends TestCase {
010            private List<Double> values;
011    
012            @Override
013            public void setUp() {
014                    values = new ArrayList<Double>();
015                    values.add(1.0);
016                    values.add(2.0);
017                    values.add(3.0);
018                    values.add(4.0);
019                    values.add(5.0);
020            }
021    
022            public void testMeanCalculation() {
023                    assertEquals(3.0, Util.calculateMean(values));
024            }
025    
026            public void testStDevCalculation() {
027                    assertEquals(1.5811, Util.calculateStDev(values, 3.0), 0.001);
028            }
029    
030            public void testNormalization() {
031                    List<Double> nrm = Util.normalizeFromMeanAndStdev(values, 3.0, 1.5811);
032                    assertEquals(-1.264, nrm.get(0), 0.001);
033                    assertEquals(-0.632, nrm.get(1), 0.001);
034                    assertEquals(0.0, nrm.get(2), 0.001);
035                    assertEquals(0.632, nrm.get(3), 0.001);
036                    assertEquals(1.264, nrm.get(4), 0.001);
037    
038            }
039    
040            public void testRandomNumberGenrationWhenStartAndEndNumbersAreSame() {
041                    int i = Util.randomNumberBetween(0, 0);
042                    int j = Util.randomNumberBetween(23, 23);
043                    assertEquals(0, i);
044                    assertEquals(23, j);
045            }
046    
047    }