KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > data > statistics > junit > BoxAndWhiskerCalculatorTests


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jfreechart/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * ---------------------------------
27  * BoxAndWhiskerCalculatorTests.java
28  * ---------------------------------
29  * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): -;
33  *
34  * $Id: BoxAndWhiskerCalculatorTests.java,v 1.4 2005/03/29 12:56:53 mungady Exp $
35  *
36  * Changes
37  * -------
38  * 28-Aug-2003 : Version 1 (DG);
39  *
40  */

41
42 package org.jfree.data.statistics.junit;
43
44 import java.util.ArrayList JavaDoc;
45 import java.util.List JavaDoc;
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 /**
54  * Tests for the {@link BoxAndWhiskerCalculator} class.
55  */

56 public class BoxAndWhiskerCalculatorTests extends TestCase {
57
58     /**
59      * Returns the tests as a test suite.
60      *
61      * @return The test suite.
62      */

63     public static Test suite() {
64         return new TestSuite(BoxAndWhiskerCalculatorTests.class);
65     }
66
67     /**
68      * Constructs a new set of tests.
69      *
70      * @param name the name of the tests.
71      */

72     public BoxAndWhiskerCalculatorTests(String JavaDoc name) {
73         super(name);
74     }
75     
76     private static final double EPSILON = 0.000000001;
77     
78     /**
79      * Tests the Q1 calculation.
80      */

81     public void testCalculateQ1() {
82         List JavaDoc values = new ArrayList JavaDoc();
83         double q1 = BoxAndWhiskerCalculator.calculateQ1(values);
84         assertTrue(Double.isNaN(q1));
85         values.add(new Double JavaDoc(1.0));
86         q1 = BoxAndWhiskerCalculator.calculateQ1(values);
87         assertEquals(q1, 1.0, EPSILON);
88         values.add(new Double JavaDoc(2.0));
89         q1 = BoxAndWhiskerCalculator.calculateQ1(values);
90         assertEquals(q1, 1.0, EPSILON);
91         values.add(new Double JavaDoc(3.0));
92         q1 = BoxAndWhiskerCalculator.calculateQ1(values);
93         assertEquals(q1, 1.5, EPSILON);
94         values.add(new Double JavaDoc(4.0));
95         q1 = BoxAndWhiskerCalculator.calculateQ1(values);
96         assertEquals(q1, 1.5, EPSILON);
97     }
98
99     /**
100      * Tests the Q3 calculation.
101      */

102     public void testCalculateQ3() {
103         List JavaDoc values = new ArrayList JavaDoc();
104         double q3 = BoxAndWhiskerCalculator.calculateQ3(values);
105         assertTrue(Double.isNaN(q3));
106         values.add(new Double JavaDoc(1.0));
107         q3 = BoxAndWhiskerCalculator.calculateQ3(values);
108         assertEquals(q3, 1.0, EPSILON);
109         values.add(new Double JavaDoc(2.0));
110         q3 = BoxAndWhiskerCalculator.calculateQ3(values);
111         assertEquals(q3, 2.0, EPSILON);
112         values.add(new Double JavaDoc(3.0));
113         q3 = BoxAndWhiskerCalculator.calculateQ3(values);
114         assertEquals(q3, 2.5, EPSILON);
115         values.add(new Double JavaDoc(4.0));
116         q3 = BoxAndWhiskerCalculator.calculateQ3(values);
117         assertEquals(q3, 3.5, EPSILON);
118     }
119 }
120
Popular Tags