KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > data > junit > TableXYDatasetTests


1 /* ======================================
2  * JFreeChart : a free Java chart library
3  * ======================================
4  *
5  * Project Info: http://www.jfree.org/jfreechart/index.html
6  * Project Lead: David Gilbert (david.gilbert@object-refinery.com);
7  *
8  * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it under the terms
11  * of the GNU Lesser General Public License as published by the Free Software Foundation;
12  * either version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License along with this
19  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  * ------------------------
23  * TableXYDatasetTests.java
24  * ------------------------
25  * (C) Copyright 2003 by Richard Atkinson and Contributors.
26  *
27  * Original Author: Richard Atkinson;
28  * Contributor(s): -;
29  *
30  * $Id: TableXYDatasetTests.java,v 1.6 2003/09/22 19:08:42 ratkinso Exp $
31  *
32  * Changes
33  * -------
34  * 11-Aug-2003 : Version 1 (RA);
35  * 18-Aug-2003 : Added tests for event notification when removing and updating series (RA);
36  * 22-Sep-2003 : Changed to recognise that empty values are now null rather than zero (RA);
37  *
38  */

39 package org.jfree.data.junit;
40
41 import junit.framework.Test;
42 import junit.framework.TestCase;
43 import junit.framework.TestSuite;
44
45 import org.jfree.data.DefaultTableXYDataset;
46 import org.jfree.data.XYSeries;
47
48 /**
49  * Tests for {@link DefaultTableXYDataset}.
50  *
51  * @author Richard Atkinson
52  */

53 public class TableXYDatasetTests extends TestCase {
54
55     /**
56      * Returns the tests as a test suite.
57      *
58      * @return the test suite.
59      */

60     public static Test suite() {
61         return new TestSuite(TableXYDatasetTests.class);
62     }
63
64     /**
65      * Constructs a new set of tests.
66      *
67      * @param name the name of the tests.
68      */

69     public TableXYDatasetTests(String JavaDoc name) {
70         super(name);
71     }
72
73     /**
74      * Assorted tests.
75      */

76     public void testTableXYDataset() {
77         
78         DefaultTableXYDataset tableXYDataSet = new DefaultTableXYDataset();
79         XYSeries series1 = new XYSeries("Series 1", false);
80         series1.add(1, 1);
81         series1.add(2, 1);
82         series1.add(4, 1);
83         series1.add(5, 1);
84         
85         XYSeries series2 = new XYSeries("Series 2", false);
86         series2.add(2, 2);
87         series2.add(3, 2);
88         series2.add(4, 2);
89         series2.add(5, 2);
90         series2.add(6, 2);
91
92         tableXYDataSet.addSeries(series1);
93         tableXYDataSet.addSeries(series2);
94
95         // Test that there are 6 X points and some specific values
96
assertEquals(6, tableXYDataSet.getItemCount());
97         assertEquals(6, tableXYDataSet.getXValue(0, 5).intValue());
98         assertEquals(null, tableXYDataSet.getYValue(0, 5));
99         assertEquals(6, tableXYDataSet.getXValue(1, 5).intValue());
100         assertEquals(2, tableXYDataSet.getYValue(1, 5).intValue());
101
102         series2.add(7, 2);
103         // Test that there are now 7 X points in both series
104
assertEquals(7, tableXYDataSet.getItemCount());
105         assertEquals(null, tableXYDataSet.getYValue(0, 6));
106         assertEquals(2, tableXYDataSet.getYValue(1, 6).intValue());
107
108         // Remove series 2
109
tableXYDataSet.removeSeries(series1);
110         // Test that there are still 7 X points
111
assertEquals(7, tableXYDataSet.getItemCount());
112
113         // Remove series 1 and add new series
114
tableXYDataSet.removeSeries(series2);
115         series1 = new XYSeries("Series 1", false);
116         series1.add(1, 1);
117         series1.add(2, 1);
118         series1.add(4, 1);
119         series1.add(5, 1);
120         tableXYDataSet.addSeries(series1);
121
122         // Test that there are now 4 X points
123
assertEquals(4, tableXYDataSet.getItemCount());
124
125     }
126 }
127
Popular Tags