1 18 package org.apache.commons.math.stat.descriptive; 19 20 import junit.framework.Test; 21 import junit.framework.TestCase; 22 import junit.framework.TestSuite; 23 24 import org.apache.commons.math.stat.descriptive.moment.Mean; 25 26 31 public class AbstractUnivariateStatisticTest extends TestCase { 32 33 public AbstractUnivariateStatisticTest(String name) { 34 super(name); 35 } 36 37 public static Test suite() { 38 TestSuite suite = new TestSuite(AbstractUnivariateStatisticTest.class); 39 suite.setName("AbstractUnivariateStatistic Tests"); 40 return suite; 41 } 42 43 protected double[] testArray = {0, 1, 2, 3, 4, 5}; 44 protected double[] nullArray = null; 45 protected double[] singletonArray = {0}; 46 protected Mean testStatistic = new Mean(); 47 48 public void testTestPositive() { 49 for (int j = 0; j < 6; j++) { 50 for (int i = 1; i < (7 - j); i++) { 51 assertTrue(testStatistic.test(testArray, 0, i)); 52 } 53 } 54 assertTrue(testStatistic.test(singletonArray, 0, 1)); 55 } 56 57 public void testTestNegative() { 58 assertFalse(testStatistic.test(singletonArray, 0, 0)); 59 assertFalse(testStatistic.test(testArray, 0, 0)); 60 try { 61 testStatistic.test(singletonArray, 2, 1); fail("Expecting IllegalArgumentException"); 63 } catch (IllegalArgumentException ex) { 64 } 66 try { 67 testStatistic.test(testArray, 0, 7); fail("Expecting IllegalArgumentException"); 69 } catch (IllegalArgumentException ex) { 70 } 72 try { 73 testStatistic.test(testArray, -1, 1); fail("Expecting IllegalArgumentException"); 75 } catch (IllegalArgumentException ex) { 76 } 78 try { 79 testStatistic.test(testArray, 0, -1); fail("Expecting IllegalArgumentException"); 81 } catch (IllegalArgumentException ex) { 82 } 84 try { 85 testStatistic.test(nullArray, 0, 1); fail("Expecting IllegalArgumentException"); 87 } catch (IllegalArgumentException ex) { 88 } 90 } 91 } 92 | Popular Tags |