KickJava   Java API By Example, From Geeks To Geeks.

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


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
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * ---------------------------------------------
28  * DefaultBoxAndWhiskerCategoryDatasetTests.java
29  * ---------------------------------------------
30  * (C) Copyright 2004, 2005, by Object Refinery Limited and Contributors.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: DefaultBoxAndWhiskerCategoryDatasetTests.java,v 1.1.2.1 2006/10/03 15:41:42 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 01-Mar-2004 : Version 1 (DG);
40  *
41  */

42
43 package org.jfree.data.statistics.junit;
44
45 import java.io.ByteArrayInputStream JavaDoc;
46 import java.io.ByteArrayOutputStream JavaDoc;
47 import java.io.ObjectInput JavaDoc;
48 import java.io.ObjectInputStream JavaDoc;
49 import java.io.ObjectOutput JavaDoc;
50 import java.io.ObjectOutputStream JavaDoc;
51 import java.util.ArrayList JavaDoc;
52
53 import junit.framework.Test;
54 import junit.framework.TestCase;
55 import junit.framework.TestSuite;
56
57 import org.jfree.data.statistics.BoxAndWhiskerItem;
58 import org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset;
59
60 /**
61  * Tests for the {@link DefaultBoxAndWhiskerCategoryDataset} class.
62  */

63 public class DefaultBoxAndWhiskerCategoryDatasetTests extends TestCase {
64
65     /**
66      * Returns the tests as a test suite.
67      *
68      * @return The test suite.
69      */

70     public static Test suite() {
71         return new TestSuite(DefaultBoxAndWhiskerCategoryDatasetTests.class);
72     }
73
74     /**
75      * Constructs a new set of tests.
76      *
77      * @param name the name of the tests.
78      */

79     public DefaultBoxAndWhiskerCategoryDatasetTests(String JavaDoc name) {
80         super(name);
81     }
82
83     /**
84      * Confirm that the equals method can distinguish all the required fields.
85      */

86     public void testEquals() {
87         
88         DefaultBoxAndWhiskerCategoryDataset d1
89             = new DefaultBoxAndWhiskerCategoryDataset();
90         d1.add(
91             new BoxAndWhiskerItem(
92                 new Double JavaDoc(1.0), new Double JavaDoc(2.0), new Double JavaDoc(3.0),
93                 new Double JavaDoc(4.0),
94                 new Double JavaDoc(5.0), new Double JavaDoc(6.0), new Double JavaDoc(7.0),
95                 new Double JavaDoc(8.0),
96                 new ArrayList JavaDoc()
97             ), "ROW1", "COLUMN1"
98         );
99         DefaultBoxAndWhiskerCategoryDataset d2
100             = new DefaultBoxAndWhiskerCategoryDataset();
101         d2.add(
102             new BoxAndWhiskerItem(
103                 new Double JavaDoc(1.0), new Double JavaDoc(2.0), new Double JavaDoc(3.0),
104                 new Double JavaDoc(4.0),
105                 new Double JavaDoc(5.0), new Double JavaDoc(6.0), new Double JavaDoc(7.0),
106                 new Double JavaDoc(8.0),
107                 new ArrayList JavaDoc()
108             ), "ROW1", "COLUMN1"
109         );
110         assertTrue(d1.equals(d2));
111         assertTrue(d2.equals(d1));
112
113     }
114
115     /**
116      * Serialize an instance, restore it, and check for equality.
117      */

118     public void testSerialization() {
119
120         DefaultBoxAndWhiskerCategoryDataset d1
121             = new DefaultBoxAndWhiskerCategoryDataset();
122         d1.add(
123             new BoxAndWhiskerItem(
124                 new Double JavaDoc(1.0), new Double JavaDoc(2.0), new Double JavaDoc(3.0),
125                 new Double JavaDoc(4.0),
126                 new Double JavaDoc(5.0), new Double JavaDoc(6.0), new Double JavaDoc(7.0),
127                 new Double JavaDoc(8.0),
128                 new ArrayList JavaDoc()
129             ), "ROW1", "COLUMN1"
130         );
131         DefaultBoxAndWhiskerCategoryDataset d2 = null;
132         
133         try {
134             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
135             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
136             out.writeObject(d1);
137             out.close();
138
139             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
140                 new ByteArrayInputStream JavaDoc(buffer.toByteArray())
141             );
142             d2 = (DefaultBoxAndWhiskerCategoryDataset) in.readObject();
143             in.close();
144         }
145         catch (Exception JavaDoc e) {
146             System.out.println(e.toString());
147         }
148         assertEquals(d1, d2);
149
150     }
151
152 }
153
Popular Tags