1 41 42 package org.jfree.data.statistics.junit; 43 44 import java.util.ArrayList ; 45 import java.util.List ; 46 47 import junit.framework.Test; 48 import junit.framework.TestCase; 49 import junit.framework.TestSuite; 50 51 import org.jfree.data.statistics.BoxAndWhiskerCalculator; 52 53 56 public class BoxAndWhiskerCalculatorTests extends TestCase { 57 58 63 public static Test suite() { 64 return new TestSuite(BoxAndWhiskerCalculatorTests.class); 65 } 66 67 72 public BoxAndWhiskerCalculatorTests(String name) { 73 super(name); 74 } 75 76 private static final double EPSILON = 0.000000001; 77 78 81 public void testCalculateQ1() { 82 List values = new ArrayList (); 83 double q1 = BoxAndWhiskerCalculator.calculateQ1(values); 84 assertTrue(Double.isNaN(q1)); 85 values.add(new Double (1.0)); 86 q1 = BoxAndWhiskerCalculator.calculateQ1(values); 87 assertEquals(q1, 1.0, EPSILON); 88 values.add(new Double (2.0)); 89 q1 = BoxAndWhiskerCalculator.calculateQ1(values); 90 assertEquals(q1, 1.0, EPSILON); 91 values.add(new Double (3.0)); 92 q1 = BoxAndWhiskerCalculator.calculateQ1(values); 93 assertEquals(q1, 1.5, EPSILON); 94 values.add(new Double (4.0)); 95 q1 = BoxAndWhiskerCalculator.calculateQ1(values); 96 assertEquals(q1, 1.5, EPSILON); 97 } 98 99 102 public void testCalculateQ3() { 103 List values = new ArrayList (); 104 double q3 = BoxAndWhiskerCalculator.calculateQ3(values); 105 assertTrue(Double.isNaN(q3)); 106 values.add(new Double (1.0)); 107 q3 = BoxAndWhiskerCalculator.calculateQ3(values); 108 assertEquals(q3, 1.0, EPSILON); 109 values.add(new Double (2.0)); 110 q3 = BoxAndWhiskerCalculator.calculateQ3(values); 111 assertEquals(q3, 2.0, EPSILON); 112 values.add(new Double (3.0)); 113 q3 = BoxAndWhiskerCalculator.calculateQ3(values); 114 assertEquals(q3, 2.5, EPSILON); 115 values.add(new Double (4.0)); 116 q3 = BoxAndWhiskerCalculator.calculateQ3(values); 117 assertEquals(q3, 3.5, EPSILON); 118 } 119 } 120 | Popular Tags |