001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * ----------------------------
028: * TimeTableXYDatasetTests.java
029: * ----------------------------
030: * (C) Copyright 2004, by Object Refinery Limited.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: TimeTableXYDatasetTests.java,v 1.1.2.1 2006/10/03 15:41:39 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 15-Sep-2004 : Version 1 (DG);
040: *
041: */
042:
043: package org.jfree.data.time.junit;
044:
045: import java.io.ByteArrayInputStream;
046: import java.io.ByteArrayOutputStream;
047: import java.io.ObjectInput;
048: import java.io.ObjectInputStream;
049: import java.io.ObjectOutput;
050: import java.io.ObjectOutputStream;
051: import java.util.TimeZone;
052:
053: import junit.framework.Test;
054: import junit.framework.TestCase;
055: import junit.framework.TestSuite;
056:
057: import org.jfree.data.time.TimeTableXYDataset;
058: import org.jfree.data.time.Year;
059:
060: /**
061: * A collection of test cases for the {@link TimeTableXYDataset} class.
062: */
063: public class TimeTableXYDatasetTests extends TestCase {
064:
065: /**
066: * Returns the tests as a test suite.
067: *
068: * @return The test suite.
069: */
070: public static Test suite() {
071: return new TestSuite(TimeTableXYDatasetTests.class);
072: }
073:
074: /**
075: * Constructs a new set of tests.
076: *
077: * @param name the name of the tests.
078: */
079: public TimeTableXYDatasetTests(String name) {
080: super (name);
081: }
082:
083: private static final double DELTA = 0.0000000001;
084:
085: /**
086: * Some checks for a simple dataset.
087: */
088: public void testStandard() {
089: TimeTableXYDataset d = new TimeTableXYDataset();
090: d.add(new Year(1999), 1.0, "Series 1");
091: assertEquals(d.getItemCount(), 1);
092: assertEquals(d.getSeriesCount(), 1);
093: d.add(new Year(2000), 2.0, "Series 2");
094: assertEquals(d.getItemCount(), 2);
095: assertEquals(d.getSeriesCount(), 2);
096: assertEquals(d.getYValue(0, 0), 1.0, DELTA);
097: assertTrue(Double.isNaN(d.getYValue(0, 1)));
098: assertTrue(Double.isNaN(d.getYValue(1, 0)));
099: assertEquals(d.getYValue(1, 1), 2.0, DELTA);
100: }
101:
102: /**
103: * Some checks for the getTimePeriod() method.
104: */
105: public void testGetTimePeriod() {
106: TimeTableXYDataset d = new TimeTableXYDataset();
107: d.add(new Year(1999), 1.0, "Series 1");
108: d.add(new Year(1998), 2.0, "Series 1");
109: d.add(new Year(1996), 3.0, "Series 1");
110: assertEquals(d.getTimePeriod(0), new Year(1996));
111: assertEquals(d.getTimePeriod(1), new Year(1998));
112: assertEquals(d.getTimePeriod(2), new Year(1999));
113: }
114:
115: /**
116: * Some checks for the equals() method.
117: */
118: public void testEquals() {
119: TimeTableXYDataset d1 = new TimeTableXYDataset();
120: TimeTableXYDataset d2 = new TimeTableXYDataset();
121: assertTrue(d1.equals(d2));
122: assertTrue(d2.equals(d1));
123:
124: d1.add(new Year(1999), 123.4, "S1");
125: assertFalse(d1.equals(d2));
126: d2.add(new Year(1999), 123.4, "S1");
127: assertTrue(d1.equals(d2));
128:
129: d1.setDomainIsPointsInTime(!d1.getDomainIsPointsInTime());
130: assertFalse(d1.equals(d2));
131: d2.setDomainIsPointsInTime(!d2.getDomainIsPointsInTime());
132: assertTrue(d1.equals(d2));
133:
134: d1 = new TimeTableXYDataset(TimeZone.getTimeZone("GMT"));
135: d2 = new TimeTableXYDataset(TimeZone
136: .getTimeZone("America/Los_Angeles"));
137: assertFalse(d1.equals(d2));
138: }
139:
140: /**
141: * Some checks for cloning.
142: */
143: public void testClone() {
144:
145: TimeTableXYDataset d = new TimeTableXYDataset();
146: d.add(new Year(1999), 25.0, "Series");
147:
148: TimeTableXYDataset clone = null;
149: try {
150: clone = (TimeTableXYDataset) d.clone();
151: } catch (CloneNotSupportedException e) {
152: assertTrue(false);
153: }
154: assertTrue(clone.equals(d));
155:
156: // now test that the clone is independent of the original
157: clone.add(new Year(2004), 1.2, "SS");
158: assertFalse(clone.equals(d));
159: }
160:
161: /**
162: * Serialize an instance, restore it, and check for equality.
163: */
164: public void testSerialization() {
165:
166: TimeTableXYDataset d1 = new TimeTableXYDataset();
167: d1.add(new Year(1999), 123.4, "S1");
168: TimeTableXYDataset d2 = null;
169:
170: try {
171: ByteArrayOutputStream buffer = new ByteArrayOutputStream();
172: ObjectOutput out = new ObjectOutputStream(buffer);
173: out.writeObject(d1);
174: out.close();
175:
176: ObjectInput in = new ObjectInputStream(
177: new ByteArrayInputStream(buffer.toByteArray()));
178: d2 = (TimeTableXYDataset) in.readObject();
179: in.close();
180: } catch (Exception e) {
181: System.out.println(e.toString());
182: }
183: assertTrue(d1.equals(d2));
184:
185: }
186:
187: }
|