file_name
stringlengths
6
86
file_path
stringlengths
45
249
content
stringlengths
47
6.26M
file_size
int64
47
6.26M
language
stringclasses
1 value
extension
stringclasses
1 value
repo_name
stringclasses
767 values
repo_stars
int64
8
14.4k
repo_forks
int64
0
1.17k
repo_open_issues
int64
0
788
repo_created_at
stringclasses
767 values
repo_pushed_at
stringclasses
767 values
XYSeriesTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/xy/XYSeriesTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2013, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------- * XYSeriesTest.java * ----------------- * (C) Copyright 2003-2013, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 23-Dec-2003 : Version 1 (DG); * 15-Jan-2007 : Added tests for new toArray() method (DG); * 30-Jan-2007 : Fixed some code that won't compile with Java 1.4 (DG); * 31-Oct-2007 : New hashCode() test (DG); * 01-May-2008 : Added testAddOrUpdate3() (DG); * 24-Nov-2008 : Added testBug1955483() (DG); * 06-Mar-2009 : Added tests for cached bounds values (DG); * */ package org.jfree.data.xy; import org.jfree.chart.TestUtilities; import org.jfree.data.general.SeriesException; import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** * Tests for the {@link XYSeries} class. */ public class XYSeriesTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { XYSeries s1 = new XYSeries("Series"); s1.add(1.0, 1.1); XYSeries s2 = new XYSeries("Series"); s2.add(1.0, 1.1); assertEquals(s1, s2); assertEquals(s2, s1); s1.setKey("Series X"); assertFalse(s1.equals(s2)); s2.setKey("Series X"); assertEquals(s1, s2); s1.add(2.0, 2.2); assertFalse(s1.equals(s2)); s2.add(2.0, 2.2); assertEquals(s1, s2); } /** * Some simple checks for the hashCode() method. */ @Test public void testHashCode() { XYSeries s1 = new XYSeries("Test"); XYSeries s2 = new XYSeries("Test"); assertEquals(s1, s2); assertEquals(s1.hashCode(), s2.hashCode()); s1.add(1.0, 500.0); s2.add(1.0, 500.0); assertEquals(s1, s2); assertEquals(s1.hashCode(), s2.hashCode()); s1.add(2.0, null); s2.add(2.0, null); assertEquals(s1, s2); assertEquals(s1.hashCode(), s2.hashCode()); s1.add(5.0, 111.0); s2.add(5.0, 111.0); assertEquals(s1, s2); assertEquals(s1.hashCode(), s2.hashCode()); s1.add(9.0, 1.0); s2.add(9.0, 1.0); assertEquals(s1, s2); assertEquals(s1.hashCode(), s2.hashCode()); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { XYSeries s1 = new XYSeries("Series"); s1.add(1.0, 1.1); XYSeries s2 = (XYSeries) s1.clone(); assertNotSame(s1, s2); assertSame(s1.getClass(), s2.getClass()); assertEquals(s1, s2); } /** * Another test of the clone() method. */ @Test public void testCloning2() throws CloneNotSupportedException { XYSeries s1 = new XYSeries("S1"); s1.add(1.0, 100.0); s1.add(2.0, null); s1.add(3.0, 200.0); XYSeries s2 = (XYSeries) s1.clone(); assertEquals(s1, s2); // check independence s2.add(4.0, 300.0); assertFalse(s1.equals(s2)); s1.add(4.0, 300.0); assertEquals(s1, s2); } /** * Another test of the clone() method. */ @Test public void testCloning3() throws CloneNotSupportedException { XYSeries s1 = new XYSeries("S1"); XYSeries s2 = (XYSeries) s1.clone(); assertEquals(s1, s2); // check independence s2.add(4.0, 300.0); assertFalse(s1.equals(s2)); s1.add(4.0, 300.0); assertEquals(s1, s2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() { XYSeries s1 = new XYSeries("Series"); s1.add(1.0, 1.1); XYSeries s2 = (XYSeries) TestUtilities.serialised(s1); assertEquals(s1, s2); } /** * Simple test for the indexOf() method. */ @Test public void testIndexOf() { XYSeries s1 = new XYSeries("Series 1"); s1.add(1.0, 1.0); s1.add(2.0, 2.0); s1.add(3.0, 3.0); assertEquals(0, s1.indexOf(1.0)); assertEquals(1, s1.indexOf(2.0)); assertEquals(2, s1.indexOf(3.0)); assertEquals(-4, s1.indexOf(99.9)); } /** * A check for the indexOf() method for an unsorted series. */ @Test public void testIndexOf2() { XYSeries s1 = new XYSeries("Series 1", false, true); s1.add(1.0, 1.0); s1.add(3.0, 3.0); s1.add(2.0, 2.0); assertEquals(0, s1.indexOf(1.0)); assertEquals(1, s1.indexOf(3.0)); assertEquals(2, s1.indexOf(2.0)); } /** * A check for the indexOf(Number) method when the series has duplicate * x-values. */ @Test public void testIndexOf3() { XYSeries s1 = new XYSeries("Series 1"); s1.add(1.0, 1.0); s1.add(2.0, 2.0); s1.add(2.0, 3.0); assertEquals(0, s1.indexOf(1.0)); assertEquals(1, s1.indexOf(2.0)); } /** * Simple test for the remove() method. */ @Test public void testRemove() { XYSeries s1 = new XYSeries("Series 1"); s1.add(1.0, 1.0); s1.add(2.0, 2.0); s1.add(3.0, 3.0); assertEquals(3, s1.getItemCount()); s1.remove(2.0); assertEquals(3.0, s1.getX(1)); s1.remove(0); assertEquals(3.0, s1.getX(0)); } /** * Some checks for the remove(int) method. */ @Test public void testRemove2() { XYSeries s1 = new XYSeries("S1"); s1.add(1.0, 1.1); s1.add(2.0, 2.2); s1.add(3.0, 3.3); s1.add(4.0, 4.4); s1.add(5.0, 5.5); s1.add(6.0, 6.6); assertEquals(6, s1.getItemCount()); assertEquals(1.0, s1.getMinX(), EPSILON); assertEquals(6.0, s1.getMaxX(), EPSILON); assertEquals(1.1, s1.getMinY(), EPSILON); assertEquals(6.6, s1.getMaxY(), EPSILON); s1.remove(5); assertEquals(5, s1.getItemCount()); assertEquals(1.0, s1.getMinX(), EPSILON); assertEquals(5.0, s1.getMaxX(), EPSILON); assertEquals(1.1, s1.getMinY(), EPSILON); assertEquals(5.5, s1.getMaxY(), EPSILON); } private static final double EPSILON = 0.0000000001; /** * When items are added with duplicate x-values, we expect them to remain * in the order they were added. */ @Test public void testAdditionOfDuplicateXValues() { XYSeries s1 = new XYSeries("Series 1"); s1.add(1.0, 1.0); s1.add(2.0, 2.0); s1.add(2.0, 3.0); s1.add(2.0, 4.0); s1.add(3.0, 5.0); assertEquals(1.0, s1.getY(0).doubleValue(), EPSILON); assertEquals(2.0, s1.getY(1).doubleValue(), EPSILON); assertEquals(3.0, s1.getY(2).doubleValue(), EPSILON); assertEquals(4.0, s1.getY(3).doubleValue(), EPSILON); assertEquals(5.0, s1.getY(4).doubleValue(), EPSILON); } /** * Some checks for the update(Number, Number) method. */ @Test public void testUpdate() { XYSeries series = new XYSeries("S1"); series.add(new Integer(1), new Integer(2)); assertEquals(2, series.getY(0)); series.update(1, 3); assertEquals(3, series.getY(0)); try { series.update(2, 99); fail("SeriesException should have been thrown for unknown key"); } catch (SeriesException e) { assertEquals("No observation for x = 2", e.getMessage()); } } /** * Some checks for the update() method for an unsorted series. */ @Test public void testUpdate2() { XYSeries series = new XYSeries("Series", false, true); series.add(5.0, 55.0); series.add(4.0, 44.0); series.add(6.0, 66.0); series.update(4.0, 99.0); assertEquals(99.0, series.getY(1)); } /** * Some checks for the addOrUpdate() method. */ @Test public void testAddOrUpdate() { XYSeries series = new XYSeries("S1", true, false); XYDataItem old = series.addOrUpdate(new Long(1), new Long(2)); assertNull(old); assertEquals(1, series.getItemCount()); assertEquals((long) 2, series.getY(0)); old = series.addOrUpdate(new Long(2), new Long(3)); assertNull(old); assertEquals(2, series.getItemCount()); assertEquals((long) 3, series.getY(1)); old = series.addOrUpdate(new Long(1), new Long(99)); assertEquals(new XYDataItem(new Long(1), new Long(2)), old); assertEquals(2, series.getItemCount()); assertEquals((long) 99, series.getY(0)); assertEquals((long) 3, series.getY(1)); } /** * Some checks for the addOrUpdate() method for an UNSORTED series. */ @Test public void testAddOrUpdate2() { XYSeries series = new XYSeries("Series", false, false); series.add(5.0, 5.5); series.add(6.0, 6.6); series.add(3.0, 3.3); series.add(4.0, 4.4); series.add(2.0, 2.2); series.add(1.0, 1.1); series.addOrUpdate(new Double(3.0), new Double(33.3)); series.addOrUpdate(new Double(2.0), new Double(22.2)); assertEquals(33.3, series.getY(2).doubleValue(), EPSILON); assertEquals(22.2, series.getY(4).doubleValue(), EPSILON); } /** * Another test for the addOrUpdate() method. */ @Test public void testAddOrUpdate3() { XYSeries series = new XYSeries("Series", false, true); series.addOrUpdate(1.0, 1.0); series.addOrUpdate(1.0, 2.0); series.addOrUpdate(1.0, 3.0); assertEquals(1.0, series.getY(0)); assertEquals(2.0, series.getY(1)); assertEquals(3.0, series.getY(2)); assertEquals(3, series.getItemCount()); } /** * Some checks for the add() method for an UNSORTED series. */ @Test public void testAdd() { XYSeries series = new XYSeries("Series", false, true); series.add(5.0, 5.50); series.add(5.1, 5.51); series.add(6.0, 6.6); series.add(3.0, 3.3); series.add(4.0, 4.4); series.add(2.0, 2.2); series.add(1.0, 1.1); assertEquals(5.5, series.getY(0).doubleValue(), EPSILON); assertEquals(5.51, series.getY(1).doubleValue(), EPSILON); assertEquals(6.6, series.getY(2).doubleValue(), EPSILON); assertEquals(3.3, series.getY(3).doubleValue(), EPSILON); assertEquals(4.4, series.getY(4).doubleValue(), EPSILON); assertEquals(2.2, series.getY(5).doubleValue(), EPSILON); assertEquals(1.1, series.getY(6).doubleValue(), EPSILON); } /** * A simple check that the maximumItemCount attribute is working. */ @Test public void testSetMaximumItemCount() { XYSeries s1 = new XYSeries("S1"); assertEquals(Integer.MAX_VALUE, s1.getMaximumItemCount()); s1.setMaximumItemCount(2); assertEquals(2, s1.getMaximumItemCount()); s1.add(1.0, 1.1); s1.add(2.0, 2.2); s1.add(3.0, 3.3); assertEquals(2.0, s1.getX(0).doubleValue(), EPSILON); assertEquals(3.0, s1.getX(1).doubleValue(), EPSILON); } /** * Check that the maximum item count can be applied retrospectively. */ @Test public void testSetMaximumItemCount2() { XYSeries s1 = new XYSeries("S1"); s1.add(1.0, 1.1); s1.add(2.0, 2.2); s1.add(3.0, 3.3); s1.setMaximumItemCount(2); assertEquals(2.0, s1.getX(0).doubleValue(), EPSILON); assertEquals(3.0, s1.getX(1).doubleValue(), EPSILON); } /** * Check that the item bounds are determined correctly when there is a * maximum item count. */ @Test public void testSetMaximumItemCount3() { XYSeries s1 = new XYSeries("S1"); s1.add(1.0, 1.1); s1.add(2.0, 2.2); s1.add(3.0, 3.3); s1.add(4.0, 4.4); s1.add(5.0, 5.5); s1.add(6.0, 6.6); s1.setMaximumItemCount(2); assertEquals(5.0, s1.getX(0).doubleValue(), EPSILON); assertEquals(6.0, s1.getX(1).doubleValue(), EPSILON); assertEquals(5.0, s1.getMinX(), EPSILON); assertEquals(6.0, s1.getMaxX(), EPSILON); assertEquals(5.5, s1.getMinY(), EPSILON); assertEquals(6.6, s1.getMaxY(), EPSILON); } /** * Check that the item bounds are determined correctly when there is a * maximum item count. */ @Test public void testSetMaximumItemCount4() { XYSeries s1 = new XYSeries("S1"); s1.setMaximumItemCount(2); s1.add(1.0, 1.1); s1.add(2.0, 2.2); s1.add(3.0, 3.3); assertEquals(2.0, s1.getX(0).doubleValue(), EPSILON); assertEquals(3.0, s1.getX(1).doubleValue(), EPSILON); assertEquals(2.0, s1.getMinX(), EPSILON); assertEquals(3.0, s1.getMaxX(), EPSILON); assertEquals(2.2, s1.getMinY(), EPSILON); assertEquals(3.3, s1.getMaxY(), EPSILON); } /** * Some checks for the toArray() method. */ @Test public void testToArray() { XYSeries s = new XYSeries("S1"); double[][] array = s.toArray(); assertEquals(2, array.length); assertEquals(0, array[0].length); assertEquals(0, array[1].length); s.add(1.0, 2.0); array = s.toArray(); assertEquals(1, array[0].length); assertEquals(1, array[1].length); assertEquals(2, array.length); assertEquals(1.0, array[0][0], EPSILON); assertEquals(2.0, array[1][0], EPSILON); s.add(2.0, null); array = s.toArray(); assertEquals(2, array.length); assertEquals(2, array[0].length); assertEquals(2, array[1].length); assertEquals(2.0, array[0][1], EPSILON); assertTrue(Double.isNaN(array[1][1])); } /** * Some checks for an example using the toArray() method. */ @Test public void testToArrayExample() { XYSeries s = new XYSeries("S"); s.add(1.0, 11.0); s.add(2.0, 22.0); s.add(3.5, 35.0); s.add(5.0, null); DefaultXYDataset dataset = new DefaultXYDataset(); dataset.addSeries("S", s.toArray()); assertEquals(1, dataset.getSeriesCount()); assertEquals(4, dataset.getItemCount(0)); assertEquals("S", dataset.getSeriesKey(0)); assertEquals(1.0, dataset.getXValue(0, 0), EPSILON); assertEquals(2.0, dataset.getXValue(0, 1), EPSILON); assertEquals(3.5, dataset.getXValue(0, 2), EPSILON); assertEquals(5.0, dataset.getXValue(0, 3), EPSILON); assertEquals(11.0, dataset.getYValue(0, 0), EPSILON); assertEquals(22.0, dataset.getYValue(0, 1), EPSILON); assertEquals(35.0, dataset.getYValue(0, 2), EPSILON); assertTrue(Double.isNaN(dataset.getYValue(0, 3))); } /** * Another test for the addOrUpdate() method. */ @Test public void testBug1955483() { XYSeries series = new XYSeries("Series", true, true); series.addOrUpdate(1.0, 1.0); series.addOrUpdate(1.0, 2.0); assertEquals(1.0, series.getY(0)); assertEquals(2.0, series.getY(1)); assertEquals(2, series.getItemCount()); } /** * Some checks for the delete(int, int) method. */ @Test public void testDelete() { XYSeries s1 = new XYSeries("S1"); s1.add(1.0, 1.1); s1.add(2.0, 2.2); s1.add(3.0, 3.3); s1.add(4.0, 4.4); s1.add(5.0, 5.5); s1.add(6.0, 6.6); s1.delete(2, 5); assertEquals(2, s1.getItemCount()); assertEquals(1.0, s1.getX(0).doubleValue(), EPSILON); assertEquals(2.0, s1.getX(1).doubleValue(), EPSILON); assertEquals(1.0, s1.getMinX(), EPSILON); assertEquals(2.0, s1.getMaxX(), EPSILON); assertEquals(1.1, s1.getMinY(), EPSILON); assertEquals(2.2, s1.getMaxY(), EPSILON); } /** * Some checks for the getMinX() method. */ @Test public void testGetMinX() { XYSeries s1 = new XYSeries("S1"); assertTrue(Double.isNaN(s1.getMinX())); s1.add(1.0, 1.1); assertEquals(1.0, s1.getMinX(), EPSILON); s1.add(2.0, 2.2); assertEquals(1.0, s1.getMinX(), EPSILON); s1.add(Double.NaN, 99.9); assertEquals(1.0, s1.getMinX(), EPSILON); s1.add(-1.0, -1.1); assertEquals(-1.0, s1.getMinX(), EPSILON); s1.add(0.0, null); assertEquals(-1.0, s1.getMinX(), EPSILON); } /** * Some checks for the getMaxX() method. */ @Test public void testGetMaxX() { XYSeries s1 = new XYSeries("S1"); assertTrue(Double.isNaN(s1.getMaxX())); s1.add(1.0, 1.1); assertEquals(1.0, s1.getMaxX(), EPSILON); s1.add(2.0, 2.2); assertEquals(2.0, s1.getMaxX(), EPSILON); s1.add(Double.NaN, 99.9); assertEquals(2.0, s1.getMaxX(), EPSILON); s1.add(-1.0, -1.1); assertEquals(2.0, s1.getMaxX(), EPSILON); s1.add(0.0, null); assertEquals(2.0, s1.getMaxX(), EPSILON); } /** * Some checks for the getMinY() method. */ @Test public void testGetMinY() { XYSeries s1 = new XYSeries("S1"); assertTrue(Double.isNaN(s1.getMinY())); s1.add(1.0, 1.1); assertEquals(1.1, s1.getMinY(), EPSILON); s1.add(2.0, 2.2); assertEquals(1.1, s1.getMinY(), EPSILON); s1.add(Double.NaN, 99.9); assertEquals(1.1, s1.getMinY(), EPSILON); s1.add(-1.0, -1.1); assertEquals(-1.1, s1.getMinY(), EPSILON); s1.add(0.0, null); assertEquals(-1.1, s1.getMinY(), EPSILON); } /** * Some checks for the getMaxY() method. */ @Test public void testGetMaxY() { XYSeries s1 = new XYSeries("S1"); assertTrue(Double.isNaN(s1.getMaxY())); s1.add(1.0, 1.1); assertEquals(1.1, s1.getMaxY(), EPSILON); s1.add(2.0, 2.2); assertEquals(2.2, s1.getMaxY(), EPSILON); s1.add(Double.NaN, 99.9); assertEquals(99.9, s1.getMaxY(), EPSILON); s1.add(-1.0, -1.1); assertEquals(99.9, s1.getMaxY(), EPSILON); s1.add(0.0, null); assertEquals(99.9, s1.getMaxY(), EPSILON); } /** * A test for a bug reported in the forum: * * http://www.jfree.org/forum/viewtopic.php?f=3&t=116601 */ @Test public void testGetMaxY2() { XYSeries series = new XYSeries(1, true, false); series.addOrUpdate(1, 20); series.addOrUpdate(2, 30); series.addOrUpdate(3, 40); assertEquals(40.0, series.getMaxY(), EPSILON); series.addOrUpdate(2, 22); assertEquals(40.0, series.getMaxY(), EPSILON); } /** * A test for the clear method. */ @Test public void testClear() { XYSeries s1 = new XYSeries("S1"); s1.add(1.0, 1.1); s1.add(2.0, 2.2); s1.add(3.0, 3.3); assertEquals(3, s1.getItemCount()); s1.clear(); assertEquals(0, s1.getItemCount()); assertTrue(Double.isNaN(s1.getMinX())); assertTrue(Double.isNaN(s1.getMaxX())); assertTrue(Double.isNaN(s1.getMinY())); assertTrue(Double.isNaN(s1.getMaxY())); } /** * Some checks for the updateByIndex() method. */ @Test public void testUpdateByIndex() { XYSeries s1 = new XYSeries("S1"); s1.add(1.0, 1.1); s1.add(2.0, 2.2); s1.add(3.0, 3.3); assertEquals(1.1, s1.getMinY(), EPSILON); assertEquals(3.3, s1.getMaxY(), EPSILON); s1.updateByIndex(0, -5.0); assertEquals(-5.0, s1.getMinY(), EPSILON); assertEquals(3.3, s1.getMaxY(), EPSILON); s1.updateByIndex(0, null); assertEquals(2.2, s1.getMinY(), EPSILON); assertEquals(3.3, s1.getMaxY(), EPSILON); s1.updateByIndex(2, null); assertEquals(2.2, s1.getMinY(), EPSILON); assertEquals(2.2, s1.getMaxY(), EPSILON); s1.updateByIndex(1, null); assertTrue(Double.isNaN(s1.getMinY())); assertTrue(Double.isNaN(s1.getMaxY())); } /** * Some checks for the updateByIndex() method. */ @Test public void testUpdateByIndex2() { XYSeries s1 = new XYSeries("S1"); s1.add(1.0, Double.NaN); assertTrue(Double.isNaN(s1.getMinY())); assertTrue(Double.isNaN(s1.getMaxY())); s1.updateByIndex(0, 1.0); assertEquals(1.0, s1.getMinY(), EPSILON); assertEquals(1.0, s1.getMaxY(), EPSILON); s1.updateByIndex(0, 2.0); assertEquals(2.0, s1.getMinY(), EPSILON); assertEquals(2.0, s1.getMaxY(), EPSILON); s1.add(-1.0, -1.0); s1.updateByIndex(0, 0.0); assertEquals(0.0, s1.getMinY(), EPSILON); assertEquals(2.0, s1.getMaxY(), EPSILON); } /** * Some checks for the updateByIndex() method. */ @Test public void testUpdateByIndex3() { XYSeries s1 = new XYSeries("S1"); s1.add(1.0, 1.1); s1.add(2.0, 2.2); s1.add(3.0, 3.3); s1.updateByIndex(1, 2.05); assertEquals(1.1, s1.getMinY(), EPSILON); assertEquals(3.3, s1.getMaxY(), EPSILON); } /** * Some checks for the update(Number, Number) method. */ @Test public void testUpdateXY() { XYSeries s1 = new XYSeries("S1"); s1.add(1.0, Double.NaN); assertTrue(Double.isNaN(s1.getMinY())); assertTrue(Double.isNaN(s1.getMaxY())); s1.update(1.0, 1.0); assertEquals(1.0, s1.getMinY(), EPSILON); assertEquals(1.0, s1.getMaxY(), EPSILON); s1.update(1.0, 2.0); assertEquals(2.0, s1.getMinY(), EPSILON); assertEquals(2.0, s1.getMaxY(), EPSILON); } @Test public void testSetKey() { XYSeries s1 = new XYSeries("S"); s1.setKey("S1"); assertEquals("S1", s1.getKey()); XYSeriesCollection c = new XYSeriesCollection(); c.addSeries(s1); XYSeries s2 = new XYSeries("S2"); c.addSeries(s2); // now we should be allowed to change s1's key to anything but "S2" s1.setKey("OK"); assertEquals("OK", s1.getKey()); try { s1.setKey("S2"); fail("Expect an exception here."); } catch (IllegalArgumentException e) { // OK } // after s1 is removed from the collection, we should be able to set // the key to anything we want... c.removeSeries(s1); s1.setKey("S2"); // check that removing by index also works s1.setKey("S1"); c.addSeries(s1); c.removeSeries(1); s1.setKey("S2"); } }
24,558
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYSeriesCollectionTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/xy/XYSeriesCollectionTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2014, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------------- * XYSeriesCollectionTest.java * --------------------------- * (C) Copyright 2003-2014, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 18-May-2003 : Version 1 (DG); * 27-Nov-2006 : Updated testCloning() (DG); * 08-Mar-2007 : Added testGetSeries() and testRemoveSeries() (DG); * 08-May-2007 : Added testIndexOf() (DG); * 03-Dec-2007 : Added testGetSeriesByKey() (DG); * 22-Apr-2008 : Added testPublicCloneable (DG); * 06-Mar-2009 : Added testGetDomainBounds (DG); * 17-May-2010 : Added checks for duplicate series names (DG); * 08-Jan-2012 : Added testBug3445507() (DG); * */ package org.jfree.data.xy; import org.jfree.chart.util.PublicCloneable; import org.jfree.data.Range; import org.jfree.data.UnknownKeyException; import org.junit.Test; import org.jfree.chart.TestUtilities; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** * Tests for the {@link XYSeriesCollection} class. */ public class XYSeriesCollectionTest { private static final double EPSILON = 0.0000000001; /** * Some checks for the constructor. */ @Test public void testConstructor() { XYSeriesCollection xysc = new XYSeriesCollection(); assertEquals(0, xysc.getSeriesCount()); assertEquals(1.0, xysc.getIntervalWidth(), EPSILON); assertEquals(0.5, xysc.getIntervalPositionFactor(), EPSILON); } /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { XYSeries s1 = new XYSeries("Series"); s1.add(1.0, 1.1); XYSeriesCollection c1 = new XYSeriesCollection(); c1.addSeries(s1); XYSeries s2 = new XYSeries("Series"); s2.add(1.0, 1.1); XYSeriesCollection c2 = new XYSeriesCollection(); c2.addSeries(s2); assertEquals(c1, c2); assertEquals(c2, c1); c1.addSeries(new XYSeries("Empty Series")); assertFalse(c1.equals(c2)); c2.addSeries(new XYSeries("Empty Series")); assertEquals(c1, c2); c1.setIntervalWidth(5.0); assertFalse(c1.equals(c2)); c2.setIntervalWidth(5.0); assertEquals(c1, c2); c1.setIntervalPositionFactor(0.75); assertFalse(c1.equals(c2)); c2.setIntervalPositionFactor(0.75); assertEquals(c1, c2); c1.setAutoWidth(true); assertFalse(c1.equals(c2)); c2.setAutoWidth(true); assertEquals(c1, c2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { XYSeries s1 = new XYSeries("Series"); s1.add(1.0, 1.1); XYSeriesCollection c1 = new XYSeriesCollection(); c1.addSeries(s1); XYSeriesCollection c2 = (XYSeriesCollection) c1.clone(); assertNotSame(c1, c2); assertSame(c1.getClass(), c2.getClass()); assertEquals(c1, c2); // check independence s1.setDescription("XYZ"); assertFalse(c1.equals(c2)); } /** * Verify that this class implements {@link PublicCloneable}. */ @Test public void testPublicCloneable() { Object c1 = new XYSeriesCollection(); assertTrue(c1 instanceof PublicCloneable); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() { XYSeries s1 = new XYSeries("Series"); s1.add(1.0, 1.1); XYSeriesCollection c1 = new XYSeriesCollection(); c1.addSeries(s1); XYSeriesCollection c2 = (XYSeriesCollection) TestUtilities.serialised(c1); assertEquals(c1, c2); } /** * A test for bug report 1170825. */ @Test public void test1170825() { XYSeries s1 = new XYSeries("Series1"); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(s1); try { /* XYSeries s = */ dataset.getSeries(1); } catch (IllegalArgumentException e) { // correct outcome } catch (IndexOutOfBoundsException e) { assertTrue(false); // wrong outcome } } /** * Some basic checks for the getSeries() method. */ @Test public void testGetSeries() { XYSeriesCollection c = new XYSeriesCollection(); XYSeries s1 = new XYSeries("s1"); c.addSeries(s1); assertEquals("s1", c.getSeries(0).getKey()); try { c.getSeries(-1); fail("Should have thrown IndexOutOfBoundsException on negative key"); } catch (IllegalArgumentException e) { assertEquals("Series index out of bounds", e.getMessage()); } try { c.getSeries(1); fail("Should have thrown IndexOutOfBoundsException on key out of range"); } catch (IllegalArgumentException e) { assertEquals("Series index out of bounds", e.getMessage()); } } /** * Some checks for the getSeries(Comparable) method. */ @Test public void testGetSeriesByKey() { XYSeriesCollection c = new XYSeriesCollection(); XYSeries s1 = new XYSeries("s1"); c.addSeries(s1); assertEquals("s1", c.getSeries("s1").getKey()); try { c.getSeries("s2"); fail("Should have thrown UnknownKeyException on unknown key"); } catch (UnknownKeyException e) { assertEquals("Key not found: s2", e.getMessage()); } try { c.getSeries(null); fail("Should have thrown IndexOutOfBoundsException on null key"); } catch (IllegalArgumentException e) { assertEquals("Null 'key' argument.", e.getMessage()); } } /** * Some basic checks for the addSeries() method. */ @Test public void testAddSeries() { XYSeriesCollection c = new XYSeriesCollection(); XYSeries s1 = new XYSeries("s1"); c.addSeries(s1); // the dataset should prevent the addition of a series with the // same name as an existing series in the dataset XYSeries s2 = new XYSeries("s1"); try { c.addSeries(s2); fail("Should have thrown IllegalArgumentException on duplicate key"); } catch (IllegalArgumentException e) { assertEquals("This dataset already contains a series with the key s1", e.getMessage()); } assertEquals(1, c.getSeriesCount()); } /** * Some basic checks for the removeSeries() method. */ @Test public void testRemoveSeries() { XYSeriesCollection c = new XYSeriesCollection(); XYSeries s1 = new XYSeries("s1"); c.addSeries(s1); c.removeSeries(0); assertEquals(0, c.getSeriesCount()); c.addSeries(s1); try { c.removeSeries(-1); fail("Should have thrown IndexOutOfBoundsException on negative key"); } catch (IllegalArgumentException e) { assertEquals("Series index out of bounds.", e.getMessage()); } try { c.removeSeries(1); fail("Should have thrown IndexOutOfBoundsException on key out of range"); } catch (IllegalArgumentException e) { assertEquals("Series index out of bounds.", e.getMessage()); } } /** * Some tests for the indexOf() method. */ @Test public void testIndexOf() { XYSeries s1 = new XYSeries("S1"); XYSeries s2 = new XYSeries("S2"); XYSeriesCollection dataset = new XYSeriesCollection(); assertEquals(-1, dataset.indexOf(s1)); assertEquals(-1, dataset.indexOf(s2)); dataset.addSeries(s1); assertEquals(0, dataset.indexOf(s1)); assertEquals(-1, dataset.indexOf(s2)); dataset.addSeries(s2); assertEquals(0, dataset.indexOf(s1)); assertEquals(1, dataset.indexOf(s2)); dataset.removeSeries(s1); assertEquals(-1, dataset.indexOf(s1)); assertEquals(0, dataset.indexOf(s2)); XYSeries s2b = new XYSeries("S2"); assertEquals(0, dataset.indexOf(s2b)); } /** * Some checks for the getDomainBounds() method. */ @Test public void testGetDomainBounds() { XYSeriesCollection dataset = new XYSeriesCollection(); Range r = dataset.getDomainBounds(false); assertNull(r); r = dataset.getDomainBounds(true); assertNull(r); XYSeries series = new XYSeries("S1"); dataset.addSeries(series); r = dataset.getDomainBounds(false); assertNull(r); r = dataset.getDomainBounds(true); assertNull(r); series.add(1.0, 1.1); r = dataset.getDomainBounds(false); assertEquals(new Range(1.0, 1.0), r); r = dataset.getDomainBounds(true); assertEquals(new Range(0.5, 1.5), r); series.add(-1.0, -1.1); r = dataset.getDomainBounds(false); assertEquals(new Range(-1.0, 1.0), r); r = dataset.getDomainBounds(true); assertEquals(new Range(-1.5, 1.5), r); } /** * Some checks for the getRangeBounds() method. */ @Test public void testGetRangeBounds() { XYSeriesCollection dataset = new XYSeriesCollection(); // when the dataset contains no series, we expect the value range to // be null assertNull(dataset.getRangeBounds(false)); assertNull(dataset.getRangeBounds(true)); // when the dataset contains one or more series, but those series // contain no items, we expect the value range to be null XYSeries series = new XYSeries("S1"); dataset.addSeries(series); assertNull(dataset.getRangeBounds(false)); assertNull(dataset.getRangeBounds(true)); // tests with values series.add(1.0, 1.1); assertEquals(new Range(1.1, 1.1), dataset.getRangeBounds(false)); assertEquals(new Range(1.1, 1.1), dataset.getRangeBounds(true)); series.add(-1.0, -1.1); assertEquals(new Range(-1.1, 1.1), dataset.getRangeBounds(false)); assertEquals(new Range(-1.1, 1.1), dataset.getRangeBounds(true)); series.add(0.0, null); assertEquals(new Range(-1.1, 1.1), dataset.getRangeBounds(false)); assertEquals(new Range(-1.1, 1.1), dataset.getRangeBounds(true)); XYSeries s2 = new XYSeries("S2"); dataset.addSeries(s2); assertEquals(new Range(-1.1, 1.1), dataset.getRangeBounds(false)); assertEquals(new Range(-1.1, 1.1), dataset.getRangeBounds(true)); s2.add(2.0, 5.0); assertEquals(new Range(-1.1, 5.0), dataset.getRangeBounds(false)); assertEquals(new Range(-1.1, 5.0), dataset.getRangeBounds(true)); } @Test public void testGetRangeLowerBound() { XYSeriesCollection dataset = new XYSeriesCollection(); // when the dataset contains no series, we expect the value range to // be null assertTrue(Double.isNaN(dataset.getRangeLowerBound(false))); assertTrue(Double.isNaN(dataset.getRangeLowerBound(true))); // when the dataset contains one or more series, but those series // contain no items, we expect the value range to be null XYSeries series = new XYSeries("S1"); dataset.addSeries(series); assertTrue(Double.isNaN(dataset.getRangeLowerBound(false))); assertTrue(Double.isNaN(dataset.getRangeLowerBound(true))); // tests with values series.add(1.0, 1.1); assertEquals(1.1, dataset.getRangeLowerBound(false), EPSILON); assertEquals(1.1, dataset.getRangeLowerBound(true), EPSILON); series.add(-1.0, -1.1); assertEquals(-1.1, dataset.getRangeLowerBound(false), EPSILON); assertEquals(-1.1, dataset.getRangeLowerBound(true), EPSILON); series.add(0.0, null); assertEquals(-1.1, dataset.getRangeLowerBound(false), EPSILON); assertEquals(-1.1, dataset.getRangeLowerBound(true), EPSILON); XYSeries s2 = new XYSeries("S2"); dataset.addSeries(s2); assertEquals(-1.1, dataset.getRangeLowerBound(false), EPSILON); assertEquals(-1.1, dataset.getRangeLowerBound(true), EPSILON); s2.add(2.0, 5.0); assertEquals(-1.1, dataset.getRangeLowerBound(false), EPSILON); assertEquals(-1.1, dataset.getRangeLowerBound(true), EPSILON); } @Test public void testGetRangeUpperBound() { XYSeriesCollection dataset = new XYSeriesCollection(); // when the dataset contains no series, we expect the value range to // be null assertTrue(Double.isNaN(dataset.getRangeUpperBound(false))); assertTrue(Double.isNaN(dataset.getRangeUpperBound(true))); // when the dataset contains one or more series, but those series // contain no items, we expect the value range to be null XYSeries series = new XYSeries("S1"); dataset.addSeries(series); assertTrue(Double.isNaN(dataset.getRangeUpperBound(false))); assertTrue(Double.isNaN(dataset.getRangeUpperBound(true))); // tests with values series.add(1.0, 1.1); assertEquals(1.1, dataset.getRangeUpperBound(false), EPSILON); assertEquals(1.1, dataset.getRangeUpperBound(true), EPSILON); series.add(-1.0, -1.1); assertEquals(1.1, dataset.getRangeUpperBound(false), EPSILON); assertEquals(1.1, dataset.getRangeUpperBound(true), EPSILON); series.add(0.0, null); assertEquals(1.1, dataset.getRangeUpperBound(false), EPSILON); assertEquals(1.1, dataset.getRangeUpperBound(true), EPSILON); XYSeries s2 = new XYSeries("S2"); dataset.addSeries(s2); assertEquals(1.1, dataset.getRangeUpperBound(false), EPSILON); assertEquals(1.1, dataset.getRangeUpperBound(true), EPSILON); s2.add(2.0, 5.0); assertEquals(5.0, dataset.getRangeUpperBound(false), EPSILON); assertEquals(5.0, dataset.getRangeUpperBound(true), EPSILON); } /** * A check that the dataset prevents renaming a series to the name of an * existing series in the dataset. */ @Test public void testRenameSeries() { XYSeries s1 = new XYSeries("S1"); XYSeries s2 = new XYSeries("S2"); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(s1); dataset.addSeries(s2); try { s2.setKey("S1"); fail("Should have thrown IndexOutOfBoundsException on negative key"); } catch (IllegalArgumentException e) { assertEquals("java.beans.PropertyVetoException: Duplicate key", e.getMessage()); } } /** * A test to cover bug 3445507. The issue does not affect * XYSeriesCollection. */ @Test public void testBug3445507() { XYSeries s1 = new XYSeries("S1"); s1.add(1.0, null); s1.add(2.0, null); XYSeries s2 = new XYSeries("S2"); s1.add(1.0, 5.0); s1.add(2.0, 6.0); XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(s1); dataset.addSeries(s2); Range r = dataset.getRangeBounds(false); assertEquals(5.0, r.getLowerBound(), EPSILON); assertEquals(6.0, r.getUpperBound(), EPSILON); } /** * Test that a series belonging to a collection can be renamed (in fact, * because of a bug this was not possible in JFreeChart 1.0.14). */ @Test public void testSeriesRename() { // first check that a valid renaming works XYSeries series1 = new XYSeries("A"); XYSeries series2 = new XYSeries("B"); XYSeriesCollection collection = new XYSeriesCollection(); collection.addSeries(series1); collection.addSeries(series2); series1.setKey("C"); assertEquals("C", collection.getSeries(0).getKey()); // next, check that setting a duplicate key fails try { series2.setKey("C"); fail("Expected an IllegalArgumentException."); } catch (IllegalArgumentException e) { // expected } assertEquals("B", series2.getKey()); // the series name should not // change because "C" is already the key for the other series in the // collection } }
18,282
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
VectorDataItemTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/xy/VectorDataItemTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------ * VectorDataItemTests.java * ------------------------ * (C) Copyright 2007, 2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 30-Jan-2007 : Version 1 (DG); * */ package org.jfree.data.xy; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; /** * Tests for the {@link VectorDataItem} class. */ public class VectorDataItemTest { /** * Test that the equals() method distinguishes all fields. */ @Test public void testEquals() { // default instances VectorDataItem v1 = new VectorDataItem(1.0, 2.0, 3.0, 4.0); VectorDataItem v2 = new VectorDataItem(1.0, 2.0, 3.0, 4.0); assertEquals(v1, v2); assertEquals(v2, v1); v1 = new VectorDataItem(1.1, 2.0, 3.0, 4.0); assertFalse(v1.equals(v2)); v2 = new VectorDataItem(1.1, 2.0, 3.0, 4.0); assertEquals(v1, v2); v1 = new VectorDataItem(1.1, 2.2, 3.0, 4.0); assertFalse(v1.equals(v2)); v2 = new VectorDataItem(1.1, 2.2, 3.0, 4.0); assertEquals(v1, v2); v1 = new VectorDataItem(1.1, 2.2, 3.3, 4.0); assertFalse(v1.equals(v2)); v2 = new VectorDataItem(1.1, 2.2, 3.3, 4.0); assertEquals(v1, v2); v1 = new VectorDataItem(1.1, 2.2, 3.3, 4.4); assertFalse(v1.equals(v2)); v2 = new VectorDataItem(1.1, 2.2, 3.3, 4.4); assertEquals(v1, v2); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashcode() { VectorDataItem v1 = new VectorDataItem(1.0, 2.0, 3.0, 4.0); VectorDataItem v2 = new VectorDataItem(1.0, 2.0, 3.0, 4.0); assertEquals(v1, v2); int h1 = v1.hashCode(); int h2 = v2.hashCode(); assertEquals(h1, h2); } /** * Check cloning. */ @Test public void testCloning() throws CloneNotSupportedException { VectorDataItem v1 = new VectorDataItem(1.0, 2.0, 3.0, 4.0); VectorDataItem v2 = (VectorDataItem) v1.clone(); assertNotSame(v1, v2); assertSame(v1.getClass(), v2.getClass()); assertEquals(v1, v2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { VectorDataItem v1 = new VectorDataItem(1.0, 2.0, 3.0, 4.0); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(v1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); VectorDataItem v2 = (VectorDataItem) in.readObject(); in.close(); assertEquals(v1, v2); } }
4,585
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
VectorSeriesCollectionTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/xy/VectorSeriesCollectionTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------------------- * VectorSeriesCollectionTests.java * -------------------------------- * (C) Copyright 2007-2012, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 30-Jan-2007 : Version 1 (DG); * 24-May-2007 : Added testRemoveSeries() (DG); * 22-Apr-2008 : Added testPublicCloneable (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.data.xy; import org.jfree.chart.util.PublicCloneable; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for the {@link VectorSeriesCollection} class. */ public class VectorSeriesCollectionTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { VectorSeries s1 = new VectorSeries("Series"); s1.add(1.0, 1.1, 1.2, 1.3); VectorSeriesCollection c1 = new VectorSeriesCollection(); c1.addSeries(s1); VectorSeries s2 = new VectorSeries("Series"); s2.add(1.0, 1.1, 1.2, 1.3); VectorSeriesCollection c2 = new VectorSeriesCollection(); c2.addSeries(s2); assertEquals(c1, c2); assertEquals(c2, c1); c1.addSeries(new VectorSeries("Empty Series")); assertFalse(c1.equals(c2)); c2.addSeries(new VectorSeries("Empty Series")); assertEquals(c1, c2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { VectorSeries s1 = new VectorSeries("Series"); s1.add(1.0, 1.1, 1.2, 1.3); VectorSeriesCollection c1 = new VectorSeriesCollection(); c1.addSeries(s1); VectorSeriesCollection c2 = (VectorSeriesCollection) c1.clone(); assertNotSame(c1, c2); assertSame(c1.getClass(), c2.getClass()); assertEquals(c1, c2); // check independence s1.setDescription("XYZ"); assertFalse(c1.equals(c2)); } /** * Verify that this class implements {@link PublicCloneable}. */ @Test public void testPublicCloneable() { VectorSeriesCollection d1 = new VectorSeriesCollection(); assertTrue(d1 instanceof PublicCloneable); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { VectorSeries s1 = new VectorSeries("Series"); s1.add(1.0, 1.1, 1.2, 1.3); VectorSeriesCollection c1 = new VectorSeriesCollection(); c1.addSeries(s1); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(c1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); VectorSeriesCollection c2 = (VectorSeriesCollection) in.readObject(); in.close(); assertEquals(c1, c2); } /** * Some checks for the removeSeries() method. */ @Test public void testRemoveSeries() { VectorSeries s1 = new VectorSeries("S1"); VectorSeries s2 = new VectorSeries("S2"); VectorSeriesCollection vsc = new VectorSeriesCollection(); vsc.addSeries(s1); vsc.addSeries(s2); assertEquals(2, vsc.getSeriesCount()); boolean b = vsc.removeSeries(s1); assertTrue(b); assertEquals(1, vsc.getSeriesCount()); assertEquals("S2", vsc.getSeriesKey(0)); b = vsc.removeSeries(new VectorSeries("NotInDataset")); assertFalse(b); assertEquals(1, vsc.getSeriesCount()); b = vsc.removeSeries(s2); assertTrue(b); assertEquals(0, vsc.getSeriesCount()); } }
5,578
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultHighLowDatasetTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/xy/DefaultHighLowDatasetTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------------- * DefaultHighLowDatasetTests.java * ------------------------------- * (C) Copyright 2006-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 28-Nov-2006 : Version 1 (DG); * 22-Apr-2008 : Added testPublicCloneable (DG); * */ package org.jfree.data.xy; import org.jfree.chart.util.PublicCloneable; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.Date; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for the {@link DefaultHighLowDataset} class. */ public class DefaultHighLowDatasetTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { DefaultHighLowDataset d1 = new DefaultHighLowDataset("Series 1", new Date[0], new double[0], new double[0], new double[0], new double[0], new double[0]); DefaultHighLowDataset d2 = new DefaultHighLowDataset("Series 1", new Date[0], new double[0], new double[0], new double[0], new double[0], new double[0]); assertEquals(d1, d2); assertEquals(d2, d1); d1 = new DefaultHighLowDataset("Series 2", new Date[0], new double[0], new double[0], new double[0], new double[0], new double[0]); assertFalse(d1.equals(d2)); d2 = new DefaultHighLowDataset("Series 2", new Date[0], new double[0], new double[0], new double[0], new double[0], new double[0]); assertEquals(d1, d2); d1 = new DefaultHighLowDataset("Series 2", new Date[] {new Date(123L)}, new double[1], new double[1], new double[1], new double[1], new double[1]); assertFalse(d1.equals(d2)); d2 = new DefaultHighLowDataset("Series 2", new Date[] {new Date(123L)}, new double[1], new double[1], new double[1], new double[1], new double[1]); assertEquals(d1, d2); d1 = new DefaultHighLowDataset("Series 2", new Date[] {new Date(123L)}, new double[] {1.2}, new double[1], new double[1], new double[1], new double[1]); assertFalse(d1.equals(d2)); d2 = new DefaultHighLowDataset("Series 2", new Date[] {new Date(123L)}, new double[] {1.2}, new double[1], new double[1], new double[1], new double[1]); assertEquals(d1, d2); d1 = new DefaultHighLowDataset("Series 2", new Date[] {new Date(123L)}, new double[] {1.2}, new double[] {3.4}, new double[1], new double[1], new double[1]); assertFalse(d1.equals(d2)); d2 = new DefaultHighLowDataset("Series 2", new Date[] {new Date(123L)}, new double[] {1.2}, new double[] {3.4}, new double[1], new double[1], new double[1]); assertEquals(d1, d2); d1 = new DefaultHighLowDataset("Series 2", new Date[] {new Date(123L)}, new double[] {1.2}, new double[] {3.4}, new double[] {5.6}, new double[1], new double[1]); assertFalse(d1.equals(d2)); d2 = new DefaultHighLowDataset("Series 2", new Date[] {new Date(123L)}, new double[] {1.2}, new double[] {3.4}, new double[] {5.6}, new double[1], new double[1]); assertEquals(d1, d2); d1 = new DefaultHighLowDataset("Series 2", new Date[] {new Date(123L)}, new double[] {1.2}, new double[] {3.4}, new double[] {5.6}, new double[] {7.8}, new double[1]); assertFalse(d1.equals(d2)); d2 = new DefaultHighLowDataset("Series 2", new Date[] {new Date(123L)}, new double[] {1.2}, new double[] {3.4}, new double[] {5.6}, new double[] {7.8}, new double[1]); assertEquals(d1, d2); d1 = new DefaultHighLowDataset("Series 2", new Date[] {new Date(123L)}, new double[] {1.2}, new double[] {3.4}, new double[] {5.6}, new double[] {7.8}, new double[] {99.9}); assertFalse(d1.equals(d2)); d2 = new DefaultHighLowDataset("Series 2", new Date[] {new Date(123L)}, new double[] {1.2}, new double[] {3.4}, new double[] {5.6}, new double[] {7.8}, new double[] {99.9}); assertEquals(d1, d2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { DefaultHighLowDataset d1 = new DefaultHighLowDataset("Series 1", new Date[] {new Date(123L)}, new double[] {1.2}, new double[] {3.4}, new double[] {5.6}, new double[] {7.8}, new double[] {99.9}); DefaultHighLowDataset d2 = (DefaultHighLowDataset) d1.clone(); assertNotSame(d1, d2); assertSame(d1.getClass(), d2.getClass()); assertEquals(d1, d2); } /** * Verify that this class implements {@link PublicCloneable}. */ @Test public void testPublicCloneable() { DefaultHighLowDataset d1 = new DefaultHighLowDataset("Series 1", new Date[0], new double[0], new double[0], new double[0], new double[0], new double[0]); assertTrue(d1 instanceof PublicCloneable); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { DefaultHighLowDataset d1 = new DefaultHighLowDataset("Series 1", new Date[] {new Date(123L)}, new double[] {1.2}, new double[] {3.4}, new double[] {5.6}, new double[] {7.8}, new double[] {99.9}); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); DefaultHighLowDataset d2 = (DefaultHighLowDataset) in.readObject(); in.close(); assertEquals(d1, d2); } }
8,065
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
YIntervalDataItemTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/xy/YIntervalDataItemTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------------- * YIntervalDataItemTests.java * --------------------------- * (C) Copyright 2006-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 20-Oct-2006 : Version 1 (DG); * */ package org.jfree.data.xy; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; /** * Tests for the {@link YIntervalDataItem} class. */ public class YIntervalDataItemTest { private static final double EPSILON = 0.00000000001; /** * Some checks for the constructor. */ @Test public void testConstructor1() { YIntervalDataItem item1 = new YIntervalDataItem(1.0, 2.0, 3.0, 4.0); assertEquals(new Double(1.0), item1.getX()); assertEquals(2.0, item1.getYValue(), EPSILON); assertEquals(3.0, item1.getYLowValue(), EPSILON); assertEquals(4.0, item1.getYHighValue(), EPSILON); } /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { YIntervalDataItem item1 = new YIntervalDataItem(1.0, 2.0, 1.5, 2.5); YIntervalDataItem item2 = new YIntervalDataItem(1.0, 2.0, 1.5, 2.5); assertEquals(item1, item2); assertEquals(item2, item1); // x item1 = new YIntervalDataItem(1.1, 2.0, 1.5, 2.5); assertFalse(item1.equals(item2)); item2 = new YIntervalDataItem(1.1, 2.0, 1.5, 2.5); assertEquals(item1, item2); // y item1 = new YIntervalDataItem(1.1, 2.2, 1.5, 2.5); assertFalse(item1.equals(item2)); item2 = new YIntervalDataItem(1.1, 2.2, 1.5, 2.5); assertEquals(item1, item2); // yLow item1 = new YIntervalDataItem(1.1, 2.2, 1.55, 2.5); assertFalse(item1.equals(item2)); item2 = new YIntervalDataItem(1.1, 2.2, 1.55, 2.5); assertEquals(item1, item2); // yHigh item1 = new YIntervalDataItem(1.1, 2.2, 1.55, 2.55); assertFalse(item1.equals(item2)); item2 = new YIntervalDataItem(1.1, 2.2, 1.55, 2.55); assertEquals(item1, item2); } /** * Some checks for the clone() method. */ @Test public void testCloning() throws CloneNotSupportedException { YIntervalDataItem item1 = new YIntervalDataItem(1.0, 2.0, 1.5, 2.5); YIntervalDataItem item2 = (YIntervalDataItem) item1.clone(); assertNotSame(item1, item2); assertSame(item1.getClass(), item2.getClass()); assertEquals(item1, item2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { YIntervalDataItem item1 = new YIntervalDataItem(1.0, 2.0, 1.5, 2.5); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(item1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); YIntervalDataItem item2 = (YIntervalDataItem) in.readObject(); in.close(); assertEquals(item1, item2); } }
4,932
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
MatrixSeriesCollectionTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/xy/MatrixSeriesCollectionTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------------------- * MatrixSeriesCollectionTests.java * -------------------------------- * (C) Copyright 2006-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 27-Nov-2006 : Version 1 (DG); * 22-Apr-2008 : Added testPublicCloneable (DG); * */ package org.jfree.data.xy; import org.jfree.chart.util.PublicCloneable; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for the {@link MatrixSeriesCollection} class. */ public class MatrixSeriesCollectionTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { MatrixSeries s1 = new MatrixSeries("Series", 2, 3); s1.update(0, 0, 1.1); MatrixSeriesCollection c1 = new MatrixSeriesCollection(); c1.addSeries(s1); MatrixSeries s2 = new MatrixSeries("Series", 2, 3); s2.update(0, 0, 1.1); MatrixSeriesCollection c2 = new MatrixSeriesCollection(); c2.addSeries(s2); assertEquals(c1, c2); assertEquals(c2, c1); c1.addSeries(new MatrixSeries("Empty Series", 1, 1)); assertFalse(c1.equals(c2)); c2.addSeries(new MatrixSeries("Empty Series", 1, 1)); assertEquals(c1, c2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { MatrixSeries s1 = new MatrixSeries("Series", 2, 3); s1.update(0, 0, 1.1); MatrixSeriesCollection c1 = new MatrixSeriesCollection(); c1.addSeries(s1); MatrixSeriesCollection c2 = (MatrixSeriesCollection) c1.clone(); assertNotSame(c1, c2); assertSame(c1.getClass(), c2.getClass()); assertEquals(c1, c2); // check independence s1.setDescription("XYZ"); assertFalse(c1.equals(c2)); } /** * Verify that this class implements {@link PublicCloneable}. */ @Test public void testPublicCloneable() { MatrixSeriesCollection c1 = new MatrixSeriesCollection(); assertTrue(c1 instanceof PublicCloneable); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { MatrixSeries s1 = new MatrixSeries("Series", 2, 3); s1.update(0, 0, 1.1); MatrixSeriesCollection c1 = new MatrixSeriesCollection(); c1.addSeries(s1); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(c1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); MatrixSeriesCollection c2 = (MatrixSeriesCollection) in.readObject(); in.close(); assertEquals(c1, c2); } }
4,702
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYIntervalSeriesTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/xy/XYIntervalSeriesTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------------- * XYIntervalSeriesTests.java * -------------------------- * (C) Copyright 2006, 2007, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 20-Oct-2006 : Version 1, based on XYSeriesTests (DG); * 13-Feb-2007 : Added testValues() (DG); * 27-Nov-2007 : Added testClear() method (DG); * */ package org.jfree.data.xy; import org.jfree.data.general.SeriesChangeEvent; import org.jfree.data.general.SeriesChangeListener; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for the {@link XYIntervalSeries} class. */ public class XYIntervalSeriesTest implements SeriesChangeListener { SeriesChangeEvent lastEvent; /** * Records the last event. * * @param event the event. */ @Override public void seriesChanged(SeriesChangeEvent event) { this.lastEvent = event; } /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { XYIntervalSeries s1 = new XYIntervalSeries("s1"); XYIntervalSeries s2 = new XYIntervalSeries("s1"); assertEquals(s1, s2); // seriesKey s1 = new XYIntervalSeries("s2"); assertFalse(s1.equals(s2)); s2 = new XYIntervalSeries("s2"); assertEquals(s1, s2); // autoSort s1 = new XYIntervalSeries("s2", false, true); assertFalse(s1.equals(s2)); s2 = new XYIntervalSeries("s2", false, true); assertEquals(s1, s2); // allowDuplicateValues s1 = new XYIntervalSeries("s2", false, false); assertFalse(s1.equals(s2)); s2 = new XYIntervalSeries("s2", false, false); assertEquals(s1, s2); // add a value s1.add(1.0, 0.5, 1.5, 2.0, 1.9, 2.1); assertFalse(s1.equals(s2)); s2.add(1.0, 0.5, 1.5, 2.0, 1.9, 2.1); assertEquals(s2, s1); // add another value s1.add(2.0, 0.5, 1.5, 2.0, 1.9, 2.1); assertFalse(s1.equals(s2)); s2.add(2.0, 0.5, 1.5, 2.0, 1.9, 2.1); assertEquals(s2, s1); // remove a value s1.remove(1.0); assertFalse(s1.equals(s2)); s2.remove(1.0); assertEquals(s2, s1); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { XYIntervalSeries s1 = new XYIntervalSeries("s1"); s1.add(1.0, 0.5, 1.5, 2.0, 1.9, 2.01); XYIntervalSeries s2 = (XYIntervalSeries) s1.clone(); assertNotSame(s1, s2); assertSame(s1.getClass(), s2.getClass()); assertEquals(s1, s2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { XYIntervalSeries s1 = new XYIntervalSeries("s1"); s1.add(1.0, 0.5, 1.5, 2.0, 1.9, 2.1); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(s1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); XYIntervalSeries s2 = (XYIntervalSeries) in.readObject(); in.close(); assertEquals(s1, s2); } /** * Simple test for the indexOf() method. */ @Test public void testIndexOf() { XYIntervalSeries s1 = new XYIntervalSeries("Series 1"); s1.add(1.0, 1.0, 1.0, 2.0, 1.9, 2.1); s1.add(2.0, 2.0, 2.0, 3.0, 2.9, 3.1); s1.add(3.0, 3.0, 3.0, 4.0, 3.9, 4.1); assertEquals(0, s1.indexOf(1.0)); } /** * A check for the indexOf() method for an unsorted series. */ @Test public void testIndexOf2() { XYIntervalSeries s1 = new XYIntervalSeries("Series 1", false, true); s1.add(1.0, 1.0, 1.0, 2.0, 1.9, 2.1); s1.add(3.0, 3.0, 3.0, 3.0, 2.9, 3.1); s1.add(2.0, 2.0, 2.0, 2.0, 1.9, 2.1); assertEquals(0, s1.indexOf(1.0)); assertEquals(1, s1.indexOf(3.0)); assertEquals(2, s1.indexOf(2.0)); } /** * Simple test for the remove() method. */ @Test public void testRemove() { XYIntervalSeries s1 = new XYIntervalSeries("Series 1"); s1.add(1.0, 1.0, 1.0, 2.0, 1.9, 2.1); s1.add(2.0, 2.0, 2.0, 2.0, 1.9, 2.1); s1.add(3.0, 3.0, 3.0, 3.0, 2.9, 3.1); assertEquals(3, s1.getItemCount()); s1.remove(2.0); assertEquals(3.0, s1.getX(1)); s1.remove(1.0); assertEquals(3.0, s1.getX(0)); } private static final double EPSILON = 0.0000000001; /** * When items are added with duplicate x-values, we expect them to remain * in the order they were added. */ @Test public void testAdditionOfDuplicateXValues() { XYIntervalSeries s1 = new XYIntervalSeries("Series 1"); s1.add(1.0, 1.0, 1.0, 1.0, 1.0, 1.0); s1.add(2.0, 2.0, 2.0, 2.0, 2.0, 2.0); s1.add(2.0, 3.0, 3.0, 3.0, 3.0, 3.0); s1.add(2.0, 4.0, 4.0, 4.0, 4.0, 4.0); s1.add(3.0, 5.0, 5.0, 5.0, 5.0, 5.0); assertEquals(1.0, s1.getYValue(0), EPSILON); assertEquals(2.0, s1.getYValue(1), EPSILON); assertEquals(3.0, s1.getYValue(2), EPSILON); assertEquals(4.0, s1.getYValue(3), EPSILON); assertEquals(5.0, s1.getYValue(4), EPSILON); } /** * Some checks for the add() method for an UNSORTED series. */ @Test public void testAdd() { XYIntervalSeries series = new XYIntervalSeries("Series", false, true); series.add(5.0, 5.50, 5.50, 5.50, 5.50, 5.50); series.add(5.1, 5.51, 5.51, 5.51, 5.51, 5.51); series.add(6.0, 6.6, 6.6, 6.6, 6.6, 6.6); series.add(3.0, 3.3, 3.3, 3.3, 3.3, 3.3); series.add(4.0, 4.4, 4.4, 4.4, 4.4, 4.4); series.add(2.0, 2.2, 2.2, 2.2, 2.2, 2.2); series.add(1.0, 1.1, 1.1, 1.1, 1.1, 1.1); assertEquals(5.5, series.getYValue(0), EPSILON); assertEquals(5.51, series.getYValue(1), EPSILON); assertEquals(6.6, series.getYValue(2), EPSILON); assertEquals(3.3, series.getYValue(3), EPSILON); assertEquals(4.4, series.getYValue(4), EPSILON); assertEquals(2.2, series.getYValue(5), EPSILON); assertEquals(1.1, series.getYValue(6), EPSILON); } /** * A simple check that the maximumItemCount attribute is working. */ @Test public void testSetMaximumItemCount() { XYIntervalSeries s1 = new XYIntervalSeries("S1"); assertEquals(Integer.MAX_VALUE, s1.getMaximumItemCount()); s1.setMaximumItemCount(2); assertEquals(2, s1.getMaximumItemCount()); s1.add(1.0, 1.1, 1.1, 1.1, 1.1, 1.1); s1.add(2.0, 2.2, 2.2, 2.2, 2.2, 2.2); s1.add(3.0, 3.3, 3.3, 3.3, 3.3, 3.3); assertEquals(2.0, s1.getX(0).doubleValue(), EPSILON); assertEquals(3.0, s1.getX(1).doubleValue(), EPSILON); } /** * Check that the maximum item count can be applied retrospectively. */ @Test public void testSetMaximumItemCount2() { XYIntervalSeries s1 = new XYIntervalSeries("S1"); s1.add(1.0, 1.1, 1.1, 1.1, 1.1, 1.1); s1.add(2.0, 2.2, 2.2, 2.2, 2.2, 2.2); s1.add(3.0, 3.3, 3.3, 3.3, 2.2, 2.2); s1.setMaximumItemCount(2); assertEquals(2.0, s1.getX(0).doubleValue(), EPSILON); assertEquals(3.0, s1.getX(1).doubleValue(), EPSILON); } /** * Some checks for the new accessor methods added in 1.0.5. */ @Test public void testValues() { XYIntervalSeries s1 = new XYIntervalSeries("S1"); s1.add(2.0, 1.0, 3.0, 5.0, 4.0, 6.0); assertEquals(2.0, s1.getX(0).doubleValue(), EPSILON); assertEquals(1.0, s1.getXLowValue(0), EPSILON); assertEquals(3.0, s1.getXHighValue(0), EPSILON); assertEquals(5.0, s1.getYValue(0), EPSILON); assertEquals(4.0, s1.getYLowValue(0), EPSILON); assertEquals(6.0, s1.getYHighValue(0), EPSILON); } /** * Some checks for the clear() method. */ @Test public void testClear() { XYIntervalSeries s1 = new XYIntervalSeries("S1"); s1.addChangeListener(this); s1.clear(); assertNull(this.lastEvent); assertTrue(s1.isEmpty()); s1.add(1.0, 2.0, 3.0, 4.0, 5.0, 6.0); assertFalse(s1.isEmpty()); s1.clear(); assertNotNull(this.lastEvent); assertTrue(s1.isEmpty()); } }
10,456
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYIntervalDataItemTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/xy/XYIntervalDataItemTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------------- * XYIntervalDataItemTests.java * ---------------------------- * (C) Copyright 2006-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 20-Oct-2006 : Version 1 (DG); * */ package org.jfree.data.xy; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; /** * Tests for the {@link XYIntervalDataItem} class. */ public class XYIntervalDataItemTest { private static final double EPSILON = 0.000000001; /** * Some checks for the constructor. */ @Test public void testConstructor1() { XYIntervalDataItem item1 = new XYIntervalDataItem(1.0, 0.5, 1.5, 2.0, 1.9, 2.1); assertEquals(new Double(1.0), item1.getX()); assertEquals(0.5, item1.getXLowValue(), EPSILON); assertEquals(1.5, item1.getXHighValue(), EPSILON); assertEquals(2.0, item1.getYValue(), EPSILON); assertEquals(1.9, item1.getYLowValue(), EPSILON); assertEquals(2.1, item1.getYHighValue(), EPSILON); } /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { XYIntervalDataItem item1 = new XYIntervalDataItem(1.0, 0.5, 1.5, 2.0, 1.9, 2.1); XYIntervalDataItem item2 = new XYIntervalDataItem(1.0, 0.5, 1.5, 2.0, 1.9, 2.1); assertEquals(item1, item2); assertEquals(item2, item1); // x item1 = new XYIntervalDataItem(1.1, 0.5, 1.5, 2.0, 1.9, 2.1); assertFalse(item1.equals(item2)); item2 = new XYIntervalDataItem(1.1, 0.5, 1.5, 2.0, 1.9, 2.1); assertEquals(item1, item2); // xLow item1 = new XYIntervalDataItem(1.1, 0.55, 1.5, 2.0, 1.9, 2.1); assertFalse(item1.equals(item2)); item2 = new XYIntervalDataItem(1.1, 0.55, 1.5, 2.0, 1.9, 2.1); assertEquals(item1, item2); // xHigh item1 = new XYIntervalDataItem(1.1, 0.55, 1.55, 2.0, 1.9, 2.1); assertFalse(item1.equals(item2)); item2 = new XYIntervalDataItem(1.1, 0.55, 1.55, 2.0, 1.9, 2.1); assertEquals(item1, item2); // y item1 = new XYIntervalDataItem(1.1, 0.55, 1.55, 2.2, 1.9, 2.1); assertFalse(item1.equals(item2)); item2 = new XYIntervalDataItem(1.1, 0.55, 1.55, 2.2, 1.9, 2.1); assertEquals(item1, item2); // yLow item1 = new XYIntervalDataItem(1.1, 0.55, 1.55, 2.2, 1.99, 2.1); assertFalse(item1.equals(item2)); item2 = new XYIntervalDataItem(1.1, 0.55, 1.55, 2.2, 1.99, 2.1); assertEquals(item1, item2); // yHigh item1 = new XYIntervalDataItem(1.1, 0.55, 1.55, 2.2, 1.99, 2.11); assertFalse(item1.equals(item2)); item2 = new XYIntervalDataItem(1.1, 0.55, 1.55, 2.2, 1.99, 2.11); assertEquals(item1, item2); } /** * Some checks for the clone() method. */ @Test public void testCloning() throws CloneNotSupportedException { XYIntervalDataItem item1 = new XYIntervalDataItem(1.0, 0.5, 1.5, 2.0, 1.9, 2.1); XYIntervalDataItem item2 = (XYIntervalDataItem) item1.clone(); assertNotSame(item1, item2); assertSame(item1.getClass(), item2.getClass()); assertEquals(item1, item2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { XYIntervalDataItem item1 = new XYIntervalDataItem(1.0, 0.5, 1.5, 2.0, 1.9, 2.1); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(item1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); XYIntervalDataItem item2 = (XYIntervalDataItem) in.readObject(); in.close(); assertEquals(item1, item2); } }
5,772
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultOHLCDatasetTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/xy/DefaultOHLCDatasetTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------------- * DefaultOHLCDatasetTests.java * ---------------------------- * (C) Copyright 2005-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 29-Apr-2005 : Version 1 (DG); * 28-Nov-2006 : Extended equals() test (DG); * 22-Apr-2008 : Added testPublicCloneable (DG); * */ package org.jfree.data.xy; import org.jfree.chart.util.PublicCloneable; import org.jfree.data.Range; import org.jfree.data.general.DatasetUtilities; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.Date; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for the {@link DefaultOHLCDataset} class. */ public class DefaultOHLCDatasetTest { private static final double EPSILON = 0.0000000001; /** * A small test for the data range calculated on this dataset. */ @Test public void testDataRange() { OHLCDataItem[] data = new OHLCDataItem[3]; data[0] = new OHLCDataItem(new Date(11L), 2.0, 4.0, 1.0, 3.0, 100.0); data[1] = new OHLCDataItem(new Date(22L), 4.0, 9.0, 2.0, 5.0, 120.0); data[2] = new OHLCDataItem(new Date(33L), 3.0, 7.0, 3.0, 6.0, 140.0); DefaultOHLCDataset d = new DefaultOHLCDataset("S1", data); Range r = DatasetUtilities.findRangeBounds(d, true); assertEquals(1.0, r.getLowerBound(), EPSILON); assertEquals(9.0, r.getUpperBound(), EPSILON); } /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { DefaultOHLCDataset d1 = new DefaultOHLCDataset("Series 1", new OHLCDataItem[0]); DefaultOHLCDataset d2 = new DefaultOHLCDataset("Series 1", new OHLCDataItem[0]); assertEquals(d1, d2); assertEquals(d2, d1); d1 = new DefaultOHLCDataset("Series 2", new OHLCDataItem[0]); assertFalse(d1.equals(d2)); d2 = new DefaultOHLCDataset("Series 2", new OHLCDataItem[0]); assertEquals(d1, d2); d1 = new DefaultOHLCDataset("Series 2", new OHLCDataItem[] { new OHLCDataItem(new Date(123L), 1.2, 3.4, 5.6, 7.8, 99.9)}); assertFalse(d1.equals(d2)); d2 = new DefaultOHLCDataset("Series 2", new OHLCDataItem[] { new OHLCDataItem(new Date(123L), 1.2, 3.4, 5.6, 7.8, 99.9)}); assertEquals(d1, d2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { DefaultOHLCDataset d1 = new DefaultOHLCDataset("Series 1", new OHLCDataItem[0]); DefaultOHLCDataset d2 = (DefaultOHLCDataset) d1.clone(); assertNotSame(d1, d2); assertSame(d1.getClass(), d2.getClass()); assertEquals(d1, d2); } /** * Confirm that cloning works. */ @Test public void testCloning2() throws CloneNotSupportedException { OHLCDataItem item1 = new OHLCDataItem(new Date(1L), 1.0, 2.0, 3.0, 4.0, 5.0); OHLCDataItem item2 = new OHLCDataItem(new Date(2L), 6.0, 7.0, 8.0, 9.0, 10.0); // create an array of items in reverse order OHLCDataItem[] items = new OHLCDataItem[] {item2, item1}; DefaultOHLCDataset d1 = new DefaultOHLCDataset("Series 1", items); DefaultOHLCDataset d2 = (DefaultOHLCDataset) d1.clone(); assertNotSame(d1, d2); assertSame(d1.getClass(), d2.getClass()); assertEquals(d1, d2); d1.sortDataByDate(); assertFalse(d1.equals(d2)); } /** * Verify that this class implements {@link PublicCloneable}. */ @Test public void testPublicCloneable() { DefaultOHLCDataset d1 = new DefaultOHLCDataset("Series 1", new OHLCDataItem[0]); assertTrue(d1 instanceof PublicCloneable); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { DefaultOHLCDataset d1 = new DefaultOHLCDataset("Series 1", new OHLCDataItem[0]); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); DefaultOHLCDataset d2 = (DefaultOHLCDataset) in.readObject(); in.close(); assertEquals(d1, d2); } }
6,318
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XIntervalSeriesTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/xy/XIntervalSeriesTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------- * XIntervalSeriesTests.java * ------------------------- * (C) Copyright 2006-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 20-Oct-2006 : Version 1, based on XYSeriesTests (DG); * 27-Nov-2007 : Added testClear() method (DG); * 10-Apr-2008 : Added testGetXLowValue() and testGetXHighValue() (DG); * */ package org.jfree.data.xy; import org.jfree.data.general.SeriesChangeEvent; import org.jfree.data.general.SeriesChangeListener; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for the {@link XIntervalSeries} class. */ public class XIntervalSeriesTest implements SeriesChangeListener { SeriesChangeEvent lastEvent; /** * Records the last event. * * @param event the event. */ @Override public void seriesChanged(SeriesChangeEvent event) { this.lastEvent = event; } /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { XIntervalSeries s1 = new XIntervalSeries("s1"); XIntervalSeries s2 = new XIntervalSeries("s1"); assertEquals(s1, s2); // seriesKey s1 = new XIntervalSeries("s2"); assertFalse(s1.equals(s2)); s2 = new XIntervalSeries("s2"); assertEquals(s1, s2); // autoSort s1 = new XIntervalSeries("s2", false, true); assertFalse(s1.equals(s2)); s2 = new XIntervalSeries("s2", false, true); assertEquals(s1, s2); // allowDuplicateValues s1 = new XIntervalSeries("s2", false, false); assertFalse(s1.equals(s2)); s2 = new XIntervalSeries("s2", false, false); assertEquals(s1, s2); // add a value s1.add(1.0, 0.5, 1.5, 2.0); assertFalse(s1.equals(s2)); s2.add(1.0, 0.5, 1.5, 2.0); assertEquals(s2, s1); // add another value s1.add(2.0, 0.5, 1.5, 2.0); assertFalse(s1.equals(s2)); s2.add(2.0, 0.5, 1.5, 2.0); assertEquals(s2, s1); // remove a value s1.remove(1.0); assertFalse(s1.equals(s2)); s2.remove(1.0); assertEquals(s2, s1); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { XIntervalSeries s1 = new XIntervalSeries("s1"); s1.add(1.0, 0.5, 1.5, 2.0); XIntervalSeries s2 = (XIntervalSeries) s1.clone(); assertNotSame(s1, s2); assertSame(s1.getClass(), s2.getClass()); assertEquals(s1, s2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { XIntervalSeries s1 = new XIntervalSeries("s1"); s1.add(1.0, 0.5, 1.5, 2.0); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(s1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); XIntervalSeries s2 = (XIntervalSeries) in.readObject(); in.close(); assertEquals(s1, s2); } /** * Simple test for the indexOf() method. */ @Test public void testIndexOf() { XIntervalSeries s1 = new XIntervalSeries("Series 1"); s1.add(1.0, 1.0, 1.0, 2.0); s1.add(2.0, 2.0, 2.0, 3.0); s1.add(3.0, 3.0, 3.0, 4.0); assertEquals(0, s1.indexOf(1.0)); } /** * A check for the indexOf() method for an unsorted series. */ @Test public void testIndexOf2() { XIntervalSeries s1 = new XIntervalSeries("Series 1", false, true); s1.add(1.0, 1.0, 1.0, 2.0); s1.add(3.0, 3.0, 3.0, 3.0); s1.add(2.0, 2.0, 2.0, 2.0); assertEquals(0, s1.indexOf(1.0)); assertEquals(1, s1.indexOf(3.0)); assertEquals(2, s1.indexOf(2.0)); } /** * Simple test for the remove() method. */ @Test public void testRemove() { XIntervalSeries s1 = new XIntervalSeries("Series 1"); s1.add(1.0, 1.0, 1.0, 2.0); s1.add(2.0, 2.0, 2.0, 2.0); s1.add(3.0, 3.0, 3.0, 3.0); assertEquals(3, s1.getItemCount()); s1.remove(2.0); assertEquals(3.0, s1.getX(1)); s1.remove(1.0); assertEquals(3.0, s1.getX(0)); } private static final double EPSILON = 0.0000000001; /** * When items are added with duplicate x-values, we expect them to remain * in the order they were added. */ @Test public void testAdditionOfDuplicateXValues() { XIntervalSeries s1 = new XIntervalSeries("Series 1"); s1.add(1.0, 1.0, 1.0, 1.0); s1.add(2.0, 2.0, 2.0, 2.0); s1.add(2.0, 3.0, 3.0, 3.0); s1.add(2.0, 4.0, 4.0, 4.0); s1.add(3.0, 5.0, 5.0, 5.0); assertEquals(1.0, s1.getYValue(0), EPSILON); assertEquals(2.0, s1.getYValue(1), EPSILON); assertEquals(3.0, s1.getYValue(2), EPSILON); assertEquals(4.0, s1.getYValue(3), EPSILON); assertEquals(5.0, s1.getYValue(4), EPSILON); } /** * Some checks for the add() method for an UNSORTED series. */ @Test public void testAdd() { XIntervalSeries series = new XIntervalSeries("Series", false, true); series.add(5.0, 5.50, 5.50, 5.50); series.add(5.1, 5.51, 5.51, 5.51); series.add(6.0, 6.6, 6.6, 6.6); series.add(3.0, 3.3, 3.3, 3.3); series.add(4.0, 4.4, 4.4, 4.4); series.add(2.0, 2.2, 2.2, 2.2); series.add(1.0, 1.1, 1.1, 1.1); assertEquals(5.5, series.getYValue(0), EPSILON); assertEquals(5.51, series.getYValue(1), EPSILON); assertEquals(6.6, series.getYValue(2), EPSILON); assertEquals(3.3, series.getYValue(3), EPSILON); assertEquals(4.4, series.getYValue(4), EPSILON); assertEquals(2.2, series.getYValue(5), EPSILON); assertEquals(1.1, series.getYValue(6), EPSILON); } /** * A simple check that the maximumItemCount attribute is working. */ @Test public void testSetMaximumItemCount() { XIntervalSeries s1 = new XIntervalSeries("S1"); assertEquals(Integer.MAX_VALUE, s1.getMaximumItemCount()); s1.setMaximumItemCount(2); assertEquals(2, s1.getMaximumItemCount()); s1.add(1.0, 1.1, 1.1, 1.1); s1.add(2.0, 2.2, 2.2, 2.2); s1.add(3.0, 3.3, 3.3, 3.3); assertEquals(2.0, s1.getX(0).doubleValue(), EPSILON); assertEquals(3.0, s1.getX(1).doubleValue(), EPSILON); } /** * Check that the maximum item count can be applied retrospectively. */ @Test public void testSetMaximumItemCount2() { XIntervalSeries s1 = new XIntervalSeries("S1"); s1.add(1.0, 1.1, 1.1, 1.1); s1.add(2.0, 2.2, 2.2, 2.2); s1.add(3.0, 3.3, 3.3, 3.3); s1.setMaximumItemCount(2); assertEquals(2.0, s1.getX(0).doubleValue(), EPSILON); assertEquals(3.0, s1.getX(1).doubleValue(), EPSILON); } /** * Some checks for the clear() method. */ @Test public void testClear() { XIntervalSeries s1 = new XIntervalSeries("S1"); s1.addChangeListener(this); s1.clear(); assertNull(this.lastEvent); assertTrue(s1.isEmpty()); s1.add(1.0, 2.0, 3.0, 4.0); assertFalse(s1.isEmpty()); s1.clear(); assertNotNull(this.lastEvent); assertTrue(s1.isEmpty()); } /** * A simple check for getXLowValue(). */ @Test public void testGetXLowValue() { XIntervalSeries s1 = new XIntervalSeries("S1"); s1.add(1.0, 2.0, 3.0, 4.0); assertEquals(2.0, s1.getXLowValue(0), EPSILON); s1.add(2.0, 1.0, 4.0, 2.5); assertEquals(1.0, s1.getXLowValue(1), EPSILON); } /** * A simple check for getXHighValue(). */ @Test public void testGetXHighValue() { XIntervalSeries s1 = new XIntervalSeries("S1"); s1.add(1.0, 2.0, 3.0, 4.0); assertEquals(3.0, s1.getXHighValue(0), EPSILON); s1.add(2.0, 1.0, 4.0, 2.5); assertEquals(4.0, s1.getXHighValue(1), EPSILON); } }
10,233
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYIntervalSeriesCollectionTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/xy/XYIntervalSeriesCollectionTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------------------ * XYIntervalSeriesCollectionTests.java * ------------------------------------ * (C) Copyright 2006-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 20-Oct-2006 : Version 1 (DG); * 13-Feb-2007 : Check for independence in testCloning() (DG); * 18-Jan-2008 : Added testRemoveSeries() (DG); * 22-Apr-2008 : Added testPublicCloneable (DG); * */ package org.jfree.data.xy; import org.jfree.chart.util.PublicCloneable; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** * Tests for the {@link XYIntervalSeriesCollection} class. */ public class XYIntervalSeriesCollectionTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { XYIntervalSeriesCollection c1 = new XYIntervalSeriesCollection(); XYIntervalSeriesCollection c2 = new XYIntervalSeriesCollection(); assertEquals(c1, c2); // add a series XYIntervalSeries s1 = new XYIntervalSeries("Series"); s1.add(1.0, 1.1, 1.2, 1.3, 1.4, 1.5); c1.addSeries(s1); assertFalse(c1.equals(c2)); XYIntervalSeries s2 = new XYIntervalSeries("Series"); s2.add(1.0, 1.1, 1.2, 1.3, 1.4, 1.5); c2.addSeries(s2); assertEquals(c1, c2); // add an empty series c1.addSeries(new XYIntervalSeries("Empty Series")); assertFalse(c1.equals(c2)); c2.addSeries(new XYIntervalSeries("Empty Series")); assertEquals(c1, c2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { XYIntervalSeriesCollection c1 = new XYIntervalSeriesCollection(); XYIntervalSeries s1 = new XYIntervalSeries("Series"); s1.add(1.0, 1.1, 1.2, 1.3, 1.4, 1.5); XYIntervalSeriesCollection c2 = (XYIntervalSeriesCollection) c1.clone(); assertNotSame(c1, c2); assertSame(c1.getClass(), c2.getClass()); assertEquals(c1, c2); // check independence c1.addSeries(new XYIntervalSeries("Empty")); assertFalse(c1.equals(c2)); c2.addSeries(new XYIntervalSeries("Empty")); assertEquals(c1, c2); } /** * Verify that this class implements {@link PublicCloneable}. */ @Test public void testPublicCloneable() { XYIntervalSeriesCollection c1 = new XYIntervalSeriesCollection(); assertTrue(c1 instanceof PublicCloneable); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { XYIntervalSeriesCollection c1 = new XYIntervalSeriesCollection(); XYIntervalSeries s1 = new XYIntervalSeries("Series"); s1.add(1.0, 1.1, 1.2, 1.3, 1.4, 1.5); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(c1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); XYIntervalSeriesCollection c2 = (XYIntervalSeriesCollection) in.readObject(); in.close(); assertEquals(c1, c2); // check independence c1.addSeries(new XYIntervalSeries("Empty")); assertFalse(c1.equals(c2)); c2.addSeries(new XYIntervalSeries("Empty")); assertEquals(c1, c2); } /** * Some basic checks for the removeSeries() method. */ @Test public void testRemoveSeries() { XYIntervalSeriesCollection c = new XYIntervalSeriesCollection(); XYIntervalSeries s1 = new XYIntervalSeries("s1"); c.addSeries(s1); c.removeSeries(0); assertEquals(0, c.getSeriesCount()); c.addSeries(s1); try { c.removeSeries(-1); fail("IllegalArgumentException should have been thrown on negative key"); } catch (IllegalArgumentException e) { assertEquals("Series index out of bounds.", e.getMessage()); } try { c.removeSeries(1); fail("IllegalArgumentException should have been thrown on key out of range"); } catch (IllegalArgumentException e) { assertEquals("Series index out of bounds.", e.getMessage()); } } /** * A test for bug report 1170825 (originally affected XYSeriesCollection, * this test is just copied over). */ @Test public void test1170825() { XYIntervalSeries s1 = new XYIntervalSeries("Series1"); XYIntervalSeriesCollection dataset = new XYIntervalSeriesCollection(); dataset.addSeries(s1); try { /* XYSeries s = */ dataset.getSeries(1); fail("Should have thrown IllegalArgumentException on index out of bounds"); } catch (IllegalArgumentException e) { assertEquals("Series index out of bounds", e.getMessage()); } } }
6,909
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
VectorTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/xy/VectorTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------- * VectorTests.java * ---------------- * (C) Copyright 2007, 2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 30-Jan-2007 : Version 1 (DG); * */ package org.jfree.data.xy; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; /** * Tests for the {@link Vector} class. */ public class VectorTest { /** * Test that the equals() method distinguishes all fields. */ @Test public void testEquals() { // default instances Vector v1 = new Vector(1.0, 2.0); Vector v2 = new Vector(1.0, 2.0); assertEquals(v1, v2); assertEquals(v2, v1); v1 = new Vector(1.1, 2.0); assertFalse(v1.equals(v2)); v2 = new Vector(1.1, 2.0); assertEquals(v1, v2); v1 = new Vector(1.1, 2.2); assertFalse(v1.equals(v2)); v2 = new Vector(1.1, 2.2); assertEquals(v1, v2); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashcode() { Vector v1 = new Vector(1.0, 2.0); Vector v2 = new Vector(1.0, 2.0); assertEquals(v1, v2); int h1 = v1.hashCode(); int h2 = v2.hashCode(); assertEquals(h1, h2); } /** * Immutable class is not cloneable. */ @Test public void testCloning() throws CloneNotSupportedException { Vector v1 = new Vector(1.0, 2.0); assertFalse(v1 instanceof Cloneable); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { Vector v1 = new Vector(1.0, 2.0); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(v1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); Vector v2 = (Vector) in.readObject(); in.close(); assertEquals(v1, v2); } }
3,763
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TableXYDatasetTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/xy/TableXYDatasetTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------ * TableXYDatasetTests.java * ------------------------ * (C) Copyright 2003-2008, by Richard Atkinson and Contributors. * * Original Author: Richard Atkinson; * Contributor(s): David Gilbert (for Object Refinery Limited); * * Changes * ------- * 11-Aug-2003 : Version 1 (RA); * 18-Aug-2003 : Added tests for event notification when removing and updating * series (RA); * 22-Sep-2003 : Changed to recognise that empty values are now null rather * than zero (RA); * 16-Feb-2004 : Added some additional tests (DG); * 15-Jul-2004 : Switched getX() with getXValue() and getY() with * getYValue() (DG); * 02-Feb-2007 : Removed author tags all over JFreeChart sources (DG); * 22-Apr-2008 : Added testPublicCloneable (DG); * */ package org.jfree.data.xy; import org.jfree.chart.util.PublicCloneable; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for {@link DefaultTableXYDataset}. */ public class TableXYDatasetTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { DefaultTableXYDataset d1 = new DefaultTableXYDataset(); DefaultTableXYDataset d2 = new DefaultTableXYDataset(); assertEquals(d1, d2); assertEquals(d2, d1); d1.addSeries(createSeries1()); assertFalse(d1.equals(d2)); d2.addSeries(createSeries1()); assertEquals(d1, d2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { DefaultTableXYDataset d1 = new DefaultTableXYDataset(); d1.addSeries(createSeries1()); DefaultTableXYDataset d2 = (DefaultTableXYDataset) d1.clone(); assertNotSame(d1, d2); assertSame(d1.getClass(), d2.getClass()); assertEquals(d1, d2); } /** * Verify that this class implements {@link PublicCloneable}. */ @Test public void testPublicCloneable() { DefaultTableXYDataset d1 = new DefaultTableXYDataset(); assertTrue(d1 instanceof PublicCloneable); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { DefaultTableXYDataset d1 = new DefaultTableXYDataset(); d1.addSeries(createSeries2()); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); DefaultTableXYDataset d2 = (DefaultTableXYDataset) in.readObject(); in.close(); assertEquals(d1, d2); } /** * Assorted tests. */ @Test public void testTableXYDataset() { XYSeries series1 = createSeries1(); XYSeries series2 = createSeries2(); DefaultTableXYDataset dataset = new DefaultTableXYDataset(); dataset.addSeries(series1); dataset.addSeries(series2); // Test that there are 6 X points and some specific values assertEquals(6, dataset.getItemCount()); assertEquals(6, dataset.getX(0, 5).intValue()); assertEquals(null, dataset.getY(0, 5)); assertEquals(6, dataset.getX(1, 5).intValue()); assertEquals(2, dataset.getY(1, 5).intValue()); // after adding a point to a series, check that there are now 7 // items in each series series2.add(7, 2); assertEquals(7, dataset.getItemCount()); assertEquals(null, dataset.getY(0, 6)); assertEquals(2, dataset.getY(1, 6).intValue()); // Remove series 1 dataset.removeSeries(series1); // Test that there are still 7 X points assertEquals(7, dataset.getItemCount()); // Remove series 2 and add new series dataset.removeSeries(series2); series1 = createSeries1(); dataset.addSeries(series1); // Test that there are now 4 X points assertEquals(4, dataset.getItemCount()); } /** * A test for bug report 788597. */ @Test public void test788597() { DefaultTableXYDataset dataset = new DefaultTableXYDataset(); dataset.addSeries(createSeries1()); assertEquals(4, dataset.getItemCount()); dataset.removeAllSeries(); assertEquals(0, dataset.getItemCount()); } /** * Test that removing all values for a given x works. */ @Test public void testRemoveAllValuesForX() { DefaultTableXYDataset dataset = new DefaultTableXYDataset(); dataset.addSeries(createSeries1()); dataset.addSeries(createSeries2()); dataset.removeAllValuesForX(2.0); assertEquals(5, dataset.getItemCount()); assertEquals(1.0, dataset.getX(0, 0)); assertEquals(3.0, dataset.getX(0, 1)); assertEquals(4.0, dataset.getX(0, 2)); assertEquals(5.0, dataset.getX(0, 3)); assertEquals(6.0, dataset.getX(0, 4)); } /** * Tests to see that pruning removes unwanted x values. */ @Test public void testPrune() { DefaultTableXYDataset dataset = new DefaultTableXYDataset(); dataset.addSeries(createSeries1()); dataset.addSeries(createSeries2()); dataset.removeSeries(1); dataset.prune(); assertEquals(4, dataset.getItemCount()); } /** * Tests the auto-pruning feature. */ @Test public void testAutoPrune() { // WITH AUTOPRUNING DefaultTableXYDataset dataset = new DefaultTableXYDataset(true); dataset.addSeries(createSeriesA()); assertEquals(2, dataset.getItemCount()); // should be 2 items dataset.addSeries(createSeriesB()); assertEquals(2, dataset.getItemCount()); // still 2 dataset.removeSeries(1); assertEquals(1, dataset.getItemCount()); // 1 value pruned. // WITHOUT AUTOPRUNING DefaultTableXYDataset dataset2 = new DefaultTableXYDataset(true); dataset2.addSeries(createSeriesA()); assertEquals(2, dataset2.getItemCount()); // should be 2 items dataset2.addSeries(createSeriesB()); assertEquals(2, dataset2.getItemCount()); // still 2 dataset2.removeSeries(1); assertEquals(1, dataset2.getItemCount()); // still 2. } /** * Creates a series for testing. * * @return A series. */ private XYSeries createSeriesA() { XYSeries s = new XYSeries("A", true, false); s.add(1.0, 1.1); s.add(2.0, null); return s; } /** * Creates a series for testing. * * @return A series. */ private XYSeries createSeriesB() { XYSeries s = new XYSeries("B", true, false); s.add(1.0, null); s.add(2.0, 2.2); return s; } /** * Creates a series for testing. * * @return A series. */ private XYSeries createSeries1() { XYSeries series1 = new XYSeries("Series 1", true, false); series1.add(1.0, 1.0); series1.add(2.0, 1.0); series1.add(4.0, 1.0); series1.add(5.0, 1.0); return series1; } /** * Creates a series for testing. * * @return A series. */ private XYSeries createSeries2() { XYSeries series2 = new XYSeries("Series 2", true, false); series2.add(2.0, 2.0); series2.add(3.0, 2.0); series2.add(4.0, 2.0); series2.add(5.0, 2.0); series2.add(6.0, 2.0); return series2; } }
9,446
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
YIntervalTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/xy/YIntervalTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------- * YIntervalTests.java * ------------------- * (C) Copyright 2006-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 20-Oct-2006 : Version 1 (DG); * */ package org.jfree.data.xy; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; /** * Tests for the {@link YInterval} class. */ public class YIntervalTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { YInterval i1 = new YInterval(1.0, 0.5, 1.5); YInterval i2 = new YInterval(1.0, 0.5, 1.5); assertEquals(i1, i2); i1 = new YInterval(1.1, 0.5, 1.5); assertFalse(i1.equals(i2)); i2 = new YInterval(1.1, 0.5, 1.5); assertEquals(i1, i2); i1 = new YInterval(1.1, 0.55, 1.5); assertFalse(i1.equals(i2)); i2 = new YInterval(1.1, 0.55, 1.5); assertEquals(i1, i2); i1 = new YInterval(1.1, 0.55, 1.55); assertFalse(i1.equals(i2)); i2 = new YInterval(1.1, 0.55, 1.55); assertEquals(i1, i2); } /** * This class is immutable. */ @Test public void testCloning() throws CloneNotSupportedException { YInterval i1 = new YInterval(1.0, 0.5, 1.5); assertFalse(i1 instanceof Cloneable); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { YInterval i1 = new YInterval(1.0, 0.5, 1.5); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(i1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); YInterval i2 = (YInterval) in.readObject(); in.close(); assertEquals(i1, i2); } }
3,616
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultCategoryDatasetTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/category/DefaultCategoryDatasetTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------------------- * DefaultCategoryDatasetTests.java * -------------------------------- * (C) Copyright 2004-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 23-Mar-2004 : Version 1 (DG); * 08-Mar-2007 : Added testCloning() (DG); * 21-Nov-2007 : Added testBug1835955() method (DG); * 09-May-2008 : Added testPublicCloneable() (DG); * */ package org.jfree.data.category; import org.jfree.chart.util.PublicCloneable; import org.jfree.data.UnknownKeyException; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** * Tests for the {@link DefaultCategoryDataset} class. */ public class DefaultCategoryDatasetTest { /** * Some checks for the getValue() method. */ @Test public void testGetValue() { DefaultCategoryDataset d = new DefaultCategoryDataset(); d.addValue(1.0, "R1", "C1"); assertEquals(1.0, d.getValue("R1", "C1")); try { d.getValue("XX", "C1"); fail("UnknownKeyException should have been thrown on unknown key"); } catch (UnknownKeyException e) { assertEquals("Unrecognised rowKey: XX", e.getMessage()); } try { d.getValue("R1", "XX"); fail("UnknownKeyException should have been thrown on unknown key"); } catch (UnknownKeyException e) { assertEquals("Unrecognised columnKey: XX", e.getMessage()); } } /** * A simple check for the getValue(int, int) method. */ @Test public void testGetValue2() { DefaultCategoryDataset d = new DefaultCategoryDataset(); try { /* Number n =*/ d.getValue(0, 0); fail("IndexOutOfBoundsException should have been thrown on getting key from empty set"); } catch (IndexOutOfBoundsException e) { assertEquals("Index: 0, Size: 0", e.getMessage()); } } /** * Some checks for the incrementValue() method. */ @Test public void testIncrementValue() { DefaultCategoryDataset d = new DefaultCategoryDataset(); d.addValue(1.0, "R1", "C1"); d.incrementValue(2.0, "R1", "C1"); assertEquals(3.0, d.getValue("R1", "C1")); // increment a null value d.addValue(null, "R2", "C1"); d.incrementValue(2.0, "R2", "C1"); assertEquals(2.0, d.getValue("R2", "C1")); // increment an unknown row try { d.incrementValue(1.0, "XX", "C1"); fail("UnknownKeyException should have been thrown on unknown row"); } catch (UnknownKeyException e) { assertEquals("Unrecognised rowKey: XX", e.getMessage()); } // increment an unknown column try { d.incrementValue(1.0, "R1", "XX"); fail("UnknownKeyException should have been thrown on unknown row"); } catch (UnknownKeyException e) { assertEquals("Unrecognised columnKey: XX", e.getMessage()); } } /** * Some tests for the getRowCount() method. */ @Test public void testGetRowCount() { DefaultCategoryDataset d = new DefaultCategoryDataset(); assertSame(d.getRowCount(), 0); d.addValue(1.0, "R1", "C1"); assertSame(d.getRowCount(), 1); d.addValue(1.0, "R2", "C1"); assertSame(d.getRowCount(), 2); d.addValue(2.0, "R2", "C1"); assertSame(d.getRowCount(), 2); // a row of all null values is still counted... d.setValue(null, "R2", "C1"); assertSame(d.getRowCount(), 2); } /** * Some tests for the getColumnCount() method. */ @Test public void testGetColumnCount() { DefaultCategoryDataset d = new DefaultCategoryDataset(); assertSame(d.getColumnCount(), 0); d.addValue(1.0, "R1", "C1"); assertSame(d.getColumnCount(), 1); d.addValue(1.0, "R1", "C2"); assertSame(d.getColumnCount(), 2); d.addValue(2.0, "R1", "C2"); assertSame(d.getColumnCount(), 2); // a column of all null values is still counted... d.setValue(null, "R1", "C2"); assertSame(d.getColumnCount(), 2); } /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { DefaultCategoryDataset d1 = new DefaultCategoryDataset(); d1.setValue(23.4, "R1", "C1"); DefaultCategoryDataset d2 = new DefaultCategoryDataset(); d2.setValue(23.4, "R1", "C1"); assertEquals(d1, d2); assertEquals(d2, d1); d1.setValue(36.5, "R1", "C2"); assertFalse(d1.equals(d2)); d2.setValue(36.5, "R1", "C2"); assertEquals(d1, d2); d1.setValue(null, "R1", "C1"); assertFalse(d1.equals(d2)); d2.setValue(null, "R1", "C1"); assertEquals(d1, d2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { DefaultCategoryDataset d1 = new DefaultCategoryDataset(); d1.setValue(23.4, "R1", "C1"); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); DefaultCategoryDataset d2 = (DefaultCategoryDataset) in.readObject(); in.close(); assertEquals(d1, d2); } /** * Some checks for the addValue() method. */ @Test public void testAddValue() { DefaultCategoryDataset d1 = new DefaultCategoryDataset(); d1.addValue(null, "R1", "C1"); assertNull(d1.getValue("R1", "C1")); d1.addValue(new Double(1.0), "R2", "C1"); assertEquals(1.0, d1.getValue("R2", "C1")); try { d1.addValue(new Double(1.1), null, "C2"); fail("UnknownKeyException should have been thrown on unknown row"); } catch (IllegalArgumentException e) { assertEquals("Null 'key' argument.", e.getMessage()); } } /** * Some basic checks for the removeValue() method. */ @Test public void testRemoveValue() { DefaultCategoryDataset d = new DefaultCategoryDataset(); d.removeValue("R1", "C1"); d.addValue(new Double(1.0), "R1", "C1"); d.removeValue("R1", "C1"); assertEquals(0, d.getRowCount()); assertEquals(0, d.getColumnCount()); d.addValue(new Double(1.0), "R1", "C1"); d.addValue(new Double(2.0), "R2", "C1"); d.removeValue("R1", "C1"); assertEquals(2.0, d.getValue(0, 0)); try { d.removeValue(null, "C1"); fail("IllegalArgumentException should have been thrown on null key"); } catch (IllegalArgumentException e) { assertEquals("Null 'key' argument.", e.getMessage()); } try { d.removeValue("R1", null); fail("IllegalArgumentException should have been thrown on null key"); } catch (IllegalArgumentException e) { assertEquals("Null 'key' argument.", e.getMessage()); } } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { DefaultCategoryDataset d1 = new DefaultCategoryDataset(); DefaultCategoryDataset d2 = (DefaultCategoryDataset) d1.clone(); assertNotSame(d1, d2); assertSame(d1.getClass(), d2.getClass()); assertEquals(d1, d2); // try a dataset with some content... d1.addValue(1.0, "R1", "C1"); d1.addValue(2.0, "R1", "C2"); d2 = (DefaultCategoryDataset) d1.clone(); assertNotSame(d1, d2); assertSame(d1.getClass(), d2.getClass()); assertEquals(d1, d2); // check that the clone doesn't share the same underlying arrays. d1.addValue(3.0, "R1", "C1"); assertFalse(d1.equals(d2)); d2.addValue(3.0, "R1", "C1"); assertEquals(d1, d2); } /** * Check that this class implements PublicCloneable. */ @Test public void testPublicCloneable() { DefaultCategoryDataset d = new DefaultCategoryDataset(); assertTrue(d instanceof PublicCloneable); } private static final double EPSILON = 0.0000000001; /** * A test for bug 1835955. */ @Test public void testBug1835955() { DefaultCategoryDataset d = new DefaultCategoryDataset(); d.addValue(1.0, "R1", "C1"); d.addValue(2.0, "R2", "C2"); d.removeColumn("C2"); d.addValue(3.0, "R2", "C2"); assertEquals(3.0, d.getValue("R2", "C2").doubleValue(), EPSILON); } /** * Some checks for the removeColumn(Comparable) method. */ @Test public void testRemoveColumn() { DefaultCategoryDataset d = new DefaultCategoryDataset(); d.addValue(1.0, "R1", "C1"); d.addValue(2.0, "R2", "C2"); assertEquals(2, d.getColumnCount()); d.removeColumn("C2"); assertEquals(1, d.getColumnCount()); try { d.removeColumn("XXX"); fail("UnknownKeyException should have been thrown on unknown key"); } catch (UnknownKeyException e) { assertEquals("Unknown key: XXX", e.getMessage()); } try { d.removeColumn(null); fail("IllegalArgumentException should have been thrown on null key"); } catch (IllegalArgumentException e) { assertEquals("Null 'columnKey' argument.", e.getMessage()); } } /** * Some checks for the removeRow(Comparable) method. */ @Test public void testRemoveRow() { DefaultCategoryDataset d = new DefaultCategoryDataset(); d.addValue(1.0, "R1", "C1"); d.addValue(2.0, "R2", "C2"); assertEquals(2, d.getRowCount()); d.removeRow("R2"); assertEquals(1, d.getRowCount()); try { d.removeRow("XXX"); fail("UnknownKeyException should have been thrown on unknown key"); } catch (UnknownKeyException e) { assertEquals("Unknown key: XXX", e.getMessage()); } try { d.removeRow(null); fail("IllegalArgumentException should have been thrown on null key"); } catch (IllegalArgumentException e) { assertEquals("Null 'rowKey' argument.", e.getMessage()); } } }
12,638
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultIntervalCategoryDatasetTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/category/DefaultIntervalCategoryDatasetTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------------------------- * DefaultIntervalCategoryDatasetTests.java * ---------------------------------------- * (C) Copyright 2007-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 08-Mar-2007 : Version 1 (DG); * 25-Feb-2008 : Added new tests to check behaviour of an empty dataset (DG); * 11-Feb-2009 : Fixed locale-sensitive failures (DG); * */ package org.jfree.data.category; import org.jfree.data.DataUtilities; import org.jfree.data.UnknownKeyException; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.List; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; /** * Tests for the {@link DefaultIntervalCategoryDataset} class. */ public class DefaultIntervalCategoryDatasetTest { /** * Some checks for the getValue() method. */ @Test public void testGetValue() { double[] starts_S1 = new double[] {0.1, 0.2, 0.3}; double[] starts_S2 = new double[] {0.3, 0.4, 0.5}; double[] ends_S1 = new double[] {0.5, 0.6, 0.7}; double[] ends_S2 = new double[] {0.7, 0.8, 0.9}; double[][] starts = new double[][] {starts_S1, starts_S2}; double[][] ends = new double[][] {ends_S1, ends_S2}; DefaultIntervalCategoryDataset d = new DefaultIntervalCategoryDataset( new Comparable[] {"Series 1", "Series 2"}, new Comparable[] {"Category 1", "Category 2", "Category 3"}, DataUtilities.createNumberArray2D(starts), DataUtilities.createNumberArray2D(ends)); assertEquals(0.1, d.getStartValue("Series 1", "Category 1")); assertEquals(0.2, d.getStartValue("Series 1", "Category 2")); assertEquals(0.3, d.getStartValue("Series 1", "Category 3")); assertEquals(0.3, d.getStartValue("Series 2", "Category 1")); assertEquals(0.4, d.getStartValue("Series 2", "Category 2")); assertEquals(0.5, d.getStartValue("Series 2", "Category 3")); assertEquals(0.5, d.getEndValue("Series 1", "Category 1")); assertEquals(0.6, d.getEndValue("Series 1", "Category 2")); assertEquals(0.7, d.getEndValue("Series 1", "Category 3")); assertEquals(0.7, d.getEndValue("Series 2", "Category 1")); assertEquals(0.8, d.getEndValue("Series 2", "Category 2")); assertEquals(0.9, d.getEndValue("Series 2", "Category 3")); try { d.getValue("XX", "Category 1"); fail("UnknownKeyException should have been thrown with provided key"); } catch (UnknownKeyException e) { assertEquals("Unknown 'series' key.", e.getMessage()); } try { d.getValue("Series 1", "XX"); fail("UnknownKeyException should have been thrown with provided key"); } catch (UnknownKeyException e) { assertEquals("Unknown 'category' key.", e.getMessage()); } } /** * Some tests for the getRowCount() method. */ @Test public void testGetRowAndColumnCount() { double[] starts_S1 = new double[] {0.1, 0.2, 0.3}; double[] starts_S2 = new double[] {0.3, 0.4, 0.5}; double[] ends_S1 = new double[] {0.5, 0.6, 0.7}; double[] ends_S2 = new double[] {0.7, 0.8, 0.9}; double[][] starts = new double[][] {starts_S1, starts_S2}; double[][] ends = new double[][] {ends_S1, ends_S2}; DefaultIntervalCategoryDataset d = new DefaultIntervalCategoryDataset(starts, ends); assertEquals(2, d.getRowCount()); assertEquals(3, d.getColumnCount()); } /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { double[] starts_S1A = new double[] {0.1, 0.2, 0.3}; double[] starts_S2A = new double[] {0.3, 0.4, 0.5}; double[] ends_S1A = new double[] {0.5, 0.6, 0.7}; double[] ends_S2A = new double[] {0.7, 0.8, 0.9}; double[][] startsA = new double[][] {starts_S1A, starts_S2A}; double[][] endsA = new double[][] {ends_S1A, ends_S2A}; DefaultIntervalCategoryDataset dA = new DefaultIntervalCategoryDataset(startsA, endsA); double[] starts_S1B = new double[] {0.1, 0.2, 0.3}; double[] starts_S2B = new double[] {0.3, 0.4, 0.5}; double[] ends_S1B = new double[] {0.5, 0.6, 0.7}; double[] ends_S2B = new double[] {0.7, 0.8, 0.9}; double[][] startsB = new double[][] {starts_S1B, starts_S2B}; double[][] endsB = new double[][] {ends_S1B, ends_S2B}; DefaultIntervalCategoryDataset dB = new DefaultIntervalCategoryDataset(startsB, endsB); assertEquals(dA, dB); assertEquals(dB, dA); // check that two empty datasets are equal DefaultIntervalCategoryDataset empty1 = new DefaultIntervalCategoryDataset(new double[0][0], new double[0][0]); DefaultIntervalCategoryDataset empty2 = new DefaultIntervalCategoryDataset(new double[0][0], new double[0][0]); assertEquals(empty1, empty2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { double[] starts_S1 = new double[] {0.1, 0.2, 0.3}; double[] starts_S2 = new double[] {0.3, 0.4, 0.5}; double[] ends_S1 = new double[] {0.5, 0.6, 0.7}; double[] ends_S2 = new double[] {0.7, 0.8, 0.9}; double[][] starts = new double[][] {starts_S1, starts_S2}; double[][] ends = new double[][] {ends_S1, ends_S2}; DefaultIntervalCategoryDataset d1 = new DefaultIntervalCategoryDataset(starts, ends); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); DefaultIntervalCategoryDataset d2 = (DefaultIntervalCategoryDataset) in.readObject(); in.close(); assertEquals(d1, d2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { double[] starts_S1 = new double[] {0.1, 0.2, 0.3}; double[] starts_S2 = new double[] {0.3, 0.4, 0.5}; double[] ends_S1 = new double[] {0.5, 0.6, 0.7}; double[] ends_S2 = new double[] {0.7, 0.8, 0.9}; double[][] starts = new double[][] {starts_S1, starts_S2}; double[][] ends = new double[][] {ends_S1, ends_S2}; DefaultIntervalCategoryDataset d1 = new DefaultIntervalCategoryDataset( new Comparable[] {"Series 1", "Series 2"}, new Comparable[] {"Category 1", "Category 2", "Category 3"}, DataUtilities.createNumberArray2D(starts), DataUtilities.createNumberArray2D(ends)); DefaultIntervalCategoryDataset d2 = (DefaultIntervalCategoryDataset) d1.clone(); assertNotSame(d1, d2); assertSame(d1.getClass(), d2.getClass()); assertEquals(d1, d2); // check that the clone doesn't share the same underlying arrays. d1.setStartValue(0, "Category 1", 0.99); assertFalse(d1.equals(d2)); d2.setStartValue(0, "Category 1", 0.99); assertEquals(d1, d2); } /** * A check to ensure that an empty dataset can be cloned. */ @Test public void testCloning2() throws CloneNotSupportedException { DefaultIntervalCategoryDataset d1 = new DefaultIntervalCategoryDataset(new double[0][0], new double[0][0]); DefaultIntervalCategoryDataset d2 = (DefaultIntervalCategoryDataset) d1.clone(); assertNotSame(d1, d2); assertSame(d1.getClass(), d2.getClass()); assertEquals(d1, d2); } /** * Some basic checks for the setStartValue() method. */ @Test public void testSetStartValue() { double[] starts_S1 = new double[] {0.1, 0.2, 0.3}; double[] starts_S2 = new double[] {0.3, 0.4, 0.5}; double[] ends_S1 = new double[] {0.5, 0.6, 0.7}; double[] ends_S2 = new double[] {0.7, 0.8, 0.9}; double[][] starts = new double[][] {starts_S1, starts_S2}; double[][] ends = new double[][] {ends_S1, ends_S2}; DefaultIntervalCategoryDataset d1 = new DefaultIntervalCategoryDataset( new Comparable[] {"Series 1", "Series 2"}, new Comparable[] {"Category 1", "Category 2", "Category 3"}, DataUtilities.createNumberArray2D(starts), DataUtilities.createNumberArray2D(ends)); d1.setStartValue(0, "Category 2", 99.9); assertEquals(99.9, d1.getStartValue("Series 1", "Category 2")); try { d1.setStartValue(-1, "Category 2", 99.9); fail("IllegalArgumentException should have been thrown on negative key"); } catch (IllegalArgumentException e) { assertEquals("DefaultIntervalCategoryDataset.setValue: series outside valid range.", e.getMessage()); } try { d1.setStartValue(2, "Category 2", 99.9); fail("IllegalArgumentException should have been thrown on key out of range"); } catch (IllegalArgumentException e) { assertEquals("DefaultIntervalCategoryDataset.setValue: series outside valid range.", e.getMessage()); } } /** * Some basic checks for the setEndValue() method. */ @Test public void testSetEndValue() { double[] starts_S1 = new double[] {0.1, 0.2, 0.3}; double[] starts_S2 = new double[] {0.3, 0.4, 0.5}; double[] ends_S1 = new double[] {0.5, 0.6, 0.7}; double[] ends_S2 = new double[] {0.7, 0.8, 0.9}; double[][] starts = new double[][] {starts_S1, starts_S2}; double[][] ends = new double[][] {ends_S1, ends_S2}; DefaultIntervalCategoryDataset d1 = new DefaultIntervalCategoryDataset( new Comparable[] {"Series 1", "Series 2"}, new Comparable[] {"Category 1", "Category 2", "Category 3"}, DataUtilities.createNumberArray2D(starts), DataUtilities.createNumberArray2D(ends)); d1.setEndValue(0, "Category 2", 99.9); assertEquals(99.9, d1.getEndValue("Series 1", "Category 2")); try { d1.setEndValue(-1, "Category 2", 99.9); fail("IllegalArgumentException should have been thrown on negative key"); } catch (IllegalArgumentException e) { assertEquals("DefaultIntervalCategoryDataset.setValue: series outside valid range.", e.getMessage()); } try { d1.setEndValue(2, "Category 2", 99.9); fail("IllegalArgumentException should have been thrown on index out of range"); } catch (IllegalArgumentException e) { assertEquals("DefaultIntervalCategoryDataset.setValue: series outside valid range.", e.getMessage()); } } /** * Some checks for the getSeriesCount() method. */ @Test public void testGetSeriesCount() { // check an empty dataset DefaultIntervalCategoryDataset empty = new DefaultIntervalCategoryDataset(new double[0][0], new double[0][0]); assertEquals(0, empty.getSeriesCount()); } /** * Some checks for the getCategoryCount() method. */ @Test public void testGetCategoryCount() { // check an empty dataset DefaultIntervalCategoryDataset empty = new DefaultIntervalCategoryDataset(new double[0][0], new double[0][0]); assertEquals(0, empty.getCategoryCount()); } /** * Some checks for the getSeriesIndex() method. */ @Test public void testGetSeriesIndex() { // check an empty dataset DefaultIntervalCategoryDataset empty = new DefaultIntervalCategoryDataset(new double[0][0], new double[0][0]); assertEquals(-1, empty.getSeriesIndex("ABC")); } /** * Some checks for the getRowIndex() method. */ @Test public void testGetRowIndex() { // check an empty dataset DefaultIntervalCategoryDataset empty = new DefaultIntervalCategoryDataset(new double[0][0], new double[0][0]); assertEquals(-1, empty.getRowIndex("ABC")); } /** * Some checks for the setSeriesKeys() method. */ @Test public void testSetSeriesKeys() { // check an empty dataset DefaultIntervalCategoryDataset empty = new DefaultIntervalCategoryDataset(new double[0][0], new double[0][0]); empty.setSeriesKeys(new String[0]); } /** * Some checks for the getCategoryIndex() method. */ @Test public void testGetCategoryIndex() { // check an empty dataset DefaultIntervalCategoryDataset empty = new DefaultIntervalCategoryDataset(new double[0][0], new double[0][0]); assertEquals(-1, empty.getCategoryIndex("ABC")); } /** * Some checks for the getColumnIndex() method. */ @Test public void testGetColumnIndex() { // check an empty dataset DefaultIntervalCategoryDataset empty = new DefaultIntervalCategoryDataset(new double[0][0], new double[0][0]); assertEquals(-1, empty.getColumnIndex("ABC")); } /** * Some checks for the setCategoryKeys() method. */ @Test public void testSetCategoryKeys() { // check an empty dataset DefaultIntervalCategoryDataset empty = new DefaultIntervalCategoryDataset(new double[0][0], new double[0][0]); empty.setCategoryKeys(new String[0]); } /** * Some checks for the getColumnKeys() method. */ @Test public void testGetColumnKeys() { // check an empty dataset DefaultIntervalCategoryDataset empty = new DefaultIntervalCategoryDataset(new double[0][0], new double[0][0]); List keys = empty.getColumnKeys(); assertEquals(0, keys.size()); } /** * Some checks for the getRowKeys() method. */ @Test public void testGetRowKeys() { // check an empty dataset DefaultIntervalCategoryDataset empty = new DefaultIntervalCategoryDataset(new double[0][0], new double[0][0]); List keys = empty.getRowKeys(); assertEquals(0, keys.size()); } /** * Some checks for the getColumnCount() method. */ @Test public void testGetColumnCount() { // check an empty dataset DefaultIntervalCategoryDataset empty = new DefaultIntervalCategoryDataset(new double[0][0], new double[0][0]); assertEquals(0, empty.getColumnCount()); } /** * Some checks for the getRowCount() method. */ @Test public void testGetRowCount() { // check an empty dataset DefaultIntervalCategoryDataset empty = new DefaultIntervalCategoryDataset(new double[0][0], new double[0][0]); assertEquals(0, empty.getColumnCount()); } }
17,671
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
SlidingCategoryDatasetTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/category/SlidingCategoryDatasetTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------------------- * SlidingCategoryDatasetTests.java * -------------------------------- * (C) Copyright 2008, 2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 08-May-2008 : Version 1 (DG); * 15-Mar-2009 : Added testGetColumnKeys() (DG); * */ package org.jfree.data.category; import org.jfree.data.UnknownKeyException; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.List; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** * Tests for the {@link SlidingCategoryDataset} class. */ public class SlidingCategoryDatasetTest { /** * Some checks for the equals() method. */ @Test public void testEquals() { DefaultCategoryDataset u1 = new DefaultCategoryDataset(); u1.addValue(1.0, "R1", "C1"); u1.addValue(2.0, "R1", "C2"); SlidingCategoryDataset d1 = new SlidingCategoryDataset(u1, 0, 5); DefaultCategoryDataset u2 = new DefaultCategoryDataset(); u2.addValue(1.0, "R1", "C1"); u2.addValue(2.0, "R1", "C2"); SlidingCategoryDataset d2 = new SlidingCategoryDataset(u2, 0, 5); assertEquals(d1, d2); d1.setFirstCategoryIndex(1); assertFalse(d1.equals(d2)); d2.setFirstCategoryIndex(1); assertEquals(d1, d2); d1.setMaximumCategoryCount(99); assertFalse(d1.equals(d2)); d2.setMaximumCategoryCount(99); assertEquals(d1, d2); u1.addValue(3.0, "R1", "C3"); assertFalse(d1.equals(d2)); u2.addValue(3.0, "R1", "C3"); assertEquals(d1, d2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { DefaultCategoryDataset u1 = new DefaultCategoryDataset(); u1.addValue(1.0, "R1", "C1"); u1.addValue(2.0, "R1", "C2"); SlidingCategoryDataset d1 = new SlidingCategoryDataset(u1, 0, 5); SlidingCategoryDataset d2 = (SlidingCategoryDataset) d1.clone(); assertNotSame(d1, d2); assertSame(d1.getClass(), d2.getClass()); assertEquals(d1, d2); // basic check for independence u1.addValue(3.0, "R1", "C3"); assertFalse(d1.equals(d2)); DefaultCategoryDataset u2 = (DefaultCategoryDataset) d2.getUnderlyingDataset(); u2.addValue(3.0, "R1", "C3"); assertEquals(d1, d2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { DefaultCategoryDataset u1 = new DefaultCategoryDataset(); u1.addValue(1.0, "R1", "C1"); u1.addValue(2.0, "R1", "C2"); SlidingCategoryDataset d1 = new SlidingCategoryDataset(u1, 0, 5); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); SlidingCategoryDataset d2 = (SlidingCategoryDataset) in.readObject(); in.close(); assertEquals(d1, d2); // basic check for independence u1.addValue(3.0, "R1", "C3"); assertFalse(d1.equals(d2)); DefaultCategoryDataset u2 = (DefaultCategoryDataset) d2.getUnderlyingDataset(); u2.addValue(3.0, "R1", "C3"); assertEquals(d1, d2); } /** * Some checks for the getColumnCount() method. */ @Test public void testGetColumnCount() { DefaultCategoryDataset underlying = new DefaultCategoryDataset(); SlidingCategoryDataset dataset = new SlidingCategoryDataset(underlying, 10, 2); assertEquals(0, dataset.getColumnCount()); underlying.addValue(1.0, "R1", "C1"); assertEquals(0, dataset.getColumnCount()); underlying.addValue(1.0, "R1", "C2"); assertEquals(0, dataset.getColumnCount()); dataset.setFirstCategoryIndex(0); assertEquals(2, dataset.getColumnCount()); underlying.addValue(1.0, "R1", "C3"); assertEquals(2, dataset.getColumnCount()); dataset.setFirstCategoryIndex(2); assertEquals(1, dataset.getColumnCount()); underlying.clear(); assertEquals(0, dataset.getColumnCount()); } /** * Some checks for the getRowCount() method. */ @Test public void testGetRowCount() { DefaultCategoryDataset underlying = new DefaultCategoryDataset(); SlidingCategoryDataset dataset = new SlidingCategoryDataset(underlying, 10, 5); assertEquals(0, dataset.getRowCount()); underlying.addValue(1.0, "R1", "C1"); assertEquals(1, dataset.getRowCount()); underlying.clear(); assertEquals(0, dataset.getRowCount()); } /** * Some checks for the getColumnIndex() method. */ @Test public void testGetColumnIndex() { DefaultCategoryDataset underlying = new DefaultCategoryDataset(); underlying.addValue(1.0, "R1", "C1"); underlying.addValue(2.0, "R1", "C2"); underlying.addValue(3.0, "R1", "C3"); underlying.addValue(4.0, "R1", "C4"); SlidingCategoryDataset dataset = new SlidingCategoryDataset(underlying, 1, 2); assertEquals(-1, dataset.getColumnIndex("C1")); assertEquals(0, dataset.getColumnIndex("C2")); assertEquals(1, dataset.getColumnIndex("C3")); assertEquals(-1, dataset.getColumnIndex("C4")); } /** * Some checks for the getRowIndex() method. */ @Test public void testGetRowIndex() { DefaultCategoryDataset underlying = new DefaultCategoryDataset(); underlying.addValue(1.0, "R1", "C1"); underlying.addValue(2.0, "R2", "C1"); underlying.addValue(3.0, "R3", "C1"); underlying.addValue(4.0, "R4", "C1"); SlidingCategoryDataset dataset = new SlidingCategoryDataset(underlying, 1, 2); assertEquals(0, dataset.getRowIndex("R1")); assertEquals(1, dataset.getRowIndex("R2")); assertEquals(2, dataset.getRowIndex("R3")); assertEquals(3, dataset.getRowIndex("R4")); } /** * Some checks for the getValue() method. */ @Test public void testGetValue() { DefaultCategoryDataset underlying = new DefaultCategoryDataset(); underlying.addValue(1.0, "R1", "C1"); underlying.addValue(2.0, "R1", "C2"); underlying.addValue(3.0, "R1", "C3"); underlying.addValue(4.0, "R1", "C4"); SlidingCategoryDataset dataset = new SlidingCategoryDataset(underlying, 1, 2); assertEquals(2.0, dataset.getValue("R1", "C2")); assertEquals(3.0, dataset.getValue("R1", "C3")); try { dataset.getValue("R1", "C1"); fail("UnknownKeyException should have been thrown with provided key"); } catch (UnknownKeyException e) { assertEquals("Unknown columnKey: C1", e.getMessage()); } try { dataset.getValue("R1", "C4"); fail("UnknownKeyException should have been thrown with provided key"); } catch (UnknownKeyException e) { assertEquals("Unknown columnKey: C4", e.getMessage()); } } /** * Some checks for the getColumnKeys() method. */ @Test public void testGetColumnKeys() { DefaultCategoryDataset underlying = new DefaultCategoryDataset(); underlying.addValue(1.0, "R1", "C1"); underlying.addValue(2.0, "R1", "C2"); underlying.addValue(3.0, "R1", "C3"); underlying.addValue(4.0, "R1", "C4"); SlidingCategoryDataset dataset = new SlidingCategoryDataset(underlying, 1, 2); List keys = dataset.getColumnKeys(); assertTrue(keys.contains("C2")); assertTrue(keys.contains("C3")); assertEquals(2, keys.size()); dataset.setFirstCategoryIndex(3); keys = dataset.getColumnKeys(); assertTrue(keys.contains("C4")); assertEquals(1, keys.size()); } }
10,043
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CategoryToPieDatasetTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/category/CategoryToPieDatasetTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------------ * CategoryToPieDatasetTests.java * ------------------------------ * (C) Copyright 2006-2012, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 26-Jul-2006 : Version 1 (DG); * 01-Aug-2006 : Added testGetIndex() method (DG); * 17-Jun-2012 : Remove JCommon dependencies (DG); * */ package org.jfree.data.category; import org.jfree.chart.util.TableOrder; import org.jfree.data.general.DefaultPieDataset; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** * Tests for the {@link CategoryToPieDataset} class. */ public class CategoryToPieDatasetTest { /** * Some tests for the constructor. */ @Test public void testConstructor() { // try a null source CategoryToPieDataset p1 = new CategoryToPieDataset(null, TableOrder.BY_COLUMN, 0); assertNull(p1.getUnderlyingDataset()); assertEquals(p1.getItemCount(), 0); assertTrue(p1.getKeys().isEmpty()); assertNull(p1.getValue("R1")); } /** * Some checks for the getValue() method. */ @Test public void testGetValue() { DefaultCategoryDataset underlying = new DefaultCategoryDataset(); underlying.addValue(1.1, "R1", "C1"); underlying.addValue(2.2, "R1", "C2"); CategoryToPieDataset d1 = new CategoryToPieDataset(underlying, TableOrder.BY_ROW, 0); assertEquals(d1.getValue("C1"), 1.1); assertEquals(d1.getValue("C2"), 2.2); // check negative index throws exception try { /* Number n = */ d1.getValue(-1); fail("Expected IndexOutOfBoundsException."); } catch (IndexOutOfBoundsException e) { // this is expected } // check index == getItemCount() throws exception try { /* Number n = */ d1.getValue(d1.getItemCount()); fail("Expected IndexOutOfBoundsException."); } catch (IndexOutOfBoundsException e) { // this is expected } // test null source CategoryToPieDataset p1 = new CategoryToPieDataset(null, TableOrder.BY_COLUMN, 0); try { /* Number n = */ p1.getValue(0); fail("Expected IndexOutOfBoundsException."); } catch (IndexOutOfBoundsException e) { // this is expected } } /** * Some checks for the getKey(int) method. */ @Test public void testGetKey() { DefaultCategoryDataset underlying = new DefaultCategoryDataset(); underlying.addValue(1.1, "R1", "C1"); underlying.addValue(2.2, "R1", "C2"); CategoryToPieDataset d1 = new CategoryToPieDataset(underlying, TableOrder.BY_ROW, 0); assertEquals(d1.getKey(0), "C1"); assertEquals(d1.getKey(1), "C2"); // check negative index throws exception try { /* Number n = */ d1.getKey(-1); fail("Expected IndexOutOfBoundsException."); } catch (IndexOutOfBoundsException e) { // this is expected } // check index == getItemCount() throws exception try { /* Number n = */ d1.getKey(d1.getItemCount()); fail("Expected IndexOutOfBoundsException."); } catch (IndexOutOfBoundsException e) { // this is expected } // test null source CategoryToPieDataset p1 = new CategoryToPieDataset(null, TableOrder.BY_COLUMN, 0); try { /* Number n = */ p1.getKey(0); fail("Expected IndexOutOfBoundsException."); } catch (IndexOutOfBoundsException e) { // this is expected } } /** * Some checks for the getIndex() method. */ @Test public void testGetIndex() { DefaultCategoryDataset underlying = new DefaultCategoryDataset(); underlying.addValue(1.1, "R1", "C1"); underlying.addValue(2.2, "R1", "C2"); CategoryToPieDataset d1 = new CategoryToPieDataset(underlying, TableOrder.BY_ROW, 0); assertEquals(0, d1.getIndex("C1")); assertEquals(1, d1.getIndex("C2")); assertEquals(-1, d1.getIndex("XX")); // try null try { d1.getIndex(null); fail("IllegalArgumentException should have been thrown on null parameter"); } catch (IllegalArgumentException e) { assertEquals("Null 'key' argument.", e.getMessage()); } } /** * For datasets, the equals() method just checks keys and values. */ @Test public void testEquals() { DefaultCategoryDataset underlying = new DefaultCategoryDataset(); underlying.addValue(1.1, "R1", "C1"); underlying.addValue(2.2, "R1", "C2"); CategoryToPieDataset d1 = new CategoryToPieDataset(underlying, TableOrder.BY_COLUMN, 1); DefaultPieDataset d2 = new DefaultPieDataset(); d2.setValue("R1", 2.2); assertEquals(d1, d2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { DefaultCategoryDataset underlying = new DefaultCategoryDataset(); underlying.addValue(1.1, "R1", "C1"); underlying.addValue(2.2, "R1", "C2"); CategoryToPieDataset d1 = new CategoryToPieDataset(underlying, TableOrder.BY_COLUMN, 1); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); CategoryToPieDataset d2 = (CategoryToPieDataset) in.readObject(); in.close(); assertEquals(d1, d2); // regular equality for the datasets doesn't check the fields, just // the data values...so let's check some more things... assertEquals(d1.getUnderlyingDataset(), d2.getUnderlyingDataset()); assertEquals(d1.getExtractType(), d2.getExtractType()); assertEquals(d1.getExtractIndex(), d2.getExtractIndex()); } }
8,045
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYDatasetSelectionExtensionTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/extension/XYDatasetSelectionExtensionTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2013, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------------------ * XYDatasetSelectionExtensionTest.java * ------------------------------------ * (C) Copyright 2013, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 18-Sep-2013 : Version 1 (DG); * */ package org.jfree.data.extension; import org.jfree.data.extension.impl.XYCursor; import org.jfree.data.extension.impl.XYDatasetSelectionExtension; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.junit.Test; import static org.junit.Assert.*; /** * Some tests for the {@link XYDatasetSelectionExtension} class. */ public class XYDatasetSelectionExtensionTest { @Test public void testGeneral() { XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries s1 = new XYSeries("S1"); s1.add(1.0, 21.0); s1.add(2.0, 22.0); s1.add(3.0, 23.0); dataset.addSeries(s1); XYDatasetSelectionExtension ext = new XYDatasetSelectionExtension( dataset); XYCursor cursor = new XYCursor(0, 2); assertFalse(ext.isSelected(cursor)); ext.setSelected(cursor, true); assertTrue(ext.isSelected(cursor)); cursor.setPosition(0, 0); assertFalse(ext.isSelected(cursor)); s1.remove(0); assertFalse(ext.isSelected(cursor)); cursor.setPosition(1, 99); // fetching the value for a key that does not exist try { ext.isSelected(cursor); fail("Expected an ArrayIndexOutOfBoundsException."); } catch (ArrayIndexOutOfBoundsException e) { // expected in this case } catch (NullPointerException e) { // expected in this case // bad } } }
3,172
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
PieDatasetSelectionExtensionTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/extension/PieDatasetSelectionExtensionTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2013, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------------------- * PieDatasetSelectionExtensionTest.java * ------------------------------------- * (C) Copyright 2013, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 18-Sep-2013 : Version 1 (DG); * */ package org.jfree.data.extension; import org.jfree.data.UnknownKeyException; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.jfree.data.extension.impl.PieCursor; import org.jfree.data.extension.impl.PieDatasetSelectionExtension; import org.jfree.data.general.DefaultPieDataset; import static org.junit.Assert.fail; import org.junit.Test; /** * Some tests for the {@link PieDatasetSelectionExtension} class. */ public class PieDatasetSelectionExtensionTest { @Test public void testGeneral() { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("A", 1.0); dataset.setValue("B", 2.0); dataset.setValue("C", 3.0); PieDatasetSelectionExtension<String> ext = new PieDatasetSelectionExtension<String>(dataset); PieCursor cursor = new PieCursor("B"); assertFalse(ext.isSelected(cursor)); ext.setSelected(cursor, true); assertTrue(ext.isSelected(cursor)); cursor.setPosition("A"); assertFalse(ext.isSelected(cursor)); dataset.remove("B"); assertFalse(ext.isSelected(cursor)); cursor.setPosition("B"); // fetching the value for a key that does not exist try { ext.isSelected(cursor); fail("Expected an UnknownKeyException."); } catch (UnknownKeyException e) { // expected in this case } } }
3,039
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
CategoryDatasetSelectionExtensionTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/extension/CategoryDatasetSelectionExtensionTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2013, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------------------------ * CategoryDatasetSelectionExtensionTest.java * ------------------------------------------ * (C) Copyright 2013, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 18-Sep-2013 : Version 1 (DG); * */ package org.jfree.data.extension; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.data.extension.impl.CategoryCursor; import org.jfree.data.extension.impl.CategoryDatasetSelectionExtension; import org.junit.Test; /** * Some tests for the {@link CategoryDatasetSelectionExtension} class. */ public class CategoryDatasetSelectionExtensionTest { @Test public void testGeneral() { DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(1.0, "R1", "C1"); dataset.addValue(2.0, "R1", "C2"); dataset.addValue(3.0, "R1", "C3"); CategoryDatasetSelectionExtension<String, String> ext = new CategoryDatasetSelectionExtension<String, String>(dataset); CategoryCursor cursor = new CategoryCursor("R1", "C1"); assertFalse(ext.isSelected(cursor)); ext.setSelected(cursor, true); assertTrue(ext.isSelected(cursor)); cursor.setPosition("R1", "C2"); assertFalse(ext.isSelected(cursor)); dataset.removeColumn("C1"); assertFalse(ext.isSelected(cursor)); } }
2,803
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
MinuteTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/MinuteTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------- * MinuteTests.java * ---------------- * (C) Copyright 2002-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 29-Jan-2002 : Version 1 (DG); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 13-Mar-2003 : Added serialization test (DG); * 21-Oct-2003 : Added hashCode test (DG); * 11-Jan-2005 : Added test for non-clonability (DG); * 05-Oct-2006 : Added new tests (DG); * 11-Dec-2006 : Added test1611872() (DG); * 11-Jul-2007 : Fixed bad time zone assumption (DG); * */ package org.jfree.data.time; import org.jfree.chart.date.MonthConstants; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; import java.util.TimeZone; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; /** * Tests for the {@link Minute} class. */ public class MinuteTest { /** * Check that a Minute instance is equal to itself. * * SourceForge Bug ID: 558850. */ @Test public void testEqualsSelf() { Minute minute = new Minute(); assertEquals(minute, minute); } /** * Tests the equals method. */ @Test public void testEquals() { Day day1 = new Day(29, MonthConstants.MARCH, 2002); Hour hour1 = new Hour(15, day1); Minute minute1 = new Minute(15, hour1); Day day2 = new Day(29, MonthConstants.MARCH, 2002); Hour hour2 = new Hour(15, day2); Minute minute2 = new Minute(15, hour2); assertEquals(minute1, minute2); } /** * In GMT, the 4.55pm on 21 Mar 2002 is java.util.Date(1016729700000L). * Use this to check the Minute constructor. */ @Test public void testDateConstructor1() { TimeZone zone = TimeZone.getTimeZone("GMT"); Locale locale = Locale.getDefault(); // locale should not matter here Calendar c = new GregorianCalendar(zone); Minute m1 = new Minute(new Date(1016729699999L), zone, locale); Minute m2 = new Minute(new Date(1016729700000L), zone, locale); assertEquals(54, m1.getMinute()); assertEquals(1016729699999L, m1.getLastMillisecond(c)); assertEquals(55, m2.getMinute()); assertEquals(1016729700000L, m2.getFirstMillisecond(c)); } /** * In Singapore, the 4.55pm on 21 Mar 2002 is * java.util.Date(1,014,281,700,000L). Use this to check the Minute * constructor. */ @Test public void testDateConstructor2() { TimeZone zone = TimeZone.getTimeZone("Asia/Singapore"); Locale locale = Locale.getDefault(); // locale should not matter here Calendar c = new GregorianCalendar(zone); Minute m1 = new Minute(new Date(1016700899999L), zone, locale); Minute m2 = new Minute(new Date(1016700900000L), zone, locale); assertEquals(54, m1.getMinute()); assertEquals(1016700899999L, m1.getLastMillisecond(c)); assertEquals(55, m2.getMinute()); assertEquals(1016700900000L, m2.getFirstMillisecond(c)); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { Minute m1 = new Minute(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(m1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); Minute m2 = (Minute) in.readObject(); in.close(); assertEquals(m1, m2); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashcode() { Minute m1 = new Minute(45, 5, 1, 2, 2003); Minute m2 = new Minute(45, 5, 1, 2, 2003); assertEquals(m1, m2); int h1 = m1.hashCode(); int h2 = m2.hashCode(); assertEquals(h1, h2); } /** * The {@link Minute} class is immutable, so should not be * {@link Cloneable}. */ @Test public void testNotCloneable() { Minute m = new Minute(45, 5, 1, 2, 2003); assertFalse(m instanceof Cloneable); } /** * Some checks for the getFirstMillisecond() method. */ @Test public void testGetFirstMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Minute m = new Minute(43, 15, 1, 4, 2006); assertEquals(1143902580000L, m.getFirstMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); } /** * Some checks for the getFirstMillisecond(TimeZone) method. */ @Test public void testGetFirstMillisecondWithTimeZone() { Minute m = new Minute(59, 15, 1, 4, 1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); Calendar c = new GregorianCalendar(zone); assertEquals(-623289660000L, m.getFirstMillisecond(c)); // try null calendar try { m.getFirstMillisecond(null); fail("NullPointerException should have been thrown on null parameter"); } catch (NullPointerException e) { //we expect to go in here } } /** * Some checks for the getFirstMillisecond(TimeZone) method. */ @Test public void testGetFirstMillisecondWithCalendar() { Minute m = new Minute(40, 2, 15, 4, 2000); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(955766400000L, m.getFirstMillisecond(calendar)); // try null calendar try { m.getFirstMillisecond(null); fail("NullPointerException should have been thrown on null parameter"); } catch (NullPointerException e) { //we expect to go in here } } /** * Some checks for the getLastMillisecond() method. */ @Test public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Minute m = new Minute(1, 1, 1, 1, 1970); assertEquals(119999L, m.getLastMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); } /** * Some checks for the getLastMillisecond(TimeZone) method. */ @Test public void testGetLastMillisecondWithTimeZone() { Minute m = new Minute(1, 2, 7, 7, 1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); Calendar c = new GregorianCalendar(zone); assertEquals(-614962680001L, m.getLastMillisecond(c)); // try null calendar try { m.getLastMillisecond(null); fail("NullPointerException should have been thrown on null parameter"); } catch (NullPointerException e) { //we expect to go in here } } /** * Some checks for the getLastMillisecond(TimeZone) method. */ @Test public void testGetLastMillisecondWithCalendar() { Minute m = new Minute(45, 21, 21, 4, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(987889559999L, m.getLastMillisecond(calendar)); // try null calendar try { m.getLastMillisecond(null); fail("NullPointerException should have been thrown on null parameter"); } catch (NullPointerException e) { //we expect to go on here } } /** * Some checks for the getSerialIndex() method. */ @Test public void testGetSerialIndex() { Minute m = new Minute(1, 1, 1, 1, 2000); assertEquals(52597501L, m.getSerialIndex()); m = new Minute(1, 1, 1, 1, 1900); assertEquals(2941L, m.getSerialIndex()); } /** * Some checks for the testNext() method. */ @Test public void testNext() { Minute m = new Minute(30, 1, 12, 12, 2000); m = (Minute) m.next(); assertEquals(2000, m.getHour().getYear()); assertEquals(12, m.getHour().getMonth()); assertEquals(12, m.getHour().getDayOfMonth()); assertEquals(1, m.getHour().getHour()); assertEquals(31, m.getMinute()); m = new Minute(59, 23, 31, 12, 9999); assertNull(m.next()); } /** * Some checks for the getStart() method. */ @Test public void testGetStart() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/Rome")); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 16, 3, 47, 0); cal.set(Calendar.MILLISECOND, 0); Minute m = new Minute(47, 3, 16, 1, 2006); assertEquals(cal.getTime(), m.getStart()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); } /** * Some checks for the getEnd() method. */ @Test public void testGetEnd() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/Rome")); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 16, 3, 47, 59); cal.set(Calendar.MILLISECOND, 999); Minute m = new Minute(47, 3, 16, 1, 2006); assertEquals(cal.getTime(), m.getEnd()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); } /** * Test for bug 1611872 - previous() fails for first minute in hour. */ @Test public void test1611872() { Minute m1 = new Minute(0, 10, 15, 4, 2000); Minute m2 = (Minute) m1.previous(); assertEquals(m2, new Minute(59, 9, 15, 4, 2000)); } }
12,121
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
MovingAverageTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/MovingAverageTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------------- * MovingAverageTests.java * ----------------------- * (C) Copyright 2003-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 14-Aug-2003 : Version 1 (DG); * 04-Oct-2004 : Eliminated NumberUtils usage (DG); * */ package org.jfree.data.time; import org.jfree.chart.date.MonthConstants; import org.junit.Test; import static org.junit.Assert.assertEquals; /** * Tests for the {@link MovingAverage} class. */ public class MovingAverageTest { private static final double EPSILON = 0.0000000001; /** * A test for the values calculated from a time series. */ @Test public void test1() { TimeSeries source = createDailyTimeSeries1(); TimeSeries maverage = MovingAverage.createMovingAverage( source, "Moving Average", 3, 3 ); // the moving average series has 7 items, the first three // days (11, 12, 13 August are skipped) assertEquals(7, maverage.getItemCount()); double value = maverage.getValue(0).doubleValue(); assertEquals(14.1, value, EPSILON); value = maverage.getValue(1).doubleValue(); assertEquals(13.4, value, EPSILON); value = maverage.getValue(2).doubleValue(); assertEquals(14.433333333333, value, EPSILON); value = maverage.getValue(3).doubleValue(); assertEquals(14.933333333333, value, EPSILON); value = maverage.getValue(4).doubleValue(); assertEquals(19.8, value, EPSILON); value = maverage.getValue(5).doubleValue(); assertEquals(15.25, value, EPSILON); value = maverage.getValue(6).doubleValue(); assertEquals(12.5, value, EPSILON); } /** * Creates a sample series. * * @return A sample series. */ private TimeSeries createDailyTimeSeries1() { TimeSeries series = new TimeSeries("Series 1"); series.add(new Day(11, MonthConstants.AUGUST, 2003), 11.2); series.add(new Day(13, MonthConstants.AUGUST, 2003), 13.8); series.add(new Day(17, MonthConstants.AUGUST, 2003), 14.1); series.add(new Day(18, MonthConstants.AUGUST, 2003), 12.7); series.add(new Day(19, MonthConstants.AUGUST, 2003), 16.5); series.add(new Day(20, MonthConstants.AUGUST, 2003), 15.6); series.add(new Day(25, MonthConstants.AUGUST, 2003), 19.8); series.add(new Day(27, MonthConstants.AUGUST, 2003), 10.7); series.add(new Day(28, MonthConstants.AUGUST, 2003), 14.3); return series; } }
3,881
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
QuarterTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/QuarterTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------- * QuarterTests.java * ----------------- * (C) Copyright 2001-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 16-Nov-2001 : Version 1 (DG); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 13-Mar-2003 : Added serialization test (DG); * 11-Jan-2005 : Added check for non-clonability (DG); * 05-Oct-2006 : Added some new tests (DG); * 11-Jul-2007 : Fixed bad time zone assumption (DG); * */ package org.jfree.data.time; import org.junit.Before; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; import java.util.TimeZone; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; /** * Tests for the {link Quarter} class. */ public class QuarterTest { /** A quarter. */ private Quarter q1Y1900; /** A quarter. */ private Quarter q2Y1900; /** A quarter. */ private Quarter q3Y9999; /** A quarter. */ private Quarter q4Y9999; /** * Common test setup. */ @Before public void setUp() { this.q1Y1900 = new Quarter(1, 1900); this.q2Y1900 = new Quarter(2, 1900); this.q3Y9999 = new Quarter(3, 9999); this.q4Y9999 = new Quarter(4, 9999); } /** * Check that a Quarter instance is equal to itself. * * SourceForge Bug ID: 558850. */ @Test public void testEqualsSelf() { Quarter quarter = new Quarter(); assertEquals(quarter, quarter); } /** * Tests the equals method. */ @Test public void testEquals() { Quarter q1 = new Quarter(2, 2002); Quarter q2 = new Quarter(2, 2002); assertEquals(q1, q2); } /** * In GMT, the end of Q1 2002 is java.util.Date(1017619199999L). Use this * to check the quarter constructor. */ @Test public void testDateConstructor1() { TimeZone zone = TimeZone.getTimeZone("GMT"); Calendar c = new GregorianCalendar(zone); Quarter q1 = new Quarter(new Date(1017619199999L), zone, Locale.getDefault()); Quarter q2 = new Quarter(new Date(1017619200000L), zone, Locale.getDefault()); assertEquals(1, q1.getQuarter()); assertEquals(1017619199999L, q1.getLastMillisecond(c)); assertEquals(2, q2.getQuarter()); assertEquals(1017619200000L, q2.getFirstMillisecond(c)); } /** * In Istanbul, the end of Q1 2002 is java.util.Date(1017608399999L). Use * this to check the quarter constructor. */ @Test public void testDateConstructor2() { TimeZone zone = TimeZone.getTimeZone("Europe/Istanbul"); Calendar c = new GregorianCalendar(zone); Quarter q1 = new Quarter(new Date(1017608399999L), zone, Locale.getDefault()); Quarter q2 = new Quarter(new Date(1017608400000L), zone, Locale.getDefault()); assertEquals(1, q1.getQuarter()); assertEquals(1017608399999L, q1.getLastMillisecond(c)); assertEquals(2, q2.getQuarter()); assertEquals(1017608400000L, q2.getFirstMillisecond(c)); } /** * Set up a quarter equal to Q1 1900. Request the previous quarter, it * should be null. */ @Test public void testQ1Y1900Previous() { Quarter previous = (Quarter) this.q1Y1900.previous(); assertNull(previous); } /** * Set up a quarter equal to Q1 1900. Request the next quarter, it should * be Q2 1900. */ @Test public void testQ1Y1900Next() { Quarter next = (Quarter) this.q1Y1900.next(); assertEquals(this.q2Y1900, next); } /** * Set up a quarter equal to Q4 9999. Request the previous quarter, it * should be Q3 9999. */ @Test public void testQ4Y9999Previous() { Quarter previous = (Quarter) this.q4Y9999.previous(); assertEquals(this.q3Y9999, previous); } /** * Set up a quarter equal to Q4 9999. Request the next quarter, it should * be null. */ @Test public void testQ4Y9999Next() { Quarter next = (Quarter) this.q4Y9999.next(); assertNull(next); } /** * Test the string parsing code... */ @Test public void testParseQuarter() { Quarter quarter = Quarter.parseQuarter("Q1-2000"); assertEquals(1, quarter.getQuarter()); assertEquals(2000, quarter.getYear().getYear()); quarter = Quarter.parseQuarter("2001-Q2"); assertEquals(2, quarter.getQuarter()); assertEquals(2001, quarter.getYear().getYear()); // test 3... quarter = Quarter.parseQuarter("Q3, 2002"); assertEquals(3, quarter.getQuarter()); assertEquals(2002, quarter.getYear().getYear()); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { Quarter q1 = new Quarter(4, 1999); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(q1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); Quarter q2 = (Quarter) in.readObject(); in.close(); assertEquals(q1, q2); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashcode() { Quarter q1 = new Quarter(2, 2003); Quarter q2 = new Quarter(2, 2003); assertEquals(q1, q2); int h1 = q1.hashCode(); int h2 = q2.hashCode(); assertEquals(h1, h2); } /** * The {@link Quarter} class is immutable, so should not be * {@link Cloneable}. */ @Test public void testNotCloneable() { Quarter q = new Quarter(2, 2003); assertFalse(q instanceof Cloneable); } /** * Some tests for the constructor with (int, int) arguments. Covers bug * report 1377239. */ @Test public void testConstructor() { try { /*Quarter q =*/ new Quarter(0, 2005); fail("IllegalArgumentException should have been thrown from 0 querter"); } catch (IllegalArgumentException e) { assertEquals("Quarter outside valid range.", e.getMessage()); } try { /*Quarter q =*/ new Quarter(5, 2005); fail("IllegalArgumentException should have been thrown from 5 quarter"); } catch (IllegalArgumentException e) { assertEquals("Quarter outside valid range.", e.getMessage()); } } /** * Some checks for the getFirstMillisecond() method. */ @Test public void testGetFirstMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Quarter q = new Quarter(3, 1970); assertEquals(15634800000L, q.getFirstMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); } /** * Some checks for the getFirstMillisecond(TimeZone) method. */ @Test public void testGetFirstMillisecondWithTimeZone() { Quarter q = new Quarter(2, 1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); Calendar c = new GregorianCalendar(zone); assertEquals(-623347200000L, q.getFirstMillisecond(c)); // try null calendar try { q.getFirstMillisecond(null); fail("NullPointerException should have been thrown on null parameter"); } catch (NullPointerException e) { //we expect to go in here } } /** * Some checks for the getFirstMillisecond(TimeZone) method. */ @Test public void testGetFirstMillisecondWithCalendar() { Quarter q = new Quarter(1, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(978307200000L, q.getFirstMillisecond(calendar)); // try null calendar try { q.getFirstMillisecond(null); fail("NullPointerException should have been thrown on null parameter"); } catch (NullPointerException e) { //we expect to go in here } } /** * Some checks for the getLastMillisecond() method. */ @Test public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Quarter q = new Quarter(3, 1970); assertEquals(23583599999L, q.getLastMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); } /** * Some checks for the getLastMillisecond(TimeZone) method. */ @Test public void testGetLastMillisecondWithTimeZone() { Quarter q = new Quarter(2, 1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); Calendar c = new GregorianCalendar(zone); assertEquals(-615488400001L, q.getLastMillisecond(c)); // try null calendar try { q.getLastMillisecond(null); fail("NullPointerException should have been thrown with null parameter"); } catch (NullPointerException e) { // we expect to go in here } } /** * Some checks for the getLastMillisecond(TimeZone) method. */ @Test public void testGetLastMillisecondWithCalendar() { Quarter q = new Quarter(3, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(1001894399999L, q.getLastMillisecond(calendar)); // try null calendar try { q.getLastMillisecond(null); fail("NullPointerException should have been thrown by null parameter"); } catch (NullPointerException e) { //we expect to go in here } } /** * Some checks for the getSerialIndex() method. */ @Test public void testGetSerialIndex() { Quarter q = new Quarter(1, 2000); assertEquals(8001L, q.getSerialIndex()); q = new Quarter(1, 1900); assertEquals(7601L, q.getSerialIndex()); } /** * Some checks for the testNext() method. */ @Test public void testNext() { Quarter q = new Quarter(1, 2000); q = (Quarter) q.next(); assertEquals(new Year(2000), q.getYear()); assertEquals(2, q.getQuarter()); q = new Quarter(4, 9999); assertNull(q.next()); } /** * Some checks for the getStart() method. */ @Test public void testGetStart() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JULY, 1, 0, 0, 0); cal.set(Calendar.MILLISECOND, 0); Quarter q = new Quarter(3, 2006); assertEquals(cal.getTime(), q.getStart()); Locale.setDefault(saved); } /** * Some checks for the getEnd() method. */ @Test public void testGetEnd() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.MARCH, 31, 23, 59, 59); cal.set(Calendar.MILLISECOND, 999); Quarter q = new Quarter(1, 2006); assertEquals(cal.getTime(), q.getEnd()); Locale.setDefault(saved); } }
13,721
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
SecondTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/SecondTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------- * SecondTests.java * ---------------- * (C) Copyright 2002-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 29-Jan-2002 : Version 1 (DG); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 13-Oct-2003 : Added serialization test (DG); * 11-Jan-2005 : Added test for non-clonability (DG); * 06-Oct-2006 : Added some new tests (DG); * 11-Jul-2007 : Fixed bad time zone assumption (DG); * */ package org.jfree.data.time; import org.jfree.chart.date.MonthConstants; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; import java.util.TimeZone; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; /** * Tests for the {@link Second} class. */ public class SecondTest { /** * Test that a Second instance is equal to itself. * * SourceForge Bug ID: 558850. */ @Test public void testEqualsSelf() { Second second = new Second(); assertEquals(second, second); } /** * Tests the equals method. */ @Test public void testEquals() { Day day1 = new Day(29, MonthConstants.MARCH, 2002); Hour hour1 = new Hour(15, day1); Minute minute1 = new Minute(15, hour1); Second second1 = new Second(34, minute1); Day day2 = new Day(29, MonthConstants.MARCH, 2002); Hour hour2 = new Hour(15, day2); Minute minute2 = new Minute(15, hour2); Second second2 = new Second(34, minute2); assertEquals(second1, second2); } /** * In GMT, the 4.55:59pm on 21 Mar 2002 is java.util.Date(1016729759000L). * Use this to check the Second constructor. */ @Test public void testDateConstructor1() { TimeZone zone = TimeZone.getTimeZone("GMT"); Calendar c = new GregorianCalendar(zone); Locale locale = Locale.getDefault(); // locale shouldn't matter here Second s1 = new Second(new Date(1016729758999L), zone, locale); Second s2 = new Second(new Date(1016729759000L), zone, locale); assertEquals(58, s1.getSecond()); assertEquals(1016729758999L, s1.getLastMillisecond(c)); assertEquals(59, s2.getSecond()); assertEquals(1016729759000L, s2.getFirstMillisecond(c)); } /** * In Chicago, the 4.55:59pm on 21 Mar 2002 is * java.util.Date(1016751359000L). Use this to check the Second constructor. */ @Test public void testDateConstructor2() { TimeZone zone = TimeZone.getTimeZone("America/Chicago"); Calendar c = new GregorianCalendar(zone); Locale locale = Locale.getDefault(); // locale shouldn't matter here Second s1 = new Second(new Date(1016751358999L), zone, locale); Second s2 = new Second(new Date(1016751359000L), zone, locale); assertEquals(58, s1.getSecond()); assertEquals(1016751358999L, s1.getLastMillisecond(c)); assertEquals(59, s2.getSecond()); assertEquals(1016751359000L, s2.getFirstMillisecond(c)); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { Second s1 = new Second(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(s1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); Second s2 = (Second) in.readObject(); in.close(); assertEquals(s1, s2); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashcode() { Second s1 = new Second(13, 45, 5, 1, 2, 2003); Second s2 = new Second(13, 45, 5, 1, 2, 2003); assertEquals(s1, s2); int h1 = s1.hashCode(); int h2 = s2.hashCode(); assertEquals(h1, h2); } /** * The {@link Second} class is immutable, so should not be * {@link Cloneable}. */ @Test public void testNotCloneable() { Second s = new Second(13, 45, 5, 1, 2, 2003); assertFalse(s instanceof Cloneable); } /** * Some checks for the getFirstMillisecond() method. */ @Test public void testGetFirstMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Second s = new Second(15, 43, 15, 1, 4, 2006); assertEquals(1143902595000L, s.getFirstMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); } /** * Some checks for the getFirstMillisecond(TimeZone) method. */ @Test public void testGetFirstMillisecondWithTimeZone() { Second s = new Second(50, 59, 15, 1, 4, 1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); Calendar c = new GregorianCalendar(zone); assertEquals(-623289610000L, s.getFirstMillisecond(c)); // try null calendar try { s.getFirstMillisecond(null); fail("NullPointerException should have been thrown on null parameter"); } catch (NullPointerException e) { //we expect to go in here } } /** * Some checks for the getFirstMillisecond(TimeZone) method. */ @Test public void testGetFirstMillisecondWithCalendar() { Second s = new Second(55, 40, 2, 15, 4, 2000); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(955766455000L, s.getFirstMillisecond(calendar)); // try null calendar try { s.getFirstMillisecond(null); fail("NullPointerException should have been thrown on null paramter"); } catch (NullPointerException e) { //we expect to go in here } } /** * Some checks for the getLastMillisecond() method. */ @Test public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Second s = new Second(1, 1, 1, 1, 1, 1970); assertEquals(61999L, s.getLastMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); } /** * Some checks for the getLastMillisecond(TimeZone) method. */ @Test public void testGetLastMillisecondWithTimeZone() { Second s = new Second(55, 1, 2, 7, 7, 1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); Calendar c = new GregorianCalendar(zone); assertEquals(-614962684001L, s.getLastMillisecond(c)); // try null calendar try { s.getLastMillisecond(null); fail("NullPointerException should have been thrown on Null Parameter"); } catch (NullPointerException e) { // we expect to go in here } } /** * Some checks for the getLastMillisecond(TimeZone) method. */ @Test public void testGetLastMillisecondWithCalendar() { Second s = new Second(50, 45, 21, 21, 4, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(987889550999L, s.getLastMillisecond(calendar)); // try null calendar try { s.getLastMillisecond(null); fail("NullPointerException should have been thrown on null parameter"); } catch (NullPointerException e) { // we expect to go in here } } /** * Some checks for the getSerialIndex() method. */ @Test public void testGetSerialIndex() { Second s = new Second(1, 1, 1, 1, 1, 2000); assertEquals(3155850061L, s.getSerialIndex()); s = new Second(1, 1, 1, 1, 1, 1900); assertEquals(176461L, s.getSerialIndex()); } /** * Some checks for the testNext() method. */ @Test public void testNext() { Second s = new Second(55, 30, 1, 12, 12, 2000); s = (Second) s.next(); assertEquals(2000, s.getMinute().getHour().getYear()); assertEquals(12, s.getMinute().getHour().getMonth()); assertEquals(12, s.getMinute().getHour().getDayOfMonth()); assertEquals(1, s.getMinute().getHour().getHour()); assertEquals(30, s.getMinute().getMinute()); assertEquals(56, s.getSecond()); s = new Second(59, 59, 23, 31, 12, 9999); assertNull(s.next()); } /** * Some checks for the getStart() method. */ @Test public void testGetStart() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 16, 3, 47, 55); cal.set(Calendar.MILLISECOND, 0); Second s = new Second(55, 47, 3, 16, 1, 2006); assertEquals(cal.getTime(), s.getStart()); Locale.setDefault(saved); } /** * Some checks for the getEnd() method. */ @Test public void testGetEnd() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 16, 3, 47, 55); cal.set(Calendar.MILLISECOND, 999); Second s = new Second(55, 47, 3, 16, 1, 2006); assertEquals(cal.getTime(), s.getEnd()); Locale.setDefault(saved); } }
11,670
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DateRangeTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/DateRangeTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------- * DateRangeTests.java * ------------------- * (C) Copyright 2004-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 23-Mar-2004 : Version 1 (DG); * 11-Jan-2005 : Added test to ensure Cloneable is not implemented (DG); * */ package org.jfree.data.time; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.Date; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; /** * Some tests for the {@link DateRange} class. */ public class DateRangeTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { DateRange r1 = new DateRange(new Date(1000L), new Date(2000L)); DateRange r2 = new DateRange(new Date(1000L), new Date(2000L)); assertEquals(r1, r2); assertEquals(r2, r1); r1 = new DateRange(new Date(1111L), new Date(2000L)); assertFalse(r1.equals(r2)); r2 = new DateRange(new Date(1111L), new Date(2000L)); assertEquals(r1, r2); r1 = new DateRange(new Date(1111L), new Date(2222L)); assertFalse(r1.equals(r2)); r2 = new DateRange(new Date(1111L), new Date(2222L)); assertEquals(r1, r2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { DateRange r1 = new DateRange(new Date(1000L), new Date(2000L)); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(r1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); DateRange r2 = (DateRange) in.readObject(); in.close(); assertEquals(r1, r2); } /** * The {@link DateRange} class is immutable, so it doesn't need to * be cloneable. */ @Test public void testClone() { DateRange r1 = new DateRange(new Date(1000L), new Date(2000L)); assertFalse(r1 instanceof Cloneable); } /** * Confirm that a DateRange is immutable. */ @Test public void testImmutable() { Date d1 = new Date(10L); Date d2 = new Date(20L); DateRange r = new DateRange(d1, d2); d1.setTime(11L); assertEquals(new Date(10L), r.getLowerDate()); r.getUpperDate().setTime(22L); assertEquals(new Date(20L), r.getUpperDate()); } }
4,162
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DayTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/DayTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------- * DayTests.java * ------------- * (C) Copyright 2001-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 15-Nov-2001 : Version 1 (DG); * 20-Mar-2002 : Added new tests for Day constructor and getStart() and * getEnd() in different time zones (DG); * 26-Jun-2002 : Removed unnecessary imports (DG); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 13-Mar-2003 : Added serialization test (DG); * 21-Oct-2003 : Added hashCode test (DG); * 11-Jan-2005 : Added test for non-clonability (DG); * 03-Oct-2006 : Added testGetSerialIndex() (DG); * 11-Jul-2007 : Fixed bad time zone assumption (DG); * */ package org.jfree.data.time; import org.jfree.chart.date.MonthConstants; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; import java.util.TimeZone; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; /** * Tests for the {@link Day} class. */ public class DayTest { /** * Check that a Day instance is equal to itself. * * SourceForge Bug ID: 558850. */ @Test public void testEqualsSelf() { Day day = new Day(); assertEquals(day, day); } /** * Tests the equals method. */ @Test public void testEquals() { Day day1 = new Day(29, MonthConstants.MARCH, 2002); Day day2 = new Day(29, MonthConstants.MARCH, 2002); assertEquals(day1, day2); } /** * In GMT, the end of 29 Feb 2004 is java.util.Date(1,078,099,199,999L). * Use this to check the day constructor. */ @Test public void testDateConstructor1() { TimeZone zone = TimeZone.getTimeZone("GMT"); Calendar c = new GregorianCalendar(zone); Locale locale = Locale.UK; Day d1 = new Day(new Date(1078099199999L), zone, locale); Day d2 = new Day(new Date(1078099200000L), zone, locale); assertEquals(MonthConstants.FEBRUARY, d1.getMonth()); assertEquals(1078099199999L, d1.getLastMillisecond(c)); assertEquals(MonthConstants.MARCH, d2.getMonth()); assertEquals(1078099200000L, d2.getFirstMillisecond(c)); } /** * In Helsinki, the end of 29 Feb 2004 is * java.util.Date(1,078,091,999,999L). Use this to check the Day * constructor. */ @Test public void testDateConstructor2() { TimeZone zone = TimeZone.getTimeZone("Europe/Helsinki"); Calendar c = new GregorianCalendar(zone); Locale locale = Locale.getDefault(); // locale shouldn't matter here Day d1 = new Day(new Date(1078091999999L), zone, locale); Day d2 = new Day(new Date(1078092000000L), zone, locale); assertEquals(MonthConstants.FEBRUARY, d1.getMonth()); assertEquals(1078091999999L, d1.getLastMillisecond(c)); assertEquals(MonthConstants.MARCH, d2.getMonth()); assertEquals(1078092000000L, d2.getFirstMillisecond(c)); } /** * Set up a day equal to 1 January 1900. Request the previous day, it * should be null. */ @Test public void test1Jan1900Previous() { Day jan1st1900 = new Day(1, MonthConstants.JANUARY, 1900); Day previous = (Day) jan1st1900.previous(); assertNull(previous); } /** * Set up a day equal to 1 January 1900. Request the next day, it should * be 2 January 1900. */ @Test public void test1Jan1900Next() { Day jan1st1900 = new Day(1, MonthConstants.JANUARY, 1900); Day next = (Day) jan1st1900.next(); assertEquals(2, next.getDayOfMonth()); } /** * Set up a day equal to 31 December 9999. Request the previous day, it * should be 30 December 9999. */ @Test public void test31Dec9999Previous() { Day dec31st9999 = new Day(31, MonthConstants.DECEMBER, 9999); Day previous = (Day) dec31st9999.previous(); assertEquals(30, previous.getDayOfMonth()); } /** * Set up a day equal to 31 December 9999. Request the next day, it should * be null. */ @Test public void test31Dec9999Next() { Day dec31st9999 = new Day(31, MonthConstants.DECEMBER, 9999); Day next = (Day) dec31st9999.next(); assertNull(next); } /** * Problem for date parsing. * <p> * This test works only correct if the short pattern of the date * format is "dd/MM/yyyy". If not, this test will result in a * false negative. * * @throws ParseException on parsing errors. */ @Test public void testParseDay() throws ParseException { GregorianCalendar gc = new GregorianCalendar(2001, 12, 31); SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy"); Date reference = format.parse("31/12/2001"); if (reference.equals(gc.getTime())) { // test 1... Day d = Day.parseDay("31/12/2001"); assertEquals(37256, d.getSerialDate().toSerial()); } // test 2... Day d = Day.parseDay("2001-12-31"); assertEquals(37256, d.getSerialDate().toSerial()); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { Day d1 = new Day(15, 4, 2000); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); Day d2 = (Day) in.readObject(); in.close(); assertEquals(d1, d2); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashcode() { Day d1 = new Day(1, 2, 2003); Day d2 = new Day(1, 2, 2003); assertEquals(d1, d2); int h1 = d1.hashCode(); int h2 = d2.hashCode(); assertEquals(h1, h2); } /** * The {@link Day} class is immutable, so should not be {@link Cloneable}. */ @Test public void testNotCloneable() { Day d = new Day(1, 2, 2003); assertFalse(d instanceof Cloneable); } /** * Some checks for the getSerialIndex() method. */ @Test public void testGetSerialIndex() { Day d = new Day(1, 1, 1900); assertEquals(2, d.getSerialIndex()); d = new Day(15, 4, 2000); assertEquals(36631, d.getSerialIndex()); } /** * Some checks for the getFirstMillisecond() method. */ @Test public void testGetFirstMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Day d = new Day(1, 3, 1970); assertEquals(5094000000L, d.getFirstMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); } /** * Some checks for the getFirstMillisecond(TimeZone) method. */ @Test public void testGetFirstMillisecondWithTimeZone() { Day d = new Day(26, 4, 1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); Calendar c = new GregorianCalendar(zone); assertEquals(-621187200000L, d.getFirstMillisecond(c)); // try null calendar try { d.getFirstMillisecond(null); fail("NullPointerException should have been thrown"); } catch (NullPointerException e) { // we expect to go in here } } /** * Some checks for the getFirstMillisecond(TimeZone) method. */ @Test public void testGetFirstMillisecondWithCalendar() { Day d = new Day(1, 12, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(1007164800000L, d.getFirstMillisecond(calendar)); // try null calendar try { d.getFirstMillisecond(null); fail("NullPointerException should have been thrown"); } catch (NullPointerException e) { //we expect to go in here } } /** * Some checks for the getLastMillisecond() method. */ @Test public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Day d = new Day(1, 1, 1970); assertEquals(82799999L, d.getLastMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); } /** * Some checks for the getLastMillisecond(TimeZone) method. */ @Test public void testGetLastMillisecondWithTimeZone() { Day d = new Day(1, 2, 1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); Calendar c = new GregorianCalendar(zone); assertEquals(-628358400001L, d.getLastMillisecond(c)); // try null calendar try { d.getLastMillisecond(null); fail("NullPointerExcption should have been thrown"); } catch (NullPointerException e) { //we expect to go in here } } /** * Some checks for the getLastMillisecond(TimeZone) method. */ @Test public void testGetLastMillisecondWithCalendar() { Day d = new Day(4, 5, 2001); Calendar calendar = Calendar.getInstance( TimeZone.getTimeZone("Europe/London"), Locale.UK); assertEquals(989017199999L, d.getLastMillisecond(calendar)); // try null calendar try { d.getLastMillisecond(null); fail("NullPointerException should have been thrown"); } catch (NullPointerException e) { //we expect to go in here } } /** * Some checks for the testNext() method. */ @Test public void testNext() { Day d = new Day(25, 12, 2000); d = (Day) d.next(); assertEquals(2000, d.getYear()); assertEquals(12, d.getMonth()); assertEquals(26, d.getDayOfMonth()); d = new Day(31, 12, 9999); assertNull(d.next()); } /** * Some checks for the getStart() method. */ @Test public void testGetStart() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.NOVEMBER, 3, 0, 0, 0); cal.set(Calendar.MILLISECOND, 0); Day d = new Day(3, 11, 2006); assertEquals(cal.getTime(), d.getStart()); Locale.setDefault(saved); } /** * Some checks for the getEnd() method. */ @Test public void testGetEnd() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(1900, Calendar.JANUARY, 1, 23, 59, 59); cal.set(Calendar.MILLISECOND, 999); Day d = new Day(1, 1, 1900); assertEquals(cal.getTime(), d.getEnd()); Locale.setDefault(saved); } }
13,255
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TimePeriodAnchorTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/TimePeriodAnchorTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------------- * TimePeriodAnchorTests.java * -------------------------- * (C) Copyright 2004-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 01-Mar-2004 : Version 1 (DG); * */ package org.jfree.data.time; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; /** * Tests for the {@link TimePeriodAnchor} class. */ public class TimePeriodAnchorTest { /** * Test the equals() method. */ @Test public void testEquals() { assertEquals(TimePeriodAnchor.START, TimePeriodAnchor.START); assertEquals(TimePeriodAnchor.MIDDLE, TimePeriodAnchor.MIDDLE); assertEquals(TimePeriodAnchor.END, TimePeriodAnchor.END); } /** * Serialize an instance, restore it, and check for identity. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { TimePeriodAnchor a1 = TimePeriodAnchor.START; ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(a1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); TimePeriodAnchor a2 = (TimePeriodAnchor) in.readObject(); in.close(); assertSame(a1, a2); } }
3,010
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
FixedMillisecondTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/FixedMillisecondTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------------- * FixedMillisecondTests.java * -------------------------- * (C) Copyright 2002-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 29-Jan-2002 : Version 1 (DG); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 21-Oct-2003 : Added hashCode test (DG); * 28-May-2008 : Added test for immutability (DG); * */ package org.jfree.data.time; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.Date; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; /** * Tests for the {@link FixedMillisecond} class. */ public class FixedMillisecondTest { /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { FixedMillisecond m1 = new FixedMillisecond(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(m1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); FixedMillisecond m2 = (FixedMillisecond) in.readObject(); in.close(); assertEquals(m1, m2); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashcode() { FixedMillisecond m1 = new FixedMillisecond(500000L); FixedMillisecond m2 = new FixedMillisecond(500000L); assertEquals(m1, m2); int h1 = m1.hashCode(); int h2 = m2.hashCode(); assertEquals(h1, h2); } /** * The {@link FixedMillisecond} class is immutable, so should not be * {@link Cloneable}. */ @Test public void testNotCloneable() { FixedMillisecond m = new FixedMillisecond(500000L); assertFalse(m instanceof Cloneable); } /** * A check for immutability. */ @Test public void testImmutability() { Date d = new Date(20L); FixedMillisecond fm = new FixedMillisecond(d); d.setTime(22L); assertEquals(20L, fm.getFirstMillisecond()); } }
3,781
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TimeSeriesTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/TimeSeriesTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2014, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * TimeSeriesTests.java * -------------------- * (C) Copyright 2001-2014, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 16-Nov-2001 : Version 1 (DG); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 13-Mar-2003 : Added serialization test (DG); * 15-Oct-2003 : Added test for setMaximumItemCount method (DG); * 23-Aug-2004 : Added test that highlights a bug where the addOrUpdate() * method can lead to more than maximumItemCount items in the * dataset (DG); * 24-May-2006 : Added new tests (DG); * 31-Oct-2007 : New hashCode() test (DG); * 21-Nov-2007 : Added testBug1832432() and testClone2() (DG); * 10-Jan-2008 : Added testBug1864222() (DG); * 13-Jan-2009 : Added testEquals3() and testRemoveAgedItems3() (DG); * 26-May-2009 : Added various tests for min/maxY values (DG); * 09-Jun-2009 : Added testAdd_TimeSeriesDataItem (DG); * 31-Aug-2009 : Added new test for createCopy() method (DG); * 03-Dec-2011 : Added testBug3446965() (DG); * */ package org.jfree.data.time; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.Locale; import java.util.TimeZone; import org.jfree.chart.date.MonthConstants; import org.jfree.data.general.SeriesChangeEvent; import org.jfree.data.general.SeriesChangeListener; import org.jfree.data.general.SeriesException; import org.junit.Before; import org.junit.Test; import org.jfree.chart.TestUtilities; import org.jfree.data.Range; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** * A collection of test cases for the {@link TimeSeries} class. */ public class TimeSeriesTest implements SeriesChangeListener { /** A time series. */ private TimeSeries seriesA; /** A time series. */ private TimeSeries seriesB; /** A time series. */ private TimeSeries seriesC; /** A flag that indicates whether or not a change event was fired. */ private boolean gotSeriesChangeEvent; /** * Common test setup. */ @Before public void setUp() { this.seriesA = new TimeSeries("Series A"); this.seriesA.add(new Year(2000), new Integer(102000)); this.seriesA.add(new Year(2001), new Integer(102001)); this.seriesA.add(new Year(2002), new Integer(102002)); this.seriesA.add(new Year(2003), new Integer(102003)); this.seriesA.add(new Year(2004), new Integer(102004)); this.seriesA.add(new Year(2005), new Integer(102005)); this.seriesB = new TimeSeries("Series B"); this.seriesB.add(new Year(2006), new Integer(202006)); this.seriesB.add(new Year(2007), new Integer(202007)); this.seriesB.add(new Year(2008), new Integer(202008)); this.seriesC = new TimeSeries("Series C"); this.seriesC.add(new Year(1999), new Integer(301999)); this.seriesC.add(new Year(2000), new Integer(302000)); this.seriesC.add(new Year(2002), new Integer(302002)); } /** * Sets the flag to indicate that a {@link SeriesChangeEvent} has been * received. * * @param event the event. */ @Override public void seriesChanged(SeriesChangeEvent event) { this.gotSeriesChangeEvent = true; } /** * Check that cloning works. */ @Test public void testClone() throws CloneNotSupportedException { TimeSeries series = new TimeSeries("Test Series"); RegularTimePeriod jan1st2002 = new Day(1, MonthConstants.JANUARY, 2002); series.add(jan1st2002, new Integer(42)); TimeSeries clone; clone = (TimeSeries) series.clone(); clone.setKey("Clone Series"); clone.update(jan1st2002, new Integer(10)); int seriesValue = series.getValue(jan1st2002).intValue(); int cloneValue = clone.getValue(jan1st2002).intValue(); assertEquals(42, seriesValue); assertEquals(10, cloneValue); assertEquals("Test Series", series.getKey()); assertEquals("Clone Series", clone.getKey()); } /** * Another test of the clone() method. */ @Test public void testClone2() throws CloneNotSupportedException { TimeSeries s1 = new TimeSeries("S1"); s1.add(new Year(2007), 100.0); s1.add(new Year(2008), null); s1.add(new Year(2009), 200.0); TimeSeries s2 = (TimeSeries) s1.clone(); assertEquals(s1, s2); // check independence s2.addOrUpdate(new Year(2009), 300.0); assertFalse(s1.equals(s2)); s1.addOrUpdate(new Year(2009), 300.0); assertEquals(s1, s2); } /** * Add a value to series A for 1999. It should be added at index 0. */ @Test public void testAddValue() { this.seriesA.add(new Year(1999), new Integer(1)); int value = this.seriesA.getValue(0).intValue(); assertEquals(1, value); } /** * Tests the retrieval of values. */ @Test public void testGetValue() { Number value1 = this.seriesA.getValue(new Year(1999)); assertNull(value1); int value2 = this.seriesA.getValue(new Year(2000)).intValue(); assertEquals(102000, value2); } /** * Tests the deletion of values. */ @Test public void testDelete() { this.seriesA.delete(0, 0); assertEquals(5, this.seriesA.getItemCount()); Number value = this.seriesA.getValue(new Year(2000)); assertNull(value); } /** * Basic tests for the delete() method. */ @Test public void testDelete2() { TimeSeries s1 = new TimeSeries("Series"); s1.add(new Year(2000), 13.75); s1.add(new Year(2001), 11.90); s1.add(new Year(2002), null); s1.addChangeListener(this); this.gotSeriesChangeEvent = false; s1.delete(new Year(2001)); assertTrue(this.gotSeriesChangeEvent); assertEquals(2, s1.getItemCount()); assertEquals(null, s1.getValue(new Year(2001))); // try deleting a time period that doesn't exist... this.gotSeriesChangeEvent = false; s1.delete(new Year(2006)); assertFalse(this.gotSeriesChangeEvent); // try deleting null try { s1.delete(null); fail("Expected IllegalArgumentException."); } catch (IllegalArgumentException e) { // expected } } /** * Some checks for the delete(int, int) method. */ @Test public void testDelete3() { TimeSeries s1 = new TimeSeries("S1"); s1.add(new Year(2011), 1.1); s1.add(new Year(2012), 2.2); s1.add(new Year(2013), 3.3); s1.add(new Year(2014), 4.4); s1.add(new Year(2015), 5.5); s1.add(new Year(2016), 6.6); s1.delete(2, 5); assertEquals(2, s1.getItemCount()); assertEquals(new Year(2011), s1.getTimePeriod(0)); assertEquals(new Year(2012), s1.getTimePeriod(1)); assertEquals(1.1, s1.getMinY(), EPSILON); assertEquals(2.2, s1.getMaxY(), EPSILON); } /** * Check that the item bounds are determined correctly when there is a * maximum item count and a new value is added. */ @Test public void testDelete_RegularTimePeriod() { TimeSeries s1 = new TimeSeries("S1"); s1.add(new Year(2010), 1.1); s1.add(new Year(2011), 2.2); s1.add(new Year(2012), 3.3); s1.add(new Year(2013), 4.4); s1.delete(new Year(2010)); s1.delete(new Year(2013)); assertEquals(2.2, s1.getMinY(), EPSILON); assertEquals(3.3, s1.getMaxY(), EPSILON); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() { TimeSeries s1 = new TimeSeries("A test"); s1.add(new Year(2000), 13.75); s1.add(new Year(2001), 11.90); s1.add(new Year(2002), null); s1.add(new Year(2005), 19.32); s1.add(new Year(2007), 16.89); TimeSeries s2 = (TimeSeries) TestUtilities.serialised(s1); assertTrue(s1.equals(s2)); } /** * Tests the equals method. */ @Test public void testEquals() { TimeSeries s1 = new TimeSeries("Time Series 1"); TimeSeries s2 = new TimeSeries("Time Series 2"); boolean b1 = s1.equals(s2); assertFalse("b1", b1); s2.setKey("Time Series 1"); boolean b2 = s1.equals(s2); assertTrue("b2", b2); RegularTimePeriod p1 = new Day(); RegularTimePeriod p2 = p1.next(); s1.add(p1, 100.0); s1.add(p2, 200.0); boolean b3 = s1.equals(s2); assertFalse("b3", b3); s2.add(p1, 100.0); s2.add(p2, 200.0); boolean b4 = s1.equals(s2); assertTrue("b4", b4); s1.setMaximumItemCount(100); boolean b5 = s1.equals(s2); assertFalse("b5", b5); s2.setMaximumItemCount(100); boolean b6 = s1.equals(s2); assertTrue("b6", b6); s1.setMaximumItemAge(100); boolean b7 = s1.equals(s2); assertFalse("b7", b7); s2.setMaximumItemAge(100); boolean b8 = s1.equals(s2); assertTrue("b8", b8); } /** * Tests a specific bug report where null arguments in the constructor * cause the equals() method to fail. Fixed for 0.9.21. */ @Test public void testEquals2() { TimeSeries s1 = new TimeSeries("Series", null, null); TimeSeries s2 = new TimeSeries("Series", null, null); assertEquals(s1, s2); } /** * Some tests to ensure that the createCopy(RegularTimePeriod, * RegularTimePeriod) method is functioning correctly. */ @Test public void testCreateCopy1() throws CloneNotSupportedException { TimeSeries series = new TimeSeries("Series"); series.add(new Month(MonthConstants.JANUARY, 2003), 45.0); series.add(new Month(MonthConstants.FEBRUARY, 2003), 55.0); series.add(new Month(MonthConstants.JUNE, 2003), 35.0); series.add(new Month(MonthConstants.NOVEMBER, 2003), 85.0); series.add(new Month(MonthConstants.DECEMBER, 2003), 75.0); // copy a range before the start of the series data... TimeSeries result1 = series.createCopy( new Month(MonthConstants.NOVEMBER, 2002), new Month(MonthConstants.DECEMBER, 2002)); assertEquals(0, result1.getItemCount()); // copy a range that includes only the first item in the series... TimeSeries result2 = series.createCopy( new Month(MonthConstants.NOVEMBER, 2002), new Month(MonthConstants.JANUARY, 2003)); assertEquals(1, result2.getItemCount()); // copy a range that begins before and ends in the middle of the // series... TimeSeries result3 = series.createCopy( new Month(MonthConstants.NOVEMBER, 2002), new Month(MonthConstants.APRIL, 2003)); assertEquals(2, result3.getItemCount()); TimeSeries result4 = series.createCopy( new Month(MonthConstants.NOVEMBER, 2002), new Month(MonthConstants.DECEMBER, 2003)); assertEquals(5, result4.getItemCount()); TimeSeries result5 = series.createCopy( new Month(MonthConstants.NOVEMBER, 2002), new Month(MonthConstants.MARCH, 2004)); assertEquals(5, result5.getItemCount()); TimeSeries result6 = series.createCopy( new Month(MonthConstants.JANUARY, 2003), new Month(MonthConstants.JANUARY, 2003)); assertEquals(1, result6.getItemCount()); TimeSeries result7 = series.createCopy( new Month(MonthConstants.JANUARY, 2003), new Month(MonthConstants.APRIL, 2003)); assertEquals(2, result7.getItemCount()); TimeSeries result8 = series.createCopy( new Month(MonthConstants.JANUARY, 2003), new Month(MonthConstants.DECEMBER, 2003)); assertEquals(5, result8.getItemCount()); TimeSeries result9 = series.createCopy( new Month(MonthConstants.JANUARY, 2003), new Month(MonthConstants.MARCH, 2004)); assertEquals(5, result9.getItemCount()); TimeSeries result10 = series.createCopy( new Month(MonthConstants.MAY, 2003), new Month(MonthConstants.DECEMBER, 2003)); assertEquals(3, result10.getItemCount()); TimeSeries result11 = series.createCopy( new Month(MonthConstants.MAY, 2003), new Month(MonthConstants.MARCH, 2004)); assertEquals(3, result11.getItemCount()); TimeSeries result12 = series.createCopy( new Month(MonthConstants.DECEMBER, 2003), new Month(MonthConstants.DECEMBER, 2003)); assertEquals(1, result12.getItemCount()); TimeSeries result13 = series.createCopy( new Month(MonthConstants.DECEMBER, 2003), new Month(MonthConstants.MARCH, 2004)); assertEquals(1, result13.getItemCount()); TimeSeries result14 = series.createCopy( new Month(MonthConstants.JANUARY, 2004), new Month(MonthConstants.MARCH, 2004)); assertEquals(0, result14.getItemCount()); } /** * Some tests to ensure that the createCopy(int, int) method is * functioning correctly. */ @Test public void testCreateCopy2() throws CloneNotSupportedException { TimeSeries series = new TimeSeries("Series"); series.add(new Month(MonthConstants.JANUARY, 2003), 45.0); series.add(new Month(MonthConstants.FEBRUARY, 2003), 55.0); series.add(new Month(MonthConstants.JUNE, 2003), 35.0); series.add(new Month(MonthConstants.NOVEMBER, 2003), 85.0); series.add(new Month(MonthConstants.DECEMBER, 2003), 75.0); // copy just the first item... TimeSeries result1 = series.createCopy(0, 0); assertEquals(new Month(1, 2003), result1.getTimePeriod(0)); // copy the first two items... result1 = series.createCopy(0, 1); assertEquals(new Month(2, 2003), result1.getTimePeriod(1)); // copy the middle three items... result1 = series.createCopy(1, 3); assertEquals(new Month(2, 2003), result1.getTimePeriod(0)); assertEquals(new Month(11, 2003), result1.getTimePeriod(2)); // copy the last two items... result1 = series.createCopy(3, 4); assertEquals(new Month(11, 2003), result1.getTimePeriod(0)); assertEquals(new Month(12, 2003), result1.getTimePeriod(1)); // copy the last item... result1 = series.createCopy(4, 4); assertEquals(new Month(12, 2003), result1.getTimePeriod(0)); // check negative first argument try { /* TimeSeries result = */ series.createCopy(-1, 1); fail("IllegalArgumentException should have been thrown on negative key"); } catch (IllegalArgumentException e) { assertEquals("Requires start >= 0.", e.getMessage()); } // check second argument less than first argument try { /* TimeSeries result = */ series.createCopy(1, 0); fail("IllegalArgumentException should have been thrown on index out of range"); } catch (IllegalArgumentException e) { assertEquals("Requires start <= end.", e.getMessage()); } TimeSeries series2 = new TimeSeries("Series 2"); TimeSeries series3 = series2.createCopy(99, 999); assertEquals(0, series3.getItemCount()); } /** * Checks that the min and max y values are updated correctly when copying * a subset. * * @throws java.lang.CloneNotSupportedException */ @Test public void testCreateCopy3() throws CloneNotSupportedException { TimeSeries s1 = new TimeSeries("S1"); s1.add(new Year(2009), 100.0); s1.add(new Year(2010), 101.0); s1.add(new Year(2011), 102.0); assertEquals(100.0, s1.getMinY(), EPSILON); assertEquals(102.0, s1.getMaxY(), EPSILON); TimeSeries s2 = s1.createCopy(0, 1); assertEquals(100.0, s2.getMinY(), EPSILON); assertEquals(101.0, s2.getMaxY(), EPSILON); TimeSeries s3 = s1.createCopy(1, 2); assertEquals(101.0, s3.getMinY(), EPSILON); assertEquals(102.0, s3.getMaxY(), EPSILON); } /** * Test the setMaximumItemCount() method to ensure that it removes items * from the series if necessary. */ @Test public void testSetMaximumItemCount() { TimeSeries s1 = new TimeSeries("S1"); s1.add(new Year(2000), 13.75); s1.add(new Year(2001), 11.90); s1.add(new Year(2002), null); s1.add(new Year(2005), 19.32); s1.add(new Year(2007), 16.89); assertSame(s1.getItemCount(), 5); s1.setMaximumItemCount(3); assertSame(s1.getItemCount(), 3); TimeSeriesDataItem item = s1.getDataItem(0); assertEquals(item.getPeriod(), new Year(2002)); assertEquals(16.89, s1.getMinY(), EPSILON); assertEquals(19.32, s1.getMaxY(), EPSILON); } /** * Some checks for the addOrUpdate() method. */ @Test public void testAddOrUpdate() { TimeSeries s1 = new TimeSeries("S1"); s1.setMaximumItemCount(2); s1.addOrUpdate(new Year(2000), 100.0); assertEquals(1, s1.getItemCount()); s1.addOrUpdate(new Year(2001), 101.0); assertEquals(2, s1.getItemCount()); s1.addOrUpdate(new Year(2001), 102.0); assertEquals(2, s1.getItemCount()); s1.addOrUpdate(new Year(2002), 103.0); assertEquals(2, s1.getItemCount()); } /** * Test the add branch of the addOrUpdate() method. */ @Test public void testAddOrUpdate2() { TimeSeries s1 = new TimeSeries("S1"); s1.setMaximumItemCount(2); s1.addOrUpdate(new Year(2010), 1.1); s1.addOrUpdate(new Year(2011), 2.2); s1.addOrUpdate(new Year(2012), 3.3); assertEquals(2, s1.getItemCount()); assertEquals(2.2, s1.getMinY(), EPSILON); assertEquals(3.3, s1.getMaxY(), EPSILON); } /** * Test that the addOrUpdate() method won't allow multiple time period * classes. */ @Test public void testAddOrUpdate3() { TimeSeries s1 = new TimeSeries("S1"); s1.addOrUpdate(new Year(2010), 1.1); assertEquals(Year.class, s1.getTimePeriodClass()); try { s1.addOrUpdate(new Month(1, 2009), 0.0); fail("IllegalArgumentException should have been thrown on key (month) not matching type (year)"); } catch (SeriesException e) { assertEquals("You are trying to add data where the time period class is org.jfree.data.time.Month, but the TimeSeries is expecting an instance of org.jfree.data.time.Year.", e.getMessage()); } } /** * Some more checks for the addOrUpdate() method. */ @Test public void testAddOrUpdate4() { TimeSeries ts = new TimeSeries("S"); TimeSeriesDataItem overwritten = ts.addOrUpdate(new Year(2009), 20.09); assertNull(overwritten); overwritten = ts.addOrUpdate(new Year(2009), 1.0); assertEquals(20.09, overwritten.getValue()); assertEquals(1.0, ts.getValue(new Year(2009))); // changing the overwritten record shouldn't affect the series overwritten.setValue(null); assertEquals(1.0, ts.getValue(new Year(2009))); TimeSeriesDataItem item = new TimeSeriesDataItem(new Year(2010), 20.10); overwritten = ts.addOrUpdate(item); assertNull(overwritten); assertEquals(20.10, ts.getValue(new Year(2010))); // changing the item that was added should not change the series item.setValue(null); assertEquals(20.10, ts.getValue(new Year(2010))); } /** * A test for the bug report 1075255. */ @Test public void testBug1075255() { TimeSeries ts = new TimeSeries("dummy"); ts.add(new FixedMillisecond(0L), 0.0); TimeSeries ts2 = new TimeSeries("dummy2"); ts2.add(new FixedMillisecond(0L), 1.0); ts.addAndOrUpdate(ts2); assertEquals(1, ts.getItemCount()); } /** * A test for bug 1832432. */ @Test public void testBug1832432() throws CloneNotSupportedException { TimeSeries s1 = new TimeSeries("Series"); TimeSeries s2 = (TimeSeries) s1.clone(); assertNotSame(s1, s2); assertSame(s1.getClass(), s2.getClass()); assertEquals(s1, s2); // test independence s1.add(new Day(1, 1, 2007), 100.0); assertFalse(s1.equals(s2)); } /** * Some checks for the getIndex() method. */ @Test public void testGetIndex() { TimeSeries series = new TimeSeries("Series"); assertEquals(-1, series.getIndex(new Month(1, 2003))); series.add(new Month(1, 2003), 45.0); assertEquals(0, series.getIndex(new Month(1, 2003))); assertEquals(-1, series.getIndex(new Month(12, 2002))); assertEquals(-2, series.getIndex(new Month(2, 2003))); series.add(new Month(3, 2003), 55.0); assertEquals(-1, series.getIndex(new Month(12, 2002))); assertEquals(0, series.getIndex(new Month(1, 2003))); assertEquals(-2, series.getIndex(new Month(2, 2003))); assertEquals(1, series.getIndex(new Month(3, 2003))); assertEquals(-3, series.getIndex(new Month(4, 2003))); } /** * Some checks for the getDataItem(int) method. */ @Test public void testGetDataItem1() { TimeSeries series = new TimeSeries("S"); // can't get anything yet...just an exception try { /*TimeSeriesDataItem item =*/ series.getDataItem(0); fail("IllegalArgumentException should have been thrown on key not existing"); } catch (IndexOutOfBoundsException e) { assertEquals("Index: 0, Size: 0", e.getMessage()); } series.add(new Year(2006), 100.0); TimeSeriesDataItem item = series.getDataItem(0); assertEquals(new Year(2006), item.getPeriod()); try { /*item = */series.getDataItem(-1); fail("IllegalArgumentException should have been thrown on negative key"); } catch (IndexOutOfBoundsException e) { assertEquals("-1", e.getMessage()); } try { /*item = */series.getDataItem(1); fail("IllegalArgumentException should have been thrown on key out of range"); } catch (IndexOutOfBoundsException e) { assertEquals("Index: 1, Size: 1", e.getMessage()); } } /** * Some checks for the getDataItem(RegularTimePeriod) method. */ @Test public void testGetDataItem2() { TimeSeries series = new TimeSeries("S"); assertNull(series.getDataItem(new Year(2006))); // try a null argument try { /* TimeSeriesDataItem item = */ series.getDataItem(null); fail("IllegalArgumentException should have been thrown on null key"); } catch (IllegalArgumentException e) { assertEquals("Null 'period' argument.", e.getMessage()); } } /** * Some checks for the removeAgedItems() method. */ @Test public void testRemoveAgedItems() { TimeSeries series = new TimeSeries("Test Series"); series.addChangeListener(this); assertEquals(Long.MAX_VALUE, series.getMaximumItemAge()); assertEquals(Integer.MAX_VALUE, series.getMaximumItemCount()); this.gotSeriesChangeEvent = false; // test empty series series.removeAgedItems(true); assertEquals(0, series.getItemCount()); assertFalse(this.gotSeriesChangeEvent); // test series with one item series.add(new Year(1999), 1.0); series.setMaximumItemAge(0); this.gotSeriesChangeEvent = false; series.removeAgedItems(true); assertEquals(1, series.getItemCount()); assertFalse(this.gotSeriesChangeEvent); // test series with two items series.setMaximumItemAge(10); series.add(new Year(2001), 2.0); this.gotSeriesChangeEvent = false; series.setMaximumItemAge(2); assertEquals(2, series.getItemCount()); assertEquals(0, series.getIndex(new Year(1999))); assertFalse(this.gotSeriesChangeEvent); series.setMaximumItemAge(1); assertEquals(1, series.getItemCount()); assertEquals(0, series.getIndex(new Year(2001))); assertTrue(this.gotSeriesChangeEvent); } /** * Some checks for the removeAgedItems(long, boolean) method. */ @Test public void testRemoveAgedItems2() { long y2006 = 1157087372534L; // milliseconds somewhere in 2006 TimeSeries series = new TimeSeries("Test Series"); series.addChangeListener(this); assertEquals(Long.MAX_VALUE, series.getMaximumItemAge()); assertEquals(Integer.MAX_VALUE, series.getMaximumItemCount()); this.gotSeriesChangeEvent = false; // test empty series series.removeAgedItems(y2006, true); assertEquals(0, series.getItemCount()); assertFalse(this.gotSeriesChangeEvent); // test a series with 1 item series.add(new Year(2004), 1.0); series.setMaximumItemAge(1); this.gotSeriesChangeEvent = false; series.removeAgedItems(new Year(2005).getMiddleMillisecond(), true); assertEquals(1, series.getItemCount()); assertFalse(this.gotSeriesChangeEvent); series.removeAgedItems(y2006, true); assertEquals(0, series.getItemCount()); assertTrue(this.gotSeriesChangeEvent); // test a series with two items series.setMaximumItemAge(2); series.add(new Year(2003), 1.0); series.add(new Year(2005), 2.0); assertEquals(2, series.getItemCount()); this.gotSeriesChangeEvent = false; assertEquals(2, series.getItemCount()); series.removeAgedItems(new Year(2005).getMiddleMillisecond(), true); assertEquals(2, series.getItemCount()); assertFalse(this.gotSeriesChangeEvent); series.removeAgedItems(y2006, true); assertEquals(1, series.getItemCount()); assertTrue(this.gotSeriesChangeEvent); } /** * Calling removeAgedItems() on an empty series should not throw any * exception. */ @Test public void testRemoveAgedItems3() { TimeSeries s = new TimeSeries("Test"); s.removeAgedItems(0L, true); } /** * Check that the item bounds are determined correctly when there is a * maximum item count. */ @Test public void testRemoveAgedItems4() { TimeSeries s1 = new TimeSeries("S1"); s1.setMaximumItemAge(2); s1.add(new Year(2010), 1.1); s1.add(new Year(2011), 2.2); s1.add(new Year(2012), 3.3); s1.add(new Year(2013), 2.5); assertEquals(3, s1.getItemCount()); assertEquals(2.2, s1.getMinY(), EPSILON); assertEquals(3.3, s1.getMaxY(), EPSILON); } /** * Check that the item bounds are determined correctly after a call to * removeAgedItems(). */ @Test public void testRemoveAgedItems5() { TimeSeries s1 = new TimeSeries("S1"); s1.setMaximumItemAge(4); s1.add(new Year(2010), 1.1); s1.add(new Year(2011), 2.2); s1.add(new Year(2012), 3.3); s1.add(new Year(2013), 2.5); s1.removeAgedItems(new Year(2015).getMiddleMillisecond(), true); assertEquals(3, s1.getItemCount()); assertEquals(2.2, s1.getMinY(), EPSILON); assertEquals(3.3, s1.getMaxY(), EPSILON); } /** * Some simple checks for the hashCode() method. */ @Test public void testHashCode() { TimeSeries s1 = new TimeSeries("Test"); TimeSeries s2 = new TimeSeries("Test"); assertEquals(s1, s2); assertEquals(s1.hashCode(), s2.hashCode()); s1.add(new Day(1, 1, 2007), 500.0); s2.add(new Day(1, 1, 2007), 500.0); assertEquals(s1, s2); assertEquals(s1.hashCode(), s2.hashCode()); s1.add(new Day(2, 1, 2007), null); s2.add(new Day(2, 1, 2007), null); assertEquals(s1, s2); assertEquals(s1.hashCode(), s2.hashCode()); s1.add(new Day(5, 1, 2007), 111.0); s2.add(new Day(5, 1, 2007), 111.0); assertEquals(s1, s2); assertEquals(s1.hashCode(), s2.hashCode()); s1.add(new Day(9, 1, 2007), 1.0); s2.add(new Day(9, 1, 2007), 1.0); assertEquals(s1, s2); assertEquals(s1.hashCode(), s2.hashCode()); } /** * Test for bug report 1864222. */ @Test public void testBug1864222() throws CloneNotSupportedException { TimeSeries s = new TimeSeries("S"); s.add(new Day(19, 8, 2005), 1); s.add(new Day(31, 1, 2006), 1); s.createCopy(new Day(1, 12, 2005), new Day(18, 1, 2006)); } /** * Test for bug report 3446965. */ @Test public void testBug3446965() { TimeSeries s = new TimeSeries("s"); s.addOrUpdate(new Year(2011), 100.0); s.addOrUpdate(new Year(2012), 150.0); s.addOrUpdate(new Year(2013), 200.0); s.addOrUpdate(new Year(2012), 250.0); // this line triggers the defect assertEquals(100.0, s.getMinY(), EPSILON); assertEquals(250.0, s.getMaxY(), EPSILON); } private static final double EPSILON = 0.0000000001; /** * Some checks for the getMinY() method. */ @Test public void testGetMinY() { TimeSeries s1 = new TimeSeries("S1"); assertTrue(Double.isNaN(s1.getMinY())); s1.add(new Year(2008), 1.1); assertEquals(1.1, s1.getMinY(), EPSILON); s1.add(new Year(2009), 2.2); assertEquals(1.1, s1.getMinY(), EPSILON); s1.add(new Year(2000), 99.9); assertEquals(1.1, s1.getMinY(), EPSILON); s1.add(new Year(2002), -1.1); assertEquals(-1.1, s1.getMinY(), EPSILON); s1.add(new Year(2003), null); assertEquals(-1.1, s1.getMinY(), EPSILON); s1.addOrUpdate(new Year(2002), null); assertEquals(1.1, s1.getMinY(), EPSILON); } @Test public void testGetMinY2() { TimeSeries ts = new TimeSeries("Time Series"); assertTrue(Double.isNaN(ts.getMinY())); ts.add(new Year(2014), 1.0); assertEquals(1.0, ts.getMinY(), EPSILON); ts.addOrUpdate(new Year(2014), null); assertTrue(Double.isNaN(ts.getMinY())); ts.addOrUpdate(new Year(2014), 1.0); assertEquals(1.0, ts.getMinY(), EPSILON); ts.clear(); assertTrue(Double.isNaN(ts.getMinY())); } /** * Some checks for the getMaxY() method. */ @Test public void testGetMaxY() { TimeSeries s1 = new TimeSeries("S1"); assertTrue(Double.isNaN(s1.getMaxY())); s1.add(new Year(2008), 1.1); assertEquals(1.1, s1.getMaxY(), EPSILON); s1.add(new Year(2009), 2.2); assertEquals(2.2, s1.getMaxY(), EPSILON); s1.add(new Year(2000), 99.9); assertEquals(99.9, s1.getMaxY(), EPSILON); s1.add(new Year(2002), -1.1); assertEquals(99.9, s1.getMaxY(), EPSILON); s1.add(new Year(2003), null); assertEquals(99.9, s1.getMaxY(), EPSILON); s1.addOrUpdate(new Year(2000), null); assertEquals(2.2, s1.getMaxY(), EPSILON); } @Test public void testGetMaxY2() { TimeSeries ts = new TimeSeries("Time Series"); assertTrue(Double.isNaN(ts.getMaxY())); ts.add(new Year(2014), 1.0); assertEquals(1.0, ts.getMaxY(), EPSILON); ts.addOrUpdate(new Year(2014), null); assertTrue(Double.isNaN(ts.getMaxY())); ts.addOrUpdate(new Year(2014), 1.0); assertEquals(1.0, ts.getMaxY(), EPSILON); ts.clear(); assertTrue(Double.isNaN(ts.getMaxY())); } /** * A test for the clear method. */ @Test public void testClear() { TimeSeries s1 = new TimeSeries("S1"); s1.add(new Year(2009), 1.1); s1.add(new Year(2010), 2.2); assertEquals(2, s1.getItemCount()); s1.clear(); assertEquals(0, s1.getItemCount()); assertTrue(Double.isNaN(s1.getMinY())); assertTrue(Double.isNaN(s1.getMaxY())); } /** * Check that the item bounds are determined correctly when there is a * maximum item count and a new value is added. */ @Test public void testAdd() { TimeSeries s1 = new TimeSeries("S1"); s1.setMaximumItemCount(2); s1.add(new Year(2010), 1.1); s1.add(new Year(2011), 2.2); s1.add(new Year(2012), 3.3); assertEquals(2, s1.getItemCount()); assertEquals(2.2, s1.getMinY(), EPSILON); assertEquals(3.3, s1.getMaxY(), EPSILON); } /** * Some checks for the update(RegularTimePeriod...method). */ @Test public void testUpdate_RegularTimePeriod() { TimeSeries s1 = new TimeSeries("S1"); s1.add(new Year(2010), 1.1); s1.add(new Year(2011), 2.2); s1.add(new Year(2012), 3.3); s1.update(new Year(2012), 4.4); assertEquals(4.4, s1.getMaxY(), EPSILON); s1.update(new Year(2010), 0.5); assertEquals(0.5, s1.getMinY(), EPSILON); s1.update(new Year(2012), null); assertEquals(2.2, s1.getMaxY(), EPSILON); s1.update(new Year(2010), null); assertEquals(2.2, s1.getMinY(), EPSILON); } /** * Create a TimeSeriesDataItem, add it to a TimeSeries. Now, modifying * the original TimeSeriesDataItem should NOT affect the TimeSeries. */ @Test public void testAdd_TimeSeriesDataItem() { TimeSeriesDataItem item = new TimeSeriesDataItem(new Year(2009), 1.0); TimeSeries series = new TimeSeries("S1"); series.add(item); assertEquals(item, series.getDataItem(0)); item.setValue(99.9); assertFalse(item.equals(series.getDataItem(0))); } @Test public void testSetKey() { TimeSeries s1 = new TimeSeries("S"); s1.setKey("S1"); assertEquals("S1", s1.getKey()); TimeSeriesCollection c = new TimeSeriesCollection(); c.addSeries(s1); TimeSeries s2 = new TimeSeries("S2"); c.addSeries(s2); // now we should be allowed to change s1's key to anything but "S2" s1.setKey("OK"); assertEquals("OK", s1.getKey()); try { s1.setKey("S2"); fail("Expect an exception here."); } catch (IllegalArgumentException e) { // OK } // after s1 is removed from the collection, we should be able to set // the key to anything we want... c.removeSeries(s1); s1.setKey("S2"); // check that removing by index also works s1.setKey("S1"); c.addSeries(s1); c.removeSeries(1); s1.setKey("S2"); } @Test public void testFindValueRange() { TimeSeries ts = new TimeSeries("Time Series"); assertNull(ts.findValueRange()); ts.add(new Year(2014), 1.0); assertEquals(new Range(1.0, 1.0), ts.findValueRange()); ts.add(new Year(2015), 2.0); assertEquals(new Range(1.0, 2.0), ts.findValueRange()); // null items are ignored ts.add(new Year(2016), null); assertEquals(new Range(1.0, 2.0), ts.findValueRange()); ts.clear(); assertNull(ts.findValueRange()); // if there are only null items, we get a NaNRange ts.add(new Year(2014), null); assertTrue(ts.findValueRange().isNaNRange()); } @Test public void testFindValueRange2() { TimeZone tzone = TimeZone.getTimeZone("Europe/London"); Calendar calendar = new GregorianCalendar(tzone, Locale.UK); calendar.clear(); calendar.set(2014, Calendar.FEBRUARY, 23, 6, 0); long start = calendar.getTimeInMillis(); calendar.clear(); calendar.set(2014, Calendar.FEBRUARY, 24, 18, 0); long end = calendar.getTimeInMillis(); Range range = new Range(start, end); TimeSeries ts = new TimeSeries("Time Series"); assertNull(ts.findValueRange(range, TimePeriodAnchor.START, tzone)); assertNull(ts.findValueRange(range, TimePeriodAnchor.MIDDLE, tzone)); assertNull(ts.findValueRange(range, TimePeriodAnchor.END, tzone)); ts.add(new Day(23, 2, 2014), 5.0); assertTrue(ts.findValueRange(range, TimePeriodAnchor.START, tzone).isNaNRange()); assertEquals(new Range(5.0, 5.0), ts.findValueRange(range, TimePeriodAnchor.MIDDLE, tzone)); assertEquals(new Range(5.0, 5.0), ts.findValueRange(range, TimePeriodAnchor.END, tzone)); ts.add(new Day(24, 2, 2014), 6.0); assertEquals(new Range(6.0, 6.0), ts.findValueRange(range, TimePeriodAnchor.START, tzone)); assertEquals(new Range(5.0, 6.0), ts.findValueRange(range, TimePeriodAnchor.MIDDLE, tzone)); assertEquals(new Range(5.0, 5.0), ts.findValueRange(range, TimePeriodAnchor.END, tzone)); ts.clear(); ts.add(new Day(24, 2, 2014), null); assertTrue(ts.findValueRange(range, TimePeriodAnchor.START, tzone).isNaNRange()); assertTrue(ts.findValueRange(range, TimePeriodAnchor.MIDDLE, tzone).isNaNRange()); assertTrue(ts.findValueRange(range, TimePeriodAnchor.END, tzone).isNaNRange()); } }
39,945
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TimePeriodValueTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/TimePeriodValueTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------- * TimePeriodValueTests.java * ------------------------- * (C) Copyright 2003-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 30-Jul-2003 : Version 1 (DG); * */ package org.jfree.data.time; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; /** * Tests for the {@link TimePeriodValue} class. */ public class TimePeriodValueTest { /** * Test that an instance is equal to itself. */ @Test public void testEqualsSelf() { TimePeriodValue tpv = new TimePeriodValue(new Day(), 55.75); assertEquals(tpv, tpv); } /** * Tests the equals() method. */ @Test public void testEquals() { TimePeriodValue tpv1 = new TimePeriodValue(new Day(30, 7, 2003), 55.75); TimePeriodValue tpv2 = new TimePeriodValue(new Day(30, 7, 2003), 55.75); assertEquals(tpv1, tpv2); assertEquals(tpv2, tpv1); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { TimePeriodValue tpv1 = new TimePeriodValue(new Day(30, 7, 2003), 55.75); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(tpv1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); TimePeriodValue tpv2 = (TimePeriodValue) in.readObject(); in.close(); assertEquals(tpv1, tpv2); } }
3,213
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
MonthTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/MonthTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------- * MonthTests.java * --------------- * (C) Copyright 2001-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 16-Nov-2001 : Version 1 (DG); * 14-Feb-2002 : Order of parameters in Month(int, int) constructor * changed (DG); * 26-Jun-2002 : Removed unnecessary import (DG); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 13-Mar-2003 : Added serialization test (DG); * 21-Oct-2003 : Added hashCode test (DG); * 11-Jan-2005 : Added non-clonability test (DG); * 05-Oct-2006 : Added some new tests (DG); * 11-Jul-2007 : Fixed bad time zone assumption (DG); * */ package org.jfree.data.time; import org.jfree.chart.date.MonthConstants; import org.junit.Before; import org.junit.Test; import java.io.*; import java.util.*; import static org.jfree.chart.date.SerialDate.DATE_FORMAT_SYMBOLS; import static org.junit.Assert.*; /** * Tests for the {@link Month} class. */ public class MonthTest { /** A month. */ private Month jan1900; /** A month. */ private Month feb1900; /** A month. */ private Month nov9999; /** A month. */ private Month dec9999; /** * Common test setup. */ @Before public void setUp() { this.jan1900 = new Month(MonthConstants.JANUARY, 1900); this.feb1900 = new Month(MonthConstants.FEBRUARY, 1900); this.nov9999 = new Month(MonthConstants.NOVEMBER, 9999); this.dec9999 = new Month(MonthConstants.DECEMBER, 9999); } /** * Check that a Month instance is equal to itself. * * SourceForge Bug ID: 558850. */ @Test public void testEqualsSelf() { Month month = new Month(); assertEquals(month, month); } /** * Tests the equals method. */ @Test public void testEquals() { Month m1 = new Month(MonthConstants.MAY, 2002); Month m2 = new Month(MonthConstants.MAY, 2002); assertEquals(m1, m2); } /** * In GMT, the end of Feb 2000 is java.util.Date(951,868,799,999L). Use * this to check the Month constructor. */ @Test public void testDateConstructor1() { TimeZone zone = TimeZone.getTimeZone("GMT"); Calendar c = new GregorianCalendar(zone); Locale locale = Locale.UK; Month m1 = new Month(new Date(951868799999L), zone, locale); Month m2 = new Month(new Date(951868800000L), zone, locale); assertEquals(MonthConstants.FEBRUARY, m1.getMonth()); assertEquals(951868799999L, m1.getLastMillisecond(c)); assertEquals(MonthConstants.MARCH, m2.getMonth()); assertEquals(951868800000L, m2.getFirstMillisecond(c)); } /** * In Auckland, the end of Feb 2000 is java.util.Date(951,821,999,999L). * Use this to check the Month constructor. */ @Test public void testDateConstructor2() { TimeZone zone = TimeZone.getTimeZone("Pacific/Auckland"); Calendar c = new GregorianCalendar(zone); Month m1 = new Month(new Date(951821999999L), zone, Locale.UK); Month m2 = new Month(new Date(951822000000L), zone, Locale.UK); assertEquals(MonthConstants.FEBRUARY, m1.getMonth()); assertEquals(951821999999L, m1.getLastMillisecond(c)); assertEquals(MonthConstants.MARCH, m2.getMonth()); assertEquals(951822000000L, m2.getFirstMillisecond(c)); } /** * Set up a month equal to Jan 1900. Request the previous month, it should * be null. */ @Test public void testJan1900Previous() { Month previous = (Month) this.jan1900.previous(); assertNull(previous); } /** * Set up a month equal to Jan 1900. Request the next month, it should be * Feb 1900. */ @Test public void testJan1900Next() { Month next = (Month) this.jan1900.next(); assertEquals(this.feb1900, next); } /** * Set up a month equal to Dec 9999. Request the previous month, it should * be Nov 9999. */ @Test public void testDec9999Previous() { Month previous = (Month) this.dec9999.previous(); assertEquals(this.nov9999, previous); } /** * Set up a month equal to Dec 9999. Request the next month, it should be * null. */ @Test public void testDec9999Next() { Month next = (Month) this.dec9999.next(); assertNull(next); } /** * Tests the string parsing code... */ @Test public void testParseMonth() { Month month = Month.parseMonth("1990-01"); assertEquals(1, month.getMonth()); assertEquals(1990, month.getYear().getYear()); month = Month.parseMonth("02-1991"); assertEquals(2, month.getMonth()); assertEquals(1991, month.getYear().getYear()); month = Month.parseMonth(DATE_FORMAT_SYMBOLS.getMonths()[2] + " 1993"); assertEquals(3, month.getMonth()); assertEquals(1993, month.getYear().getYear()); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { Month m1 = new Month(12, 1999); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(m1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); Month m2 = (Month) in.readObject(); in.close(); assertEquals(m1, m2); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashcode() { Month m1 = new Month(2, 2003); Month m2 = new Month(2, 2003); assertEquals(m1, m2); int h1 = m1.hashCode(); int h2 = m2.hashCode(); assertEquals(h1, h2); } /** * The {@link Month} class is immutable, so should not be {@link Cloneable}. */ @Test public void testNotCloneable() { Month m = new Month(2, 2003); assertFalse(m instanceof Cloneable); } /** * Some checks for the getFirstMillisecond() method. */ @Test public void testGetFirstMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Month m = new Month(3, 1970); assertEquals(5094000000L, m.getFirstMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); } /** * Some checks for the getFirstMillisecond(TimeZone) method. */ @Test public void testGetFirstMillisecondWithTimeZone() { Month m = new Month(2, 1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); Calendar c = new GregorianCalendar(zone); assertEquals(-628444800000L, m.getFirstMillisecond(c)); // try null calendar try { m.getFirstMillisecond(null); fail("NullPointerException should have been thrown on null parameter"); } catch (NullPointerException e) { //we expect to go in here } } /** * Some checks for the getFirstMillisecond(TimeZone) method. */ @Test public void testGetFirstMillisecondWithCalendar() { Month m = new Month(1, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(978307200000L, m.getFirstMillisecond(calendar)); // try null calendar try { m.getFirstMillisecond(null); fail("NullPointerException should have been thrown on null parameter"); } catch (NullPointerException e) { // we expect to go in here } } /** * Some checks for the getLastMillisecond() method. */ @Test public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Month m = new Month(3, 1970); assertEquals(7772399999L, m.getLastMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); } /** * Some checks for the getLastMillisecond(TimeZone) method. */ @Test public void testGetLastMillisecondWithTimeZone() { Month m = new Month(2, 1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); Calendar c = new GregorianCalendar(zone); assertEquals(-626025600001L, m.getLastMillisecond(c)); // try null calendar try { m.getLastMillisecond(null); fail("NullPointerException should have been thrown on null parameter"); } catch (NullPointerException e) { // we expect to go in here } } /** * Some checks for the getLastMillisecond(TimeZone) method. */ @Test public void testGetLastMillisecondWithCalendar() { Month m = new Month(3, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(986083199999L, m.getLastMillisecond(calendar)); // try null calendar try { m.getLastMillisecond(null); fail("NullPointerException should have been thrown on null parameter"); } catch (NullPointerException e) { //we expect to go in here } } /** * Some checks for the getSerialIndex() method. */ @Test public void testGetSerialIndex() { Month m = new Month(1, 2000); assertEquals(24001L, m.getSerialIndex()); m = new Month(1, 1900); assertEquals(22801L, m.getSerialIndex()); } /** * Some checks for the testNext() method. */ @Test public void testNext() { Month m = new Month(12, 2000); m = (Month) m.next(); assertEquals(new Year(2001), m.getYear()); assertEquals(1, m.getMonth()); m = new Month(12, 9999); assertNull(m.next()); } /** * Some checks for the getStart() method. */ @Test public void testGetStart() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.MARCH, 1, 0, 0, 0); cal.set(Calendar.MILLISECOND, 0); Month m = new Month(3, 2006); assertEquals(cal.getTime(), m.getStart()); Locale.setDefault(saved); } /** * Some checks for the getEnd() method. */ @Test public void testGetEnd() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 31, 23, 59, 59); cal.set(Calendar.MILLISECOND, 999); Month m = new Month(1, 2006); assertEquals(cal.getTime(), m.getEnd()); Locale.setDefault(saved); } }
13,215
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TimeSeriesCollectionTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/TimeSeriesCollectionTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2014, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------------------- * TimeSeriesCollectionTest.java * ----------------------------- * (C) Copyright 2003-2014, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 01-May-2003 : Version 1 (DG); * 04-Dec-2003 : Added a test for the getSurroundingItems() method (DG); * 08-May-2007 : Added testIndexOf() method (DG); * 18-May-2009 : Added testFindDomainBounds() (DG); * 08-Jan-2012 : Added testBug3445507() (DG); * */ package org.jfree.data.time; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import org.junit.Test; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; import java.util.GregorianCalendar; import java.util.List; import java.util.Locale; import java.util.TimeZone; import org.jfree.chart.TestUtilities; import org.jfree.data.Range; import org.jfree.data.general.DatasetUtilities; /** * A collection of test cases for the {@link TimeSeriesCollection} class. */ public class TimeSeriesCollectionTest { /** * Some tests for the equals() method. */ @Test public void testEquals() { TimeSeriesCollection c1 = new TimeSeriesCollection(); TimeSeriesCollection c2 = new TimeSeriesCollection(); TimeSeries s1 = new TimeSeries("Series 1"); TimeSeries s2 = new TimeSeries("Series 2"); // newly created collections should be equal boolean b1 = c1.equals(c2); assertTrue("b1", b1); // add series to collection 1, should be not equal c1.addSeries(s1); c1.addSeries(s2); boolean b2 = c1.equals(c2); assertFalse("b2", b2); // now add the same series to collection 2 to make them equal again... c2.addSeries(s1); c2.addSeries(s2); boolean b3 = c1.equals(c2); assertTrue("b3", b3); // now remove series 2 from collection 2 c2.removeSeries(s2); boolean b4 = c1.equals(c2); assertFalse("b4", b4); // now remove series 2 from collection 1 to make them equal again c1.removeSeries(s2); boolean b5 = c1.equals(c2); assertTrue("b5", b5); } /** * Tests the remove series method. */ @Test public void testRemoveSeries() { TimeSeriesCollection c1 = new TimeSeriesCollection(); TimeSeries s1 = new TimeSeries("Series 1"); TimeSeries s2 = new TimeSeries("Series 2"); TimeSeries s3 = new TimeSeries("Series 3"); TimeSeries s4 = new TimeSeries("Series 4"); c1.addSeries(s1); c1.addSeries(s2); c1.addSeries(s3); c1.addSeries(s4); c1.removeSeries(s3); TimeSeries s = c1.getSeries(2); boolean b1 = s.equals(s4); assertTrue(b1); } /** * Some checks for the {@link TimeSeriesCollection#removeSeries(int)} * method. */ @Test public void testRemoveSeries_int() { TimeSeriesCollection c1 = new TimeSeriesCollection(); TimeSeries s1 = new TimeSeries("Series 1"); TimeSeries s2 = new TimeSeries("Series 2"); TimeSeries s3 = new TimeSeries("Series 3"); TimeSeries s4 = new TimeSeries("Series 4"); c1.addSeries(s1); c1.addSeries(s2); c1.addSeries(s3); c1.addSeries(s4); c1.removeSeries(2); assertEquals(c1.getSeries(2), s4); c1.removeSeries(0); assertEquals(c1.getSeries(0), s2); assertEquals(2, c1.getSeriesCount()); } /** * Test the getSurroundingItems() method to ensure it is returning the * values we expect. */ @Test public void testGetSurroundingItems() { TimeSeries series = new TimeSeries("Series 1"); TimeSeriesCollection collection = new TimeSeriesCollection(series); collection.setXPosition(TimePeriodAnchor.MIDDLE); // for a series with no data, we expect {-1, -1}... int[] result = collection.getSurroundingItems(0, 1000L); assertSame(result[0], -1); assertSame(result[1], -1); // now test with a single value in the series... Day today = new Day(); long start1 = today.getFirstMillisecond(); long middle1 = today.getMiddleMillisecond(); long end1 = today.getLastMillisecond(); series.add(today, 99.9); result = collection.getSurroundingItems(0, start1); assertSame(result[0], -1); assertSame(result[1], 0); result = collection.getSurroundingItems(0, middle1); assertSame(result[0], 0); assertSame(result[1], 0); result = collection.getSurroundingItems(0, end1); assertSame(result[0], 0); assertSame(result[1], -1); // now add a second value to the series... Day tomorrow = (Day) today.next(); long start2 = tomorrow.getFirstMillisecond(); long middle2 = tomorrow.getMiddleMillisecond(); long end2 = tomorrow.getLastMillisecond(); series.add(tomorrow, 199.9); result = collection.getSurroundingItems(0, start2); assertSame(result[0], 0); assertSame(result[1], 1); result = collection.getSurroundingItems(0, middle2); assertSame(result[0], 1); assertSame(result[1], 1); result = collection.getSurroundingItems(0, end2); assertSame(result[0], 1); assertSame(result[1], -1); // now add a third value to the series... Day yesterday = (Day) today.previous(); long start3 = yesterday.getFirstMillisecond(); long middle3 = yesterday.getMiddleMillisecond(); long end3 = yesterday.getLastMillisecond(); series.add(yesterday, 1.23); result = collection.getSurroundingItems(0, start3); assertSame(result[0], -1); assertSame(result[1], 0); result = collection.getSurroundingItems(0, middle3); assertSame(result[0], 0); assertSame(result[1], 0); result = collection.getSurroundingItems(0, end3); assertSame(result[0], 0); assertSame(result[1], 1); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() { TimeSeriesCollection c1 = new TimeSeriesCollection(createSeries()); TimeSeriesCollection c2 = (TimeSeriesCollection) TestUtilities.serialised(c1); assertEquals(c1, c2); } /** * Creates a time series for testing. * * @return A time series. */ private TimeSeries createSeries() { RegularTimePeriod t = new Day(); TimeSeries series = new TimeSeries("Test"); series.add(t, 1.0); t = t.next(); series.add(t, 2.0); t = t.next(); series.add(t, null); t = t.next(); series.add(t, 4.0); return series; } /** * A test for bug report 1170825. */ @Test public void test1170825() { TimeSeries s1 = new TimeSeries("Series1"); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); try { /* TimeSeries s = */ dataset.getSeries(1); fail("Should have thrown an IllegalArgumentException on index out of bounds"); } catch (IllegalArgumentException e) { assertEquals("The 'series' argument is out of bounds (1).", e.getMessage()); } } /** * Some tests for the indexOf() method. */ @Test public void testIndexOf() { TimeSeries s1 = new TimeSeries("S1"); TimeSeries s2 = new TimeSeries("S2"); TimeSeriesCollection dataset = new TimeSeriesCollection(); assertEquals(-1, dataset.indexOf(s1)); assertEquals(-1, dataset.indexOf(s2)); dataset.addSeries(s1); assertEquals(0, dataset.indexOf(s1)); assertEquals(-1, dataset.indexOf(s2)); dataset.addSeries(s2); assertEquals(0, dataset.indexOf(s1)); assertEquals(1, dataset.indexOf(s2)); dataset.removeSeries(s1); assertEquals(-1, dataset.indexOf(s1)); assertEquals(0, dataset.indexOf(s2)); TimeSeries s2b = new TimeSeries("S2"); assertEquals(0, dataset.indexOf(s2b)); } private static final double EPSILON = 0.0000000001; /** * This method provides a check for the bounds calculated using the * {@link DatasetUtilities#findDomainBounds(org.jfree.data.xy.XYDataset, * java.util.List, boolean)} method. */ @Test public void testFindDomainBounds() { TimeSeriesCollection dataset = new TimeSeriesCollection(TimeZone.getTimeZone("Europe/Paris")); List<Comparable> visibleSeriesKeys = new java.util.ArrayList<Comparable>(); Range r = DatasetUtilities.findDomainBounds(dataset, visibleSeriesKeys, true); assertNull(r); TimeSeries s1 = new TimeSeries("S1"); dataset.addSeries(s1); visibleSeriesKeys.add("S1"); r = DatasetUtilities.findDomainBounds(dataset, visibleSeriesKeys, true); assertNull(r); // store the current time zone TimeZone saved = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/Paris")); s1.add(new Year(2008), 8.0); r = DatasetUtilities.findDomainBounds(dataset, visibleSeriesKeys, true); assertEquals(1199142000000.0, r.getLowerBound(), EPSILON); assertEquals(1230764399999.0, r.getUpperBound(), EPSILON); TimeSeries s2 = new TimeSeries("S2"); dataset.addSeries(s2); s2.add(new Year(2009), 9.0); s2.add(new Year(2010), 10.0); r = DatasetUtilities.findDomainBounds(dataset, visibleSeriesKeys, true); assertEquals(1199142000000.0, r.getLowerBound(), EPSILON); assertEquals(1230764399999.0, r.getUpperBound(), EPSILON); visibleSeriesKeys.add("S2"); r = DatasetUtilities.findDomainBounds(dataset, visibleSeriesKeys, true); assertEquals(1199142000000.0, r.getLowerBound(), EPSILON); assertEquals(1293836399999.0, r.getUpperBound(), EPSILON); // restore the default time zone TimeZone.setDefault(saved); } /** * Basic checks for cloning. */ @Test public void testCloning() throws CloneNotSupportedException { TimeSeries s1 = new TimeSeries("Series"); s1.add(new Year(2009), 1.1); TimeSeriesCollection c1 = new TimeSeriesCollection(); c1.addSeries(s1); TimeSeriesCollection c2 = (TimeSeriesCollection) c1.clone(); assertNotSame(c1, c2); assertSame(c1.getClass(), c2.getClass()); assertEquals(c1, c2); // check independence s1.setDescription("XYZ"); assertFalse(c1.equals(c2)); c2.getSeries(0).setDescription("XYZ"); assertEquals(c1, c2); } /** * A test to cover bug 3445507. */ @Test public void testBug3445507() { TimeSeries s1 = new TimeSeries("S1"); s1.add(new Year(2011), null); s1.add(new Year(2012), null); TimeSeries s2 = new TimeSeries("S2"); s2.add(new Year(2011), 5.0); s2.add(new Year(2012), 6.0); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(s1); dataset.addSeries(s2); List<Comparable> keys = new ArrayList<Comparable>(); keys.add("S1"); keys.add("S2"); Range r = dataset.getRangeBounds(keys, new Range( Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY), false); assertEquals(5.0, r.getLowerBound(), EPSILON); assertEquals(6.0, r.getUpperBound(), EPSILON); } /** * Some checks for the getRangeBounds() method. */ @Test public void testGetRangeBounds() { TimeSeriesCollection dataset = new TimeSeriesCollection(); // when the dataset contains no series, we expect the range to be null assertNull(dataset.getRangeBounds(false)); assertNull(dataset.getRangeBounds(true)); // when the dataset contains one or more series, but those series // contain no items, we still expect the range to be null TimeSeries s1 = new TimeSeries("S1"); dataset.addSeries(s1); assertNull(dataset.getRangeBounds(false)); assertNull(dataset.getRangeBounds(true)); // tests with values s1.add(new Year(2012), 1.0); assertEquals(new Range(1.0, 1.0), dataset.getRangeBounds(false)); assertEquals(new Range(1.0, 1.0), dataset.getRangeBounds(true)); s1.add(new Year(2013), -1.0); assertEquals(new Range(-1.0, 1.0), dataset.getRangeBounds(false)); assertEquals(new Range(-1.0, 1.0), dataset.getRangeBounds(true)); s1.add(new Year(2014), null); assertEquals(new Range(-1.0, 1.0), dataset.getRangeBounds(false)); assertEquals(new Range(-1.0, 1.0), dataset.getRangeBounds(true)); // adding a second series TimeSeries s2 = new TimeSeries("S2"); dataset.addSeries(s2); assertEquals(new Range(-1.0, 1.0), dataset.getRangeBounds(false)); assertEquals(new Range(-1.0, 1.0), dataset.getRangeBounds(true)); s2.add(new Year(2014), 5.0); assertEquals(new Range(-1.0, 5.0), dataset.getRangeBounds(false)); assertEquals(new Range(-1.0, 5.0), dataset.getRangeBounds(true)); dataset.removeAllSeries(); assertNull(dataset.getRangeBounds(false)); assertNull(dataset.getRangeBounds(true)); s1 = new TimeSeries("s1"); s2 = new TimeSeries("s2"); dataset.addSeries(s1); dataset.addSeries(s2); assertNull(dataset.getRangeBounds(false)); assertNull(dataset.getRangeBounds(true)); s2.add(new Year(2014), 100.0); assertEquals(new Range(100.0, 100.0), dataset.getRangeBounds(false)); assertEquals(new Range(100.0, 100.0), dataset.getRangeBounds(true)); } @Test public void testGetRangeBounds2() { TimeZone tzone = TimeZone.getTimeZone("Europe/London"); Calendar calendar = new GregorianCalendar(tzone, Locale.UK); calendar.clear(); calendar.set(2014, Calendar.FEBRUARY, 23, 6, 0); long start = calendar.getTimeInMillis(); calendar.clear(); calendar.set(2014, Calendar.FEBRUARY, 24, 18, 0); long end = calendar.getTimeInMillis(); Range range = new Range(start, end); TimeSeriesCollection collection = new TimeSeriesCollection(tzone); assertNull(collection.getRangeBounds(Collections.EMPTY_LIST, range, true)); TimeSeries s1 = new TimeSeries("S1"); s1.add(new Day(24, 2, 2014), 10.0); collection.addSeries(s1); List<Comparable> visibleSeries = new ArrayList<Comparable>(); visibleSeries.add("S1"); assertEquals(new Range(10.0, 10.0), collection.getRangeBounds( visibleSeries, range, true)); collection.setXPosition(TimePeriodAnchor.MIDDLE); assertEquals(new Range(10.0, 10.0), collection.getRangeBounds( visibleSeries, range, true)); collection.setXPosition(TimePeriodAnchor.END); assertTrue(collection.getRangeBounds( visibleSeries, range, true).isNaNRange()); } }
16,971
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
HourTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/HourTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------- * HourTests.java * -------------- * (C) Copyright 2002-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 29-Jan-2002 : Version 1 (DG); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 13-Mar-2003 : Added serialization test (DG); * 21-Oct-2003 : Added hashCode test (DG); * 11-Jan-2005 : Added test for non-clonability (DG); * 05-Oct-2006 : Added new tests (DG); * 11-Jul-2007 : Fixed bad time zone assumption (DG); * */ package org.jfree.data.time; import org.jfree.chart.date.MonthConstants; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; import java.util.TimeZone; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; /** * Tests for the {@link Hour} class. */ public class HourTest { /** * Check that an Hour instance is equal to itself. * * SourceForge Bug ID: 558850. */ @Test public void testEqualsSelf() { Hour hour = new Hour(); assertEquals(hour, hour); } /** * Tests the equals method. */ @Test public void testEquals() { Hour hour1 = new Hour(15, new Day(29, MonthConstants.MARCH, 2002)); Hour hour2 = new Hour(15, new Day(29, MonthConstants.MARCH, 2002)); assertEquals(hour1, hour2); } /** * In GMT, the 4pm on 21 Mar 2002 is java.util.Date(1,014,307,200,000L). * Use this to check the hour constructor. */ @Test public void testDateConstructor1() { TimeZone zone = TimeZone.getTimeZone("GMT"); Calendar c = new GregorianCalendar(zone); Locale locale = Locale.getDefault(); // locale should not matter here Hour h1 = new Hour(new Date(1014307199999L), zone, locale); Hour h2 = new Hour(new Date(1014307200000L), zone, locale); assertEquals(15, h1.getHour()); assertEquals(1014307199999L, h1.getLastMillisecond(c)); assertEquals(16, h2.getHour()); assertEquals(1014307200000L, h2.getFirstMillisecond(c)); } /** * In Sydney, the 4pm on 21 Mar 2002 is java.util.Date(1,014,267,600,000L). * Use this to check the hour constructor. */ @Test public void testDateConstructor2() { TimeZone zone = TimeZone.getTimeZone("Australia/Sydney"); Locale locale = Locale.getDefault(); // locale should not matter here Calendar c = new GregorianCalendar(zone); Hour h1 = new Hour(new Date(1014267599999L), zone, locale); Hour h2 = new Hour (new Date(1014267600000L), zone, locale); assertEquals(15, h1.getHour()); assertEquals(1014267599999L, h1.getLastMillisecond(c)); assertEquals(16, h2.getHour()); assertEquals(1014267600000L, h2.getFirstMillisecond(c)); } /** * Set up an hour equal to hour zero, 1 January 1900. Request the * previous hour, it should be null. */ @Test public void testFirstHourPrevious() { Hour first = new Hour(0, new Day(1, MonthConstants.JANUARY, 1900)); Hour previous = (Hour) first.previous(); assertNull(previous); } /** * Set up an hour equal to hour zero, 1 January 1900. Request the next * hour, it should be null. */ @Test public void testFirstHourNext() { Hour first = new Hour(0, new Day(1, MonthConstants.JANUARY, 1900)); Hour next = (Hour) first.next(); assertEquals(1, next.getHour()); assertEquals(1900, next.getYear()); } /** * Set up an hour equal to hour zero, 1 January 1900. Request the previous * hour, it should be null. */ @Test public void testLastHourPrevious() { Hour last = new Hour(23, new Day(31, MonthConstants.DECEMBER, 9999)); Hour previous = (Hour) last.previous(); assertEquals(22, previous.getHour()); assertEquals(9999, previous.getYear()); } /** * Set up an hour equal to hour zero, 1 January 1900. Request the next * hour, it should be null. */ @Test public void testLastHourNext() { Hour last = new Hour(23, new Day(31, MonthConstants.DECEMBER, 9999)); Hour next = (Hour) last.next(); assertNull(next); } /** * Problem for date parsing. */ @Test public void testParseHour() { // test 1... Hour h = Hour.parseHour("2002-01-29 13"); assertEquals(13, h.getHour()); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { Hour h1 = new Hour(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(h1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); Hour h2 = (Hour) in.readObject(); in.close(); assertEquals(h1, h2); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashcode() { Hour h1 = new Hour(7, 9, 10, 1999); Hour h2 = new Hour(7, 9, 10, 1999); assertEquals(h1, h2); int hash1 = h1.hashCode(); int hash2 = h2.hashCode(); assertEquals(hash1, hash2); } /** * The {@link Hour} class is immutable, so should not be {@link Cloneable}. */ @Test public void testNotCloneable() { Hour h = new Hour(7, 9, 10, 1999); assertFalse(h instanceof Cloneable); } /** * Some checks for the getFirstMillisecond() method. */ @Test public void testGetFirstMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Hour h = new Hour(15, 1, 4, 2006); assertEquals(1143900000000L, h.getFirstMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); } /** * Some checks for the getFirstMillisecond(TimeZone) method. */ @Test public void testGetFirstMillisecondWithTimeZone() { Hour h = new Hour(15, 1, 4, 1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); Calendar c = new GregorianCalendar(zone); assertEquals(-623293200000L, h.getFirstMillisecond(c)); // try null calendar try { h.getFirstMillisecond(null); fail("NullPointerException should have been thrown on null parameter"); } catch (NullPointerException e) { //we expect to go in here } } /** * Some checks for the getFirstMillisecond(TimeZone) method. */ @Test public void testGetFirstMillisecondWithCalendar() { Hour h = new Hour(2, 15, 4, 2000); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(955764000000L, h.getFirstMillisecond(calendar)); // try null calendar try { h.getFirstMillisecond(null); fail("NullPointerException should have been thrown on null parameter"); } catch (NullPointerException e) { // we expect to go in here } } /** * Some checks for the getLastMillisecond() method. */ @Test public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Hour h = new Hour(1, 1, 1, 1970); assertEquals(3599999L, h.getLastMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); } /** * Some checks for the getLastMillisecond(TimeZone) method. */ @Test public void testGetLastMillisecondWithTimeZone() { Hour h = new Hour(2, 7, 7, 1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); Calendar c = new GregorianCalendar(zone); assertEquals(-614959200001L, h.getLastMillisecond(c)); // try null calendar try { h.getLastMillisecond(null); fail("NullPointerException should have been thrown on null parameter"); } catch (NullPointerException e) { // we expect to go in here } } /** * Some checks for the getLastMillisecond(TimeZone) method. */ @Test public void testGetLastMillisecondWithCalendar() { Hour h = new Hour(21, 21, 4, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(987890399999L, h.getLastMillisecond(calendar)); // try null calendar try { h.getLastMillisecond(null); fail("NullPointerExceptoin should have been thrown on null parameter"); } catch (NullPointerException e) { //we expect to go in here } } /** * Some checks for the getSerialIndex() method. */ @Test public void testGetSerialIndex() { Hour h = new Hour(1, 1, 1, 2000); assertEquals(876625L, h.getSerialIndex()); h = new Hour(1, 1, 1, 1900); assertEquals(49L, h.getSerialIndex()); } /** * Some checks for the testNext() method. */ @Test public void testNext() { Hour h = new Hour(1, 12, 12, 2000); h = (Hour) h.next(); assertEquals(2000, h.getYear()); assertEquals(12, h.getMonth()); assertEquals(12, h.getDayOfMonth()); assertEquals(2, h.getHour()); h = new Hour(23, 31, 12, 9999); assertNull(h.next()); } /** * Some checks for the getStart() method. */ @Test public void testGetStart() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 16, 3, 0, 0); cal.set(Calendar.MILLISECOND, 0); Hour h = new Hour(3, 16, 1, 2006); assertEquals(cal.getTime(), h.getStart()); Locale.setDefault(saved); } /** * Some checks for the getEnd() method. */ @Test public void testGetEnd() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 8, 1, 59, 59); cal.set(Calendar.MILLISECOND, 999); Hour h = new Hour(1, 8, 1, 2006); assertEquals(cal.getTime(), h.getEnd()); Locale.setDefault(saved); } }
12,720
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TimeTableXYDatasetTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/TimeTableXYDatasetTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------------- * TimeTableXYDatasetTests.java * ---------------------------- * (C) Copyright 2004-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): Rob Eden; * * Changes * ------- * 15-Sep-2004 : Version 1 (DG); * 25-Jul-2007 : Added test for clear() method, by Rob Eden (DG); * */ package org.jfree.data.time; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.TimeZone; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; /** * A collection of test cases for the {@link TimeTableXYDataset} class. */ public class TimeTableXYDatasetTest { private static final double DELTA = 0.0000000001; /** * Some checks for a simple dataset. */ @Test public void testStandard() { TimeTableXYDataset d = new TimeTableXYDataset(); d.add(new Year(1999), 1.0, "Series 1"); assertEquals(d.getItemCount(), 1); assertEquals(d.getSeriesCount(), 1); d.add(new Year(2000), 2.0, "Series 2"); assertEquals(d.getItemCount(), 2); assertEquals(d.getSeriesCount(), 2); assertEquals(d.getYValue(0, 0), 1.0, DELTA); assertTrue(Double.isNaN(d.getYValue(0, 1))); assertTrue(Double.isNaN(d.getYValue(1, 0))); assertEquals(d.getYValue(1, 1), 2.0, DELTA); } /** * Some checks for the getTimePeriod() method. */ @Test public void testGetTimePeriod() { TimeTableXYDataset d = new TimeTableXYDataset(); d.add(new Year(1999), 1.0, "Series 1"); d.add(new Year(1998), 2.0, "Series 1"); d.add(new Year(1996), 3.0, "Series 1"); assertEquals(d.getTimePeriod(0), new Year(1996)); assertEquals(d.getTimePeriod(1), new Year(1998)); assertEquals(d.getTimePeriod(2), new Year(1999)); } /** * Some checks for the equals() method. */ @Test public void testEquals() { TimeTableXYDataset d1 = new TimeTableXYDataset(); TimeTableXYDataset d2 = new TimeTableXYDataset(); assertEquals(d1, d2); assertEquals(d2, d1); d1.add(new Year(1999), 123.4, "S1"); assertFalse(d1.equals(d2)); d2.add(new Year(1999), 123.4, "S1"); assertEquals(d1, d2); d1.setDomainIsPointsInTime(!d1.getDomainIsPointsInTime()); assertFalse(d1.equals(d2)); d2.setDomainIsPointsInTime(!d2.getDomainIsPointsInTime()); assertEquals(d1, d2); d1 = new TimeTableXYDataset(TimeZone.getTimeZone("GMT")); d2 = new TimeTableXYDataset(TimeZone.getTimeZone( "America/Los_Angeles")); assertFalse(d1.equals(d2)); } /** * Some checks for cloning. */ @Test public void testClone() throws CloneNotSupportedException { TimeTableXYDataset d = new TimeTableXYDataset(); d.add(new Year(1999), 25.0, "Series"); TimeTableXYDataset clone = (TimeTableXYDataset) d.clone(); assertEquals(clone, d); // now test that the clone is independent of the original clone.add(new Year(2004), 1.2, "SS"); assertFalse(clone.equals(d)); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { TimeTableXYDataset d1 = new TimeTableXYDataset(); d1.add(new Year(1999), 123.4, "S1"); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); TimeTableXYDataset d2 = (TimeTableXYDataset) in.readObject(); in.close(); assertEquals(d1, d2); } /** * Test clearing data. */ @Test public void testClear() { TimeTableXYDataset d = new TimeTableXYDataset(); d.add(new Year(1999), 1.0, "Series 1"); assertEquals(d.getItemCount(), 1); assertEquals(d.getSeriesCount(), 1); d.add(new Year(2000), 2.0, "Series 2"); d.clear(); // Make sure there's nothing left assertEquals(0, d.getItemCount()); assertEquals(0, d.getSeriesCount()); } }
5,915
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TimePeriodValuesTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/TimePeriodValuesTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------- * TimePeriodValueTests.java * ------------------------- * (C) Copyright 2003-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 30-Jul-2003 : Version 1 (DG); * 07-Apr-2008 : Added new tests for min/max-start/middle/end * index updates (DG); * */ package org.jfree.data.time; import org.jfree.chart.date.MonthConstants; import org.jfree.data.general.SeriesChangeEvent; import org.jfree.data.general.SeriesChangeListener; import org.junit.Before; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.Date; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** * A collection of test cases for the {@link TimePeriodValues} class. */ public class TimePeriodValuesTest { /** Series A. */ private TimePeriodValues seriesA; /** Series B. */ private TimePeriodValues seriesB; /** Series C. */ private TimePeriodValues seriesC; /** * Common test setup. */ @Before public void setUp() { this.seriesA = new TimePeriodValues("Series A"); this.seriesA.add(new Year(2000), new Integer(102000)); this.seriesA.add(new Year(2001), new Integer(102001)); this.seriesA.add(new Year(2002), new Integer(102002)); this.seriesA.add(new Year(2003), new Integer(102003)); this.seriesA.add(new Year(2004), new Integer(102004)); this.seriesA.add(new Year(2005), new Integer(102005)); this.seriesB = new TimePeriodValues("Series B"); this.seriesB.add(new Year(2006), new Integer(202006)); this.seriesB.add(new Year(2007), new Integer(202007)); this.seriesB.add(new Year(2008), new Integer(202008)); this.seriesC = new TimePeriodValues("Series C"); this.seriesC.add(new Year(1999), new Integer(301999)); this.seriesC.add(new Year(2000), new Integer(302000)); this.seriesC.add(new Year(2002), new Integer(302002)); } /** * Set up a quarter equal to Q1 1900. Request the previous quarter, it * should be null. */ @Test public void testClone() throws CloneNotSupportedException { TimePeriodValues series = new TimePeriodValues("Test Series"); RegularTimePeriod jan1st2002 = new Day(1, MonthConstants.JANUARY, 2002); series.add(jan1st2002, new Integer(42)); TimePeriodValues clone = (TimePeriodValues) series.clone(); clone.setKey("Clone Series"); clone.update(0, 10); int seriesValue = series.getValue(0).intValue(); int cloneValue = clone.getValue(0).intValue(); assertEquals(42, seriesValue); assertEquals(10, cloneValue); assertEquals("Test Series", series.getKey()); assertEquals("Clone Series", clone.getKey()); } /** * Add a value to series A for 1999. It should be added at index 0. */ @Test public void testAddValue() { TimePeriodValues tpvs = new TimePeriodValues("Test"); tpvs.add(new Year(1999), new Integer(1)); int value = tpvs.getValue(0).intValue(); assertEquals(1, value); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { TimePeriodValues s1 = new TimePeriodValues("A test"); s1.add(new Year(2000), 13.75); s1.add(new Year(2001), 11.90); s1.add(new Year(2002), null); s1.add(new Year(2005), 19.32); s1.add(new Year(2007), 16.89); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(s1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); TimePeriodValues s2 = (TimePeriodValues) in.readObject(); in.close(); assertEquals(s1, s2); } /** * Tests the equals method. */ @Test public void testEquals() { TimePeriodValues s1 = new TimePeriodValues("Time Series 1"); TimePeriodValues s2 = new TimePeriodValues("Time Series 2"); boolean b1 = s1.equals(s2); assertFalse("b1", b1); s2.setKey("Time Series 1"); boolean b2 = s1.equals(s2); assertTrue("b2", b2); // domain description s1.setDomainDescription("XYZ"); assertFalse(s1.equals(s2)); s2.setDomainDescription("XYZ"); assertEquals(s1, s2); // domain description - null s1.setDomainDescription(null); assertFalse(s1.equals(s2)); s2.setDomainDescription(null); assertEquals(s1, s2); // range description s1.setRangeDescription("XYZ"); assertFalse(s1.equals(s2)); s2.setRangeDescription("XYZ"); assertEquals(s1, s2); // range description - null s1.setRangeDescription(null); assertFalse(s1.equals(s2)); s2.setRangeDescription(null); assertEquals(s1, s2); RegularTimePeriod p1 = new Day(); RegularTimePeriod p2 = p1.next(); s1.add(p1, 100.0); s1.add(p2, 200.0); boolean b3 = s1.equals(s2); assertFalse("b3", b3); s2.add(p1, 100.0); s2.add(p2, 200.0); boolean b4 = s1.equals(s2); assertTrue("b4", b4); } /** * A test for bug report 1161329. */ @Test public void test1161329() { TimePeriodValues tpv = new TimePeriodValues("Test"); RegularTimePeriod t = new Day(); tpv.add(t, 1.0); t = t.next(); tpv.add(t, 2.0); tpv.delete(0, 1); assertEquals(0, tpv.getItemCount()); tpv.add(t, 2.0); assertEquals(1, tpv.getItemCount()); } static final double EPSILON = 0.0000000001; /** * Some checks for the add() methods. */ @Test public void testAdd() { TimePeriodValues tpv = new TimePeriodValues("Test"); MySeriesChangeListener listener = new MySeriesChangeListener(); tpv.addChangeListener(listener); tpv.add(new TimePeriodValue(new SimpleTimePeriod(new Date(1L), new Date(3L)), 99.0)); assertEquals(99.0, tpv.getValue(0).doubleValue(), EPSILON); assertEquals(tpv, listener.getLastEvent().getSource()); // a null item should throw an IllegalArgumentException try { tpv.add(null); fail("IllegalArgumentException should have been thrown on null parameter"); } catch (IllegalArgumentException e) { assertEquals("Null item not allowed.", e.getMessage()); } } /** * Some tests for the getMinStartIndex() method. */ @Test public void testGetMinStartIndex() { TimePeriodValues s = new TimePeriodValues("Test"); assertEquals(-1, s.getMinStartIndex()); s.add(new SimpleTimePeriod(100L, 200L), 1.0); assertEquals(0, s.getMinStartIndex()); s.add(new SimpleTimePeriod(300L, 400L), 2.0); assertEquals(0, s.getMinStartIndex()); s.add(new SimpleTimePeriod(0L, 50L), 3.0); assertEquals(2, s.getMinStartIndex()); } /** * Some tests for the getMaxStartIndex() method. */ @Test public void testGetMaxStartIndex() { TimePeriodValues s = new TimePeriodValues("Test"); assertEquals(-1, s.getMaxStartIndex()); s.add(new SimpleTimePeriod(100L, 200L), 1.0); assertEquals(0, s.getMaxStartIndex()); s.add(new SimpleTimePeriod(300L, 400L), 2.0); assertEquals(1, s.getMaxStartIndex()); s.add(new SimpleTimePeriod(0L, 50L), 3.0); assertEquals(1, s.getMaxStartIndex()); } /** * Some tests for the getMinMiddleIndex() method. */ @Test public void testGetMinMiddleIndex() { TimePeriodValues s = new TimePeriodValues("Test"); assertEquals(-1, s.getMinMiddleIndex()); s.add(new SimpleTimePeriod(100L, 200L), 1.0); assertEquals(0, s.getMinMiddleIndex()); s.add(new SimpleTimePeriod(300L, 400L), 2.0); assertEquals(0, s.getMinMiddleIndex()); s.add(new SimpleTimePeriod(0L, 50L), 3.0); assertEquals(2, s.getMinMiddleIndex()); } /** * Some tests for the getMaxMiddleIndex() method. */ @Test public void testGetMaxMiddleIndex() { TimePeriodValues s = new TimePeriodValues("Test"); assertEquals(-1, s.getMaxMiddleIndex()); s.add(new SimpleTimePeriod(100L, 200L), 1.0); assertEquals(0, s.getMaxMiddleIndex()); s.add(new SimpleTimePeriod(300L, 400L), 2.0); assertEquals(1, s.getMaxMiddleIndex()); s.add(new SimpleTimePeriod(0L, 50L), 3.0); assertEquals(1, s.getMaxMiddleIndex()); s.add(new SimpleTimePeriod(150L, 200L), 4.0); assertEquals(1, s.getMaxMiddleIndex()); } /** * Some tests for the getMinEndIndex() method. */ @Test public void getMinEndIndex() { TimePeriodValues s = new TimePeriodValues("Test"); assertEquals(-1, s.getMinEndIndex()); s.add(new SimpleTimePeriod(100L, 200L), 1.0); assertEquals(0, s.getMinEndIndex()); s.add(new SimpleTimePeriod(300L, 400L), 2.0); assertEquals(0, s.getMinEndIndex()); s.add(new SimpleTimePeriod(0L, 50L), 3.0); assertEquals(2, s.getMinEndIndex()); } /** * Some tests for the getMaxEndIndex() method. */ @Test public void getMaxEndIndex() { TimePeriodValues s = new TimePeriodValues("Test"); assertEquals(-1, s.getMaxEndIndex()); s.add(new SimpleTimePeriod(100L, 200L), 1.0); assertEquals(0, s.getMaxEndIndex()); s.add(new SimpleTimePeriod(300L, 400L), 2.0); assertEquals(1, s.getMaxEndIndex()); s.add(new SimpleTimePeriod(0L, 50L), 3.0); assertEquals(1, s.getMaxEndIndex()); } /** * A listener used for detecting series change events. */ static class MySeriesChangeListener implements SeriesChangeListener { SeriesChangeEvent lastEvent; /** * Creates a new listener. */ public MySeriesChangeListener() { this.lastEvent = null; } /** * Returns the last event. * * @return The last event (possibly <code>null</code>). */ public SeriesChangeEvent getLastEvent() { return this.lastEvent; } /** * Callback method for series change events. * * @param event the event. */ @Override public void seriesChanged(SeriesChangeEvent event) { this.lastEvent = event; } } }
12,472
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
YearTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/YearTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------- * YearTests.java * -------------- * (C) Copyright 2001-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 16-Nov-2001 : Version 1 (DG); * 19-Mar-2002 : Added tests for constructor that uses java.util.Date to ensure * it is consistent with the getStart() and getEnd() methods (DG); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 13-Mar-2003 : Added serialization test (DG); * 11-Jan-2005 : Added test for non-clonability (DG); * 05-Oct-2006 : Added some new tests (DG); * 11-Jul-2007 : Fixed bad time zone assumption (DG); * */ package org.jfree.data.time; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; import java.util.TimeZone; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; /** * Tests for the {@link Year} class. */ public class YearTest { /** * Check that a Year instance is equal to itself. * * SourceForge Bug ID: 558850. */ @Test public void testEqualsSelf() { Year year = new Year(); assertEquals(year, year); } /** * Tests the equals method. */ @Test public void testEquals() { Year year1 = new Year(2002); Year year2 = new Year(2002); assertEquals(year1, year2); year1 = new Year(1999); assertFalse(year1.equals(year2)); year2 = new Year(1999); assertEquals(year1, year2); } /** * In GMT, the end of 2001 is java.util.Date(1009843199999L). Use this to * check the year constructor. */ @Test public void testDateConstructor1() { TimeZone zone = TimeZone.getTimeZone("GMT"); Calendar c = new GregorianCalendar(zone); Date d1 = new Date(1009843199999L); Date d2 = new Date(1009843200000L); Year y1 = new Year(d1, zone, Locale.getDefault()); Year y2 = new Year(d2, zone, Locale.getDefault()); assertEquals(2001, y1.getYear()); assertEquals(1009843199999L, y1.getLastMillisecond(c)); assertEquals(2002, y2.getYear()); assertEquals(1009843200000L, y2.getFirstMillisecond(c)); } /** * In Los Angeles, the end of 2001 is java.util.Date(1009871999999L). Use * this to check the year constructor. */ @Test public void testDateConstructor2() { TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); Calendar c = new GregorianCalendar(zone); Year y1 = new Year(new Date(1009871999999L), zone, Locale.getDefault()); Year y2 = new Year(new Date(1009872000000L), zone, Locale.getDefault()); assertEquals(2001, y1.getYear()); assertEquals(1009871999999L, y1.getLastMillisecond(c)); assertEquals(2002, y2.getYear()); assertEquals(1009872000000L, y2.getFirstMillisecond(c)); } /** * Set up a year equal to 1900. Request the previous year, it should be * null. */ @Test public void testMinuss9999Previous() { Year current = new Year(-9999); Year previous = (Year) current.previous(); assertNull(previous); } /** * Set up a year equal to 1900. Request the next year, it should be 1901. */ @Test public void test1900Next() { Year current = new Year(1900); Year next = (Year) current.next(); assertEquals(1901, next.getYear()); } /** * Set up a year equal to 9999. Request the previous year, it should be * 9998. */ @Test public void test9999Previous() { Year current = new Year(9999); Year previous = (Year) current.previous(); assertEquals(9998, previous.getYear()); } /** * Set up a year equal to 9999. Request the next year, it should be null. */ @Test public void test9999Next() { Year current = new Year(9999); Year next = (Year) current.next(); assertNull(next); } /** * Tests the year string parser. */ @Test public void testParseYear() { // test 1... Year year = Year.parseYear("2000"); assertEquals(2000, year.getYear()); // test 2... year = Year.parseYear(" 2001 "); assertEquals(2001, year.getYear()); // test 3... year = Year.parseYear("99"); assertEquals(99, year.getYear()); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { Year y1 = new Year(1999); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(y1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); Year y2 = (Year) in.readObject(); in.close(); assertEquals(y1, y2); } /** * The {@link Year} class is immutable, so should not be {@link Cloneable}. */ @Test public void testNotCloneable() { Year y = new Year(1999); assertFalse(y instanceof Cloneable); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashcode() { Year y1 = new Year(1988); Year y2 = new Year(1988); assertEquals(y1, y2); int h1 = y1.hashCode(); int h2 = y2.hashCode(); assertEquals(h1, h2); } /** * Some checks for the getFirstMillisecond() method. */ @Test public void testGetFirstMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Year y = new Year(1970); // TODO: Check this result... assertEquals(-3600000L, y.getFirstMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); } /** * Some checks for the getFirstMillisecond(TimeZone) method. */ @Test public void testGetFirstMillisecondWithTimeZone() { Year y = new Year(1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); Calendar c = new GregorianCalendar(zone); assertEquals(-631123200000L, y.getFirstMillisecond(c)); // try null calendar try { y.getFirstMillisecond(null); fail("NullPointerException should have been thrown"); } catch (NullPointerException e) { //we expect to go in here } } /** * Some checks for the getFirstMillisecond(TimeZone) method. */ @Test public void testGetFirstMillisecondWithCalendar() { Year y = new Year(2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(978307200000L, y.getFirstMillisecond(calendar)); // try null calendar try { y.getFirstMillisecond(null); fail("NullPointerException should have been thrown"); } catch (NullPointerException e) { // we expect to go in here } } /** * Some checks for the getLastMillisecond() method. */ @Test public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Year y = new Year(1970); // TODO: Check this result... assertEquals(31532399999L, y.getLastMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); } /** * Some checks for the getLastMillisecond(TimeZone) method. */ @Test public void testGetLastMillisecondWithTimeZone() { Year y = new Year(1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); Calendar c = new GregorianCalendar(zone); assertEquals(-599587200001L, y.getLastMillisecond(c)); // try null calendar try { y.getLastMillisecond(null); fail("NullPointerException should have been thrown"); } catch (NullPointerException e) { //we expect to go in here } } /** * Some checks for the getLastMillisecond(TimeZone) method. */ @Test public void testGetLastMillisecondWithCalendar() { Year y = new Year(2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(1009843199999L, y.getLastMillisecond(calendar)); // try null calendar try { y.getLastMillisecond(null); fail("NullPointerException should have been thrown"); } catch (NullPointerException e) { //we expect to go in here } } /** * Some checks for the getSerialIndex() method. */ @Test public void testGetSerialIndex() { Year y = new Year(2000); assertEquals(2000L, y.getSerialIndex()); } /** * Some checks for the testNext() method. */ @Test public void testNext() { Year y = new Year(2000); y = (Year) y.next(); assertEquals(2001, y.getYear()); y = new Year(9999); assertNull(y.next()); } /** * Some checks for the getStart() method. */ @Test public void testGetStart() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 1, 0, 0, 0); cal.set(Calendar.MILLISECOND, 0); Year y = new Year(2006); assertEquals(cal.getTime(), y.getStart()); Locale.setDefault(saved); } /** * Some checks for the getEnd() method. */ @Test public void testGetEnd() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.DECEMBER, 31, 23, 59, 59); cal.set(Calendar.MILLISECOND, 999); Year y = new Year(2006); assertEquals(cal.getTime(), y.getEnd()); Locale.setDefault(saved); } }
12,338
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
SimpleTimePeriodTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/SimpleTimePeriodTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------------- * SimpleTimePeriodTests.java * -------------------------- * (C) Copyright 2003-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 13-Mar-2003 : Version 1 (DG); * 21-Oct-2003 : Added hashCode() test (DG); * 02-Jun-2008 : Added a test for immutability (DG); * */ package org.jfree.data.time; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.Date; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; /** * Tests for the {@link SimpleTimePeriod} class. */ public class SimpleTimePeriodTest { /** * Check that an instance is equal to itself. * * SourceForge Bug ID: 558850. */ @Test public void testEqualsSelf() { SimpleTimePeriod p = new SimpleTimePeriod(new Date(1000L), new Date(1001L)); assertEquals(p, p); } /** * Test the equals() method. */ @Test public void testEquals() { SimpleTimePeriod p1 = new SimpleTimePeriod(new Date(1000L), new Date(1004L)); SimpleTimePeriod p2 = new SimpleTimePeriod(new Date(1000L), new Date(1004L)); assertEquals(p1, p2); assertEquals(p2, p1); p1 = new SimpleTimePeriod(new Date(1002L), new Date(1004L)); assertFalse(p1.equals(p2)); p2 = new SimpleTimePeriod(new Date(1002L), new Date(1004L)); assertEquals(p1, p2); p1 = new SimpleTimePeriod(new Date(1002L), new Date(1003L)); assertFalse(p1.equals(p2)); p2 = new SimpleTimePeriod(new Date(1002L), new Date(1003L)); assertEquals(p1, p2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { SimpleTimePeriod p1 = new SimpleTimePeriod(new Date(1000L), new Date(1001L)); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(p1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); SimpleTimePeriod p2 = (SimpleTimePeriod) in.readObject(); in.close(); assertEquals(p1, p2); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashcode() { SimpleTimePeriod s1 = new SimpleTimePeriod(new Date(10L), new Date(20L)); SimpleTimePeriod s2 = new SimpleTimePeriod(new Date(10L), new Date(20L)); assertEquals(s1, s2); int h1 = s1.hashCode(); int h2 = s2.hashCode(); assertEquals(h1, h2); } /** * This class is immutable, so it should not implement Cloneable. */ @Test public void testClone() { SimpleTimePeriod s1 = new SimpleTimePeriod(new Date(10L), new Date(20)); assertFalse(s1 instanceof Cloneable); } /** * Some simple checks for immutability. */ @Test public void testImmutable() { SimpleTimePeriod p1 = new SimpleTimePeriod(new Date(10L), new Date(20L)); SimpleTimePeriod p2 = new SimpleTimePeriod(new Date(10L), new Date(20L)); assertEquals(p1, p2); p1.getStart().setTime(11L); assertEquals(p1, p2); Date d1 = new Date(10L); Date d2 = new Date(20L); p1 = new SimpleTimePeriod(d1, d2); d1.setTime(11L); assertEquals(new Date(10L), p1.getStart()); } /** * Some checks for the compareTo() method. */ @Test public void testCompareTo() { SimpleTimePeriod s1 = new SimpleTimePeriod(new Date(10L), new Date(20L)); SimpleTimePeriod s2 = new SimpleTimePeriod(new Date(10L), new Date(20L)); assertEquals(0, s1.compareTo(s2)); s1 = new SimpleTimePeriod(new Date(9L), new Date(21L)); s2 = new SimpleTimePeriod(new Date(10L), new Date(20L)); assertEquals(-1, s1.compareTo(s2)); s1 = new SimpleTimePeriod(new Date(11L), new Date(19L)); s2 = new SimpleTimePeriod(new Date(10L), new Date(20L)); assertEquals(1, s1.compareTo(s2)); s1 = new SimpleTimePeriod(new Date(9L), new Date(19L)); s2 = new SimpleTimePeriod(new Date(10L), new Date(20L)); assertEquals(-1, s1.compareTo(s2)); s1 = new SimpleTimePeriod(new Date(11L), new Date(21)); s2 = new SimpleTimePeriod(new Date(10L), new Date(20L)); assertEquals(1, s1.compareTo(s2)); s1 = new SimpleTimePeriod(new Date(10L), new Date(18)); s2 = new SimpleTimePeriod(new Date(10L), new Date(20L)); assertEquals(-1, s1.compareTo(s2)); s1 = new SimpleTimePeriod(new Date(10L), new Date(22)); s2 = new SimpleTimePeriod(new Date(10L), new Date(20L)); assertEquals(1, s1.compareTo(s2)); } }
6,595
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
WeekTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/WeekTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------- * WeekTests.java * -------------- * (C) Copyright 2002-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 05-Apr-2002 : Version 1 (DG); * 26-Jun-2002 : Removed unnecessary imports (DG); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 13-Mar-2003 : Added serialization test (DG); * 21-Oct-2003 : Added hashCode test (DG); * 06-Apr-2006 : Added testBug1448828() method (DG); * 01-Jun-2006 : Added testBug1498805() method (DG); * 11-Jul-2007 : Fixed bad time zone assumption (DG); * 28-Aug-2007 : Added test for constructor problem (DG); * 19-Dec-2007 : Set default locale for tests that are sensitive * to the locale (DG); * */ package org.jfree.data.time; import org.junit.Before; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; import java.util.TimeZone; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; /** * Tests for the {@link Week} class. */ public class WeekTest { /** A week. */ private Week w1Y1900; /** A week. */ private Week w2Y1900; /** A week. */ private Week w51Y9999; /** A week. */ private Week w52Y9999; /** * Common test setup. */ @Before public void setUp() { this.w1Y1900 = new Week(1, 1900); this.w2Y1900 = new Week(2, 1900); this.w51Y9999 = new Week(51, 9999); this.w52Y9999 = new Week(52, 9999); } /** * Tests the equals method. */ @Test public void testEquals() { Week w1 = new Week(1, 2002); Week w2 = new Week(1, 2002); assertEquals(w1, w2); assertEquals(w2, w1); w1 = new Week(2, 2002); assertFalse(w1.equals(w2)); w2 = new Week(2, 2002); assertEquals(w1, w2); w1 = new Week(2, 2003); assertFalse(w1.equals(w2)); w2 = new Week(2, 2003); assertEquals(w1, w2); } /** * Request the week before week 1, 1900: it should be <code>null</code>. */ @Test public void testW1Y1900Previous() { Week previous = (Week) this.w1Y1900.previous(); assertNull(previous); } /** * Request the week after week 1, 1900: it should be week 2, 1900. */ @Test public void testW1Y1900Next() { Week next = (Week) this.w1Y1900.next(); assertEquals(this.w2Y1900, next); } /** * Request the week before w52, 9999: it should be week 51, 9999. */ @Test public void testW52Y9999Previous() { Week previous = (Week) this.w52Y9999.previous(); assertEquals(this.w51Y9999, previous); } /** * Request the week after w52, 9999: it should be <code>null</code>. */ @Test public void testW52Y9999Next() { Week next = (Week) this.w52Y9999.next(); assertNull(next); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { Week w1 = new Week(24, 1999); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(w1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); Week w2 = (Week) in.readObject(); in.close(); assertEquals(w1, w2); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashcode() { Week w1 = new Week(2, 2003); Week w2 = new Week(2, 2003); assertEquals(w1, w2); int h1 = w1.hashCode(); int h2 = w2.hashCode(); assertEquals(h1, h2); } /** * The {@link Week} class is immutable, so should not be {@link Cloneable}. */ @Test public void testNotCloneable() { Week w = new Week(1, 1999); assertFalse(w instanceof Cloneable); } /** * The first week in 2005 should span the range: * * TimeZone | Start Millis | End Millis | Start Date | End Date * -----------------+---------------+---------------+-------------+------------ * Europe/London | 1104710400000 | 1105315199999 | 3-Jan-2005 | 9-Jan-2005 * Europe/Paris | 1104706800000 | 1105311599999 | 3-Jan-2005 | 2-Jan-2005 * America/New_York | 1104037200000 | 1104641999999 | 26-Dec-2004 | 1-Jan-2005 * * In London and Paris, Monday is the first day of the week, while in the * US it is Sunday. * * Previously, we were using these values, but see Java Bug ID 4960215: * * TimeZone | Start Millis | End Millis | Start Date | End Date * -----------------+---------------+---------------+-------------+------------ * Europe/London | 1104105600000 | 1104710399999 | 27-Dec-2004 | 2-Jan-2005 * Europe/Paris | 1104102000000 | 1104706799999 | 27-Dec-2004 | 2-Jan-2005 * America/New_York | 1104037200000 | 1104641999999 | 26-Dec-2004 | 1-Jan-2005 */ @Test public void testWeek12005() { Week w1 = new Week(1, 2005); Calendar c1 = Calendar.getInstance( TimeZone.getTimeZone("Europe/London"), Locale.UK); c1.setMinimalDaysInFirstWeek(4); // see Java Bug ID 4960215 assertEquals(1104710400000L, w1.getFirstMillisecond(c1)); assertEquals(1105315199999L, w1.getLastMillisecond(c1)); Calendar c2 = Calendar.getInstance( TimeZone.getTimeZone("Europe/Paris"), Locale.FRANCE); c2.setMinimalDaysInFirstWeek(4); // see Java Bug ID 4960215 assertEquals(1104706800000L, w1.getFirstMillisecond(c2)); assertEquals(1105311599999L, w1.getLastMillisecond(c2)); Calendar c3 = Calendar.getInstance( TimeZone.getTimeZone("America/New_York"), Locale.US); assertEquals(1104037200000L, w1.getFirstMillisecond(c3)); assertEquals(1104641999999L, w1.getLastMillisecond(c3)); } /** * The 53rd week in 2004 in London and Paris should span the range: * * TimeZone | Start Millis | End Millis | Start Date | End Date * -----------------+---------------+---------------+-------------+------------ * Europe/London | 1104105600000 | 1104710399999 | 27-Dec-2004 | 02-Jan-2005 * Europe/Paris | 1104102000000 | 1104706799999 | 27-Dec-2004 | 02-Jan-2005 * * The 53rd week in 2005 in New York should span the range: * * TimeZone | Start Millis | End Millis | Start Date | End Date * -----------------+---------------+---------------+-------------+------------ * America/New_York | 1135486800000 | 1136091599999 | 25-Dec-2005 | 31-Dec-2005 * * In London and Paris, Monday is the first day of the week, while in the * US it is Sunday. */ @Test public void testWeek532005() { Week w1 = new Week(53, 2004); Calendar c1 = Calendar.getInstance( TimeZone.getTimeZone("Europe/London"), Locale.UK); c1.setMinimalDaysInFirstWeek(4); // see Java Bug ID 4960215 assertEquals(1104105600000L, w1.getFirstMillisecond(c1)); assertEquals(1104710399999L, w1.getLastMillisecond(c1)); Calendar c2 = Calendar.getInstance( TimeZone.getTimeZone("Europe/Paris"), Locale.FRANCE); c2.setMinimalDaysInFirstWeek(4); // see Java Bug ID 4960215 assertEquals(1104102000000L, w1.getFirstMillisecond(c2)); assertEquals(1104706799999L, w1.getLastMillisecond(c2)); w1 = new Week(53, 2005); Calendar c3 = Calendar.getInstance( TimeZone.getTimeZone("America/New_York"), Locale.US); assertEquals(1135486800000L, w1.getFirstMillisecond(c3)); assertEquals(1136091599999L, w1.getLastMillisecond(c3)); } /** * A test case for bug 1448828. */ @Test public void testBug1448828() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); try { Week w = new Week(new Date(1136109830000l), TimeZone.getTimeZone("GMT"), Locale.UK); assertEquals(2005, w.getYearValue()); assertEquals(52, w.getWeek()); } finally { Locale.setDefault(saved); } } /** * A test case for bug 1498805. */ @Test public void testBug1498805() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); try { TimeZone zone = TimeZone.getTimeZone("GMT"); GregorianCalendar gc = new GregorianCalendar(zone); gc.set(2005, Calendar.JANUARY, 1, 12, 0, 0); Week w = new Week(gc.getTime(), zone, Locale.UK); assertEquals(53, w.getWeek()); assertEquals(new Year(2004), w.getYear()); } finally { Locale.setDefault(saved); } } /** * Some checks for the getFirstMillisecond() method. */ @Test public void testGetFirstMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Week w = new Week(3, 1970); assertEquals(946800000L, w.getFirstMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); } /** * Some checks for the getFirstMillisecond(TimeZone) method. */ @Test public void testGetFirstMillisecondWithTimeZone() { Week w = new Week(47, 1950); Locale saved = Locale.getDefault(); Locale.setDefault(Locale.US); try { TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); Calendar c = new GregorianCalendar(zone); assertEquals(-603302400000L, w.getFirstMillisecond(c)); } finally { Locale.setDefault(saved); } // try null calendar try { w.getFirstMillisecond(null); fail("NullPointerException should have been thrown"); } catch (NullPointerException e) { //should go in here } } /** * Some checks for the getFirstMillisecond(TimeZone) method. */ @Test public void testGetFirstMillisecondWithCalendar() { Week w = new Week(1, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(978307200000L, w.getFirstMillisecond(calendar)); // try null calendar try { w.getFirstMillisecond(null); fail("NullPointerException should have been thrown"); } catch (NullPointerException e) { //we should go in here } } /** * Some checks for the getLastMillisecond() method. */ @Test public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Week w = new Week(31, 1970); assertEquals(18485999999L, w.getLastMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); } /** * Some checks for the getLastMillisecond(TimeZone) method. */ @Test public void testGetLastMillisecondWithTimeZone() { Week w = new Week(2, 1950); Locale saved = Locale.getDefault(); Locale.setDefault(Locale.US); try { TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); Calendar c = new GregorianCalendar(zone); assertEquals(-629913600001L, w.getLastMillisecond(c)); } finally { Locale.setDefault(saved); } // try null zone try { w.getLastMillisecond(null); fail("NullPointerException should have been thrown"); } catch (NullPointerException e) { //we should go in here } } /** * Some checks for the getLastMillisecond(TimeZone) method. */ @Test public void testGetLastMillisecondWithCalendar() { Week w = new Week(52, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(1009756799999L, w.getLastMillisecond(calendar)); // try null calendar try { w.getLastMillisecond(null); fail("NullPointerException should have been thrown"); } catch (NullPointerException e) { //we should go in here } } /** * Some checks for the getSerialIndex() method. */ @Test public void testGetSerialIndex() { Week w = new Week(1, 2000); assertEquals(106001L, w.getSerialIndex()); w = new Week(1, 1900); assertEquals(100701L, w.getSerialIndex()); } /** * Some checks for the testNext() method. */ @Test public void testNext() { Week w = new Week(12, 2000); w = (Week) w.next(); assertEquals(new Year(2000), w.getYear()); assertEquals(13, w.getWeek()); w = new Week(53, 9999); assertNull(w.next()); } /** * Some checks for the getStart() method. */ @Test public void testGetStart() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 16, 0, 0, 0); cal.set(Calendar.MILLISECOND, 0); Week w = new Week(3, 2006); assertEquals(cal.getTime(), w.getStart()); Locale.setDefault(saved); } /** * Some checks for the getEnd() method. */ @Test public void testGetEnd() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 8, 23, 59, 59); cal.set(Calendar.MILLISECOND, 999); Week w = new Week(1, 2006); assertEquals(cal.getTime(), w.getEnd()); Locale.setDefault(saved); } /** * A test for a problem in constructing a new Week instance. */ @Test public void testConstructor() { Locale savedLocale = Locale.getDefault(); TimeZone savedZone = TimeZone.getDefault(); Locale.setDefault(new Locale("da", "DK")); TimeZone.setDefault(TimeZone.getTimeZone("Europe/Copenhagen")); GregorianCalendar cal = (GregorianCalendar) Calendar.getInstance( TimeZone.getDefault(), Locale.getDefault()); // first day of week is monday assertEquals(Calendar.MONDAY, cal.getFirstDayOfWeek()); cal.set(2007, Calendar.AUGUST, 26, 1, 0, 0); cal.set(Calendar.MILLISECOND, 0); Date t = cal.getTime(); Week w = new Week(t, TimeZone.getTimeZone("Europe/Copenhagen"), Locale.getDefault()); assertEquals(34, w.getWeek()); Locale.setDefault(Locale.US); TimeZone.setDefault(TimeZone.getTimeZone("US/Detroit")); cal = (GregorianCalendar) Calendar.getInstance(TimeZone.getDefault()); // first day of week is Sunday assertEquals(Calendar.SUNDAY, cal.getFirstDayOfWeek()); cal.set(2007, Calendar.AUGUST, 26, 1, 0, 0); cal.set(Calendar.MILLISECOND, 0); t = cal.getTime(); w = new Week(t, TimeZone.getTimeZone("Europe/Copenhagen"), Locale.getDefault()); assertEquals(35, w.getWeek()); w = new Week(t, TimeZone.getTimeZone("Europe/Copenhagen"), new Locale("da", "DK")); assertEquals(34, w.getWeek()); Locale.setDefault(savedLocale); TimeZone.setDefault(savedZone); } }
17,901
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TimeSeriesDataItemTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/TimeSeriesDataItemTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------------- * TimeSeriesDataItemTests.java * ---------------------------- * (C) Copyright 2003-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 13-Mar-2003 : Version 1 (DG); * */ package org.jfree.data.time; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; /** * Tests for the {@link TimeSeriesDataItem} class. */ public class TimeSeriesDataItemTest { /** * Test that an instance is equal to itself. * * SourceForge Bug ID: 558850. */ @Test public void testEqualsSelf() { TimeSeriesDataItem item = new TimeSeriesDataItem( new Day(23, 9, 2001), 99.7 ); assertEquals(item, item); } /** * Test the equals() method. */ @Test public void testEquals() { TimeSeriesDataItem item1 = new TimeSeriesDataItem( new Day(23, 9, 2001), 99.7 ); TimeSeriesDataItem item2 = new TimeSeriesDataItem( new Day(23, 9, 2001), 99.7 ); assertEquals(item1, item2); assertEquals(item2, item1); item1.setValue(5); assertFalse(item1.equals(item2)); item2.setValue(5); assertEquals(item1, item2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { TimeSeriesDataItem item1 = new TimeSeriesDataItem( new Day(23, 9, 2001), 99.7 ); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(item1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); TimeSeriesDataItem item2 = (TimeSeriesDataItem) in.readObject(); in.close(); assertEquals(item1, item2); } }
3,553
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TimePeriodValuesCollectionTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/TimePeriodValuesCollectionTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------------------ * TimePeriodValuesCollectionTests.java * ------------------------------------ * (C) Copyright 2005-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 11-Mar-2005 : Version 1 (DG); * 08-Mar-2007 : Added testGetSeries() (DG); * 11-Jun-2007 : Added tests for getDomainBounds() (DG); * 10-Jul-2007 : Fixed compile errors (DG); * 07-Apr-2008 : Added more checks to * testGetDomainBoundsWithInterval() (DG); * */ package org.jfree.data.time; import org.jfree.data.Range; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; /** * Some tests for the {@link TimePeriodValuesCollection} class. */ public class TimePeriodValuesCollectionTest { /** * A test for bug report 1161340. I wasn't able to reproduce the problem * with this test. */ @Test public void test1161340() { TimePeriodValuesCollection dataset = new TimePeriodValuesCollection(); TimePeriodValues v1 = new TimePeriodValues("V1"); v1.add(new Day(11, 3, 2005), 1.2); v1.add(new Day(12, 3, 2005), 3.4); dataset.addSeries(v1); assertEquals(1, dataset.getSeriesCount()); dataset.removeSeries(v1); assertEquals(0, dataset.getSeriesCount()); TimePeriodValues v2 = new TimePeriodValues("V2"); v1.add(new Day(5, 3, 2005), 1.2); v1.add(new Day(6, 3, 2005), 3.4); dataset.addSeries(v2); assertEquals(1, dataset.getSeriesCount()); } /** * Tests the equals() method. */ @Test public void testEquals() { TimePeriodValuesCollection c1 = new TimePeriodValuesCollection(); TimePeriodValuesCollection c2 = new TimePeriodValuesCollection(); assertEquals(c1, c2); c1.setXPosition(TimePeriodAnchor.END); assertFalse(c1.equals(c2)); c2.setXPosition(TimePeriodAnchor.END); assertEquals(c1, c2); TimePeriodValues v1 = new TimePeriodValues("Test"); TimePeriodValues v2 = new TimePeriodValues("Test"); c1.addSeries(v1); assertFalse(c1.equals(c2)); c2.addSeries(v2); assertEquals(c1, c2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { TimePeriodValuesCollection c1 = new TimePeriodValuesCollection(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(c1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); TimePeriodValuesCollection c2 = (TimePeriodValuesCollection) in.readObject(); in.close(); assertEquals(c1, c2); } /** * Some basic checks for the getSeries() method. */ @Test public void testGetSeries() { TimePeriodValuesCollection c1 = new TimePeriodValuesCollection(); TimePeriodValues s1 = new TimePeriodValues("Series 1"); c1.addSeries(s1); assertEquals("Series 1", c1.getSeries(0).getKey()); try { c1.getSeries(-1); fail("IllegalArgumentException should have been thrown on negative series"); } catch (IllegalArgumentException e) { assertEquals("Index 'series' out of range.", e.getMessage()); } try { c1.getSeries(1); fail("IllegalArgumentException should have been thrown on index greater than series length"); } catch (IllegalArgumentException e) { assertEquals("Index 'series' out of range.", e.getMessage()); } } private static final double EPSILON = 0.0000000001; /** * Some checks for the getDomainBounds() method. */ @Test public void testGetDomainBoundsWithoutInterval() { // check empty dataset TimePeriodValuesCollection dataset = new TimePeriodValuesCollection(); Range r = dataset.getDomainBounds(false); assertNull(r); // check dataset with one time period TimePeriodValues s1 = new TimePeriodValues("S1"); s1.add(new SimpleTimePeriod(1000L, 2000L), 1.0); dataset.addSeries(s1); r = dataset.getDomainBounds(false); assertEquals(1500.0, r.getLowerBound(), EPSILON); assertEquals(1500.0, r.getUpperBound(), EPSILON); // check dataset with two time periods s1.add(new SimpleTimePeriod(1500L, 3000L), 2.0); r = dataset.getDomainBounds(false); assertEquals(1500.0, r.getLowerBound(), EPSILON); assertEquals(2250.0, r.getUpperBound(), EPSILON); } /** * Some more checks for the getDomainBounds() method. * * @see #testGetDomainBoundsWithoutInterval() */ @Test public void testGetDomainBoundsWithInterval() { // check empty dataset TimePeriodValuesCollection dataset = new TimePeriodValuesCollection(); Range r = dataset.getDomainBounds(true); assertNull(r); // check dataset with one time period TimePeriodValues s1 = new TimePeriodValues("S1"); s1.add(new SimpleTimePeriod(1000L, 2000L), 1.0); dataset.addSeries(s1); r = dataset.getDomainBounds(true); assertEquals(1000.0, r.getLowerBound(), EPSILON); assertEquals(2000.0, r.getUpperBound(), EPSILON); // check dataset with two time periods s1.add(new SimpleTimePeriod(1500L, 3000L), 2.0); r = dataset.getDomainBounds(true); assertEquals(1000.0, r.getLowerBound(), EPSILON); assertEquals(3000.0, r.getUpperBound(), EPSILON); // add a third time period s1.add(new SimpleTimePeriod(6000L, 7000L), 1.5); r = dataset.getDomainBounds(true); assertEquals(1000.0, r.getLowerBound(), EPSILON); assertEquals(7000.0, r.getUpperBound(), EPSILON); // add a fourth time period s1.add(new SimpleTimePeriod(4000L, 5000L), 1.4); r = dataset.getDomainBounds(true); assertEquals(1000.0, r.getLowerBound(), EPSILON); assertEquals(7000.0, r.getUpperBound(), EPSILON); } }
8,072
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
MillisecondTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/MillisecondTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------- * MillisecondTests.java * --------------------- * (C) Copyright 2002-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 29-Jan-2002 : Version 1 (DG); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 21-Oct-2003 : Added hashCode tests (DG); * 29-Apr-2004 : Added test for getMiddleMillisecond() method (DG); * 11-Jan-2005 : Added test for non-clonability (DG); * 05-Oct-2006 : Added some tests (DG); * 11-Jul-2007 : Fixed bad time zone assumption (DG); * */ package org.jfree.data.time; import org.jfree.chart.date.MonthConstants; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; import java.util.TimeZone; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.fail; /** * Tests for the {@link Millisecond} class. */ public class MillisecondTest { /** * Check that a {@link Millisecond} instance is equal to itself. * * SourceForge Bug ID: 558850. */ @Test public void testEqualsSelf() { Millisecond millisecond = new Millisecond(); assertEquals(millisecond, millisecond); } /** * Tests the equals method. */ @Test public void testEquals() { Day day1 = new Day(29, MonthConstants.MARCH, 2002); Hour hour1 = new Hour(15, day1); Minute minute1 = new Minute(15, hour1); Second second1 = new Second(34, minute1); Millisecond milli1 = new Millisecond(999, second1); Day day2 = new Day(29, MonthConstants.MARCH, 2002); Hour hour2 = new Hour(15, day2); Minute minute2 = new Minute(15, hour2); Second second2 = new Second(34, minute2); Millisecond milli2 = new Millisecond(999, second2); assertEquals(milli1, milli2); } /** * In GMT, the 4.55:59.123pm on 21 Mar 2002 is * java.util.Date(1016729759123L). Use this to check the Millisecond * constructor. */ @Test public void testDateConstructor1() { TimeZone zone = TimeZone.getTimeZone("GMT"); Locale locale = Locale.getDefault(); // locale should not matter here Calendar c = new GregorianCalendar(zone); Millisecond m1 = new Millisecond(new Date(1016729759122L), zone, locale); Millisecond m2 = new Millisecond(new Date(1016729759123L), zone, locale); assertEquals(122, m1.getMillisecond()); assertEquals(1016729759122L, m1.getLastMillisecond(c)); assertEquals(123, m2.getMillisecond()); assertEquals(1016729759123L, m2.getFirstMillisecond(c)); } /** * In Tallinn, the 4.55:59.123pm on 21 Mar 2002 is * java.util.Date(1016722559123L). Use this to check the Millisecond * constructor. */ @Test public void testDateConstructor2() { TimeZone zone = TimeZone.getTimeZone("Europe/Tallinn"); Locale locale = Locale.getDefault(); // locale should not matter here Calendar c = new GregorianCalendar(zone); Millisecond m1 = new Millisecond(new Date(1016722559122L), zone, locale); Millisecond m2 = new Millisecond(new Date(1016722559123L), zone, locale); assertEquals(122, m1.getMillisecond()); assertEquals(1016722559122L, m1.getLastMillisecond(c)); assertEquals(123, m2.getMillisecond()); assertEquals(1016722559123L, m2.getFirstMillisecond(c)); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { Millisecond m1 = new Millisecond(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(m1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); Millisecond m2 = (Millisecond) in.readObject(); in.close(); assertEquals(m1, m2); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashcode() { Millisecond m1 = new Millisecond(599, 23, 45, 7, 9, 10, 2007); Millisecond m2 = new Millisecond(599, 23, 45, 7, 9, 10, 2007); assertEquals(m1, m2); int hash1 = m1.hashCode(); int hash2 = m2.hashCode(); assertEquals(hash1, hash2); } /** * A test for bug report 943985 - the calculation for the middle * millisecond is incorrect for odd milliseconds. */ @Test public void test943985() { Millisecond ms = new Millisecond(new java.util.Date(4)); assertEquals(ms.getFirstMillisecond(), ms.getMiddleMillisecond()); assertEquals(ms.getMiddleMillisecond(), ms.getLastMillisecond()); ms = new Millisecond(new java.util.Date(5)); assertEquals(ms.getFirstMillisecond(), ms.getMiddleMillisecond()); assertEquals(ms.getMiddleMillisecond(), ms.getLastMillisecond()); } /** * The {@link Millisecond} class is immutable, so should not be * {@link Cloneable}. */ @Test public void testNotCloneable() { Millisecond m = new Millisecond(599, 23, 45, 7, 9, 10, 2007); assertFalse(m instanceof Cloneable); } /** * Some checks for the getFirstMillisecond() method. */ @Test public void testGetFirstMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Millisecond m = new Millisecond(500, 15, 43, 15, 1, 4, 2006); assertEquals(1143902595500L, m.getFirstMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); } /** * Some checks for the getFirstMillisecond(TimeZone) method. */ @Test public void testGetFirstMillisecondWithTimeZone() { Millisecond m = new Millisecond(500, 50, 59, 15, 1, 4, 1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); Calendar c = new GregorianCalendar(zone); assertEquals(-623289609500L, m.getFirstMillisecond(c)); // try null calendar try { m.getFirstMillisecond(null); fail("NullPointerException should have been thrown"); } catch (NullPointerException e) { //we expect to go in here } } /** * Some checks for the getFirstMillisecond(TimeZone) method. */ @Test public void testGetFirstMillisecondWithCalendar() { Millisecond m = new Millisecond(500, 55, 40, 2, 15, 4, 2000); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(955766455500L, m.getFirstMillisecond(calendar)); // try null calendar try { m.getFirstMillisecond(null); fail("NullPointerException should have been thrown"); } catch (NullPointerException e) { // we expect to go in here } } /** * Some checks for the getLastMillisecond() method. */ @Test public void testGetLastMillisecond() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.UK); TimeZone savedZone = TimeZone.getDefault(); TimeZone.setDefault(TimeZone.getTimeZone("Europe/London")); Millisecond m = new Millisecond(750, 1, 1, 1, 1, 1, 1970); assertEquals(61750L, m.getLastMillisecond()); Locale.setDefault(saved); TimeZone.setDefault(savedZone); } /** * Some checks for the getLastMillisecond(TimeZone) method. */ @Test public void testGetLastMillisecondWithTimeZone() { Millisecond m = new Millisecond(750, 55, 1, 2, 7, 7, 1950); TimeZone zone = TimeZone.getTimeZone("America/Los_Angeles"); Calendar c = new GregorianCalendar(zone); assertEquals(-614962684250L, m.getLastMillisecond(c)); // try null calendar try { m.getLastMillisecond(null); fail("Should have thrown a NullPointerException"); } catch (NullPointerException e) { //we should enter here } } /** * Some checks for the getLastMillisecond(TimeZone) method. */ @Test public void testGetLastMillisecondWithCalendar() { Millisecond m = new Millisecond(250, 50, 45, 21, 21, 4, 2001); GregorianCalendar calendar = new GregorianCalendar(Locale.GERMANY); calendar.setTimeZone(TimeZone.getTimeZone("Europe/Frankfurt")); assertEquals(987889550250L, m.getLastMillisecond(calendar)); // try null calendar try { m.getLastMillisecond(null); fail("Should have thrown NullPointerException"); } catch (NullPointerException e) { //expected to enter here } } /** * Some checks for the getSerialIndex() method. */ @Test public void testGetSerialIndex() { Millisecond m = new Millisecond(500, 1, 1, 1, 1, 1, 2000); assertEquals(3155850061500L, m.getSerialIndex()); m = new Millisecond(500, 1, 1, 1, 1, 1, 1900); // TODO: this must be wrong... assertEquals(176461500L, m.getSerialIndex()); } /** * Some checks for the testNext() method. */ @Test public void testNext() { Millisecond m = new Millisecond(555, 55, 30, 1, 12, 12, 2000); m = (Millisecond) m.next(); assertEquals(2000, m.getSecond().getMinute().getHour().getYear()); assertEquals(12, m.getSecond().getMinute().getHour().getMonth()); assertEquals(12, m.getSecond().getMinute().getHour().getDayOfMonth()); assertEquals(1, m.getSecond().getMinute().getHour().getHour()); assertEquals(30, m.getSecond().getMinute().getMinute()); assertEquals(55, m.getSecond().getSecond()); assertEquals(556, m.getMillisecond()); m = new Millisecond(999, 59, 59, 23, 31, 12, 9999); assertNull(m.next()); } /** * Some checks for the getStart() method. */ @Test public void testGetStart() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 16, 3, 47, 55); cal.set(Calendar.MILLISECOND, 555); Millisecond m = new Millisecond(555, 55, 47, 3, 16, 1, 2006); assertEquals(cal.getTime(), m.getStart()); Locale.setDefault(saved); } /** * Some checks for the getEnd() method. */ @Test public void testGetEnd() { Locale saved = Locale.getDefault(); Locale.setDefault(Locale.ITALY); Calendar cal = Calendar.getInstance(Locale.ITALY); cal.set(2006, Calendar.JANUARY, 16, 3, 47, 55); cal.set(Calendar.MILLISECOND, 555); Millisecond m = new Millisecond(555, 55, 47, 3, 16, 1, 2006); assertEquals(cal.getTime(), m.getEnd()); Locale.setDefault(saved); } }
13,037
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
OHLCSeriesTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/ohlc/OHLCSeriesTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * OHLCSeriesTests.java * -------------------- * (C) Copyright 2006-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 04-Dec-2006 : Version 1, based on XYSeriesTests (DG); * 27-Nov-2007 : Added testClear() method (DG); * 23-May-2009 : Added testHashCode() (DG); * 17-Jun-2009 : Added testRemove_int() (DG); * */ package org.jfree.data.time.ohlc; import org.jfree.data.general.SeriesChangeEvent; import org.jfree.data.general.SeriesChangeListener; import org.jfree.data.general.SeriesException; import org.jfree.data.time.Year; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** * Tests for the {@link OHLCSeries} class. */ public class OHLCSeriesTest implements SeriesChangeListener { SeriesChangeEvent lastEvent; /** * Records a change event. * * @param event the event. */ @Override public void seriesChanged(SeriesChangeEvent event) { this.lastEvent = event; } /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { OHLCSeries s1 = new OHLCSeries("s1"); OHLCSeries s2 = new OHLCSeries("s1"); assertEquals(s1, s2); // seriesKey s1 = new OHLCSeries("s2"); assertFalse(s1.equals(s2)); s2 = new OHLCSeries("s2"); assertEquals(s1, s2); // add a value s1.add(new Year(2006), 2.0, 4.0, 1.0, 3.0); assertFalse(s1.equals(s2)); s2.add(new Year(2006), 2.0, 4.0, 1.0, 3.0); assertEquals(s2, s1); // add another value s1.add(new Year(2008), 2.0, 4.0, 1.0, 3.0); assertFalse(s1.equals(s2)); s2.add(new Year(2008), 2.0, 4.0, 1.0, 3.0); assertEquals(s2, s1); // remove a value s1.remove(new Year(2008)); assertFalse(s1.equals(s2)); s2.remove(new Year(2008)); assertEquals(s2, s1); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashcode() { OHLCSeries s1 = new OHLCSeries("Test"); s1.add(new Year(2009), 1.0, 3.0, 2.0, 1.4); OHLCSeries s2 = new OHLCSeries("Test"); s2.add(new Year(2009), 1.0, 3.0, 2.0, 1.4); assertEquals(s1, s2); int h1 = s1.hashCode(); int h2 = s2.hashCode(); assertEquals(h1, h2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { OHLCSeries s1 = new OHLCSeries("s1"); s1.add(new Year(2006), 2.0, 4.0, 1.0, 3.0); OHLCSeries s2 = (OHLCSeries) s1.clone(); assertNotSame(s1, s2); assertSame(s1.getClass(), s2.getClass()); assertEquals(s1, s2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { OHLCSeries s1 = new OHLCSeries("s1"); s1.add(new Year(2006), 2.0, 4.0, 1.0, 3.0); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(s1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); OHLCSeries s2 = (OHLCSeries) in.readObject(); in.close(); assertEquals(s1, s2); } /** * Simple test for the indexOf() method. */ @Test public void testIndexOf() { OHLCSeries s1 = new OHLCSeries("s1"); s1.add(new Year(2006), 2.0, 4.0, 1.0, 3.0); s1.add(new Year(2011), 2.0, 4.0, 1.0, 3.0); s1.add(new Year(2010), 2.0, 4.0, 1.0, 3.0); assertEquals(0, s1.indexOf(new Year(2006))); assertEquals(1, s1.indexOf(new Year(2010))); assertEquals(2, s1.indexOf(new Year(2011))); } /** * Simple test for the remove() method. */ @Test public void testRemove() { OHLCSeries s1 = new OHLCSeries("s1"); s1.add(new Year(2006), 2.0, 4.0, 1.0, 3.0); s1.add(new Year(2011), 2.1, 4.1, 1.1, 3.1); s1.add(new Year(2010), 2.2, 4.2, 1.2, 3.2); assertEquals(3, s1.getItemCount()); s1.remove(new Year(2010)); assertEquals(new Year(2011), s1.getPeriod(1)); s1.remove(new Year(2006)); assertEquals(new Year(2011), s1.getPeriod(0)); } /** * A check for the remove(int) method. */ @Test public void testRemove_int() { OHLCSeries s1 = new OHLCSeries("s1"); s1.add(new Year(2006), 2.0, 4.0, 1.0, 3.0); s1.add(new Year(2011), 2.1, 4.1, 1.1, 3.1); s1.add(new Year(2010), 2.2, 4.2, 1.2, 3.2); assertEquals(3, s1.getItemCount()); s1.remove(s1.getItemCount() - 1); assertEquals(2, s1.getItemCount()); assertEquals(new Year(2010), s1.getPeriod(1)); } /** * If you add a duplicate period, an exception should be thrown. */ @Test public void testAdditionOfDuplicatePeriod() { OHLCSeries s1 = new OHLCSeries("s1"); s1.add(new Year(2006), 1.0, 1.0, 1.0, 1.0); try { s1.add(new Year(2006), 1.0, 1.0, 1.0, 1.0); fail("Should have thrown a SeriesException on duplicate value"); } catch (SeriesException e) { assertEquals("X-value already exists.", e.getMessage()); } } /** * A simple check that the maximumItemCount attribute is working. */ @Test public void testSetMaximumItemCount() { OHLCSeries s1 = new OHLCSeries("s1"); assertEquals(Integer.MAX_VALUE, s1.getMaximumItemCount()); s1.setMaximumItemCount(2); assertEquals(2, s1.getMaximumItemCount()); s1.add(new Year(2006), 1.0, 1.1, 1.1, 1.1); s1.add(new Year(2007), 2.0, 2.2, 2.2, 2.2); s1.add(new Year(2008), 3.0, 3.3, 3.3, 3.3); assertEquals(new Year(2007), s1.getPeriod(0)); assertEquals(new Year(2008), s1.getPeriod(1)); } /** * Check that the maximum item count can be applied retrospectively. */ @Test public void testSetMaximumItemCount2() { OHLCSeries s1 = new OHLCSeries("s1"); s1.add(new Year(2006), 1.0, 1.1, 1.1, 1.1); s1.add(new Year(2007), 2.0, 2.2, 2.2, 2.2); s1.add(new Year(2008), 3.0, 3.3, 3.3, 3.3); s1.setMaximumItemCount(2); assertEquals(new Year(2007), s1.getPeriod(0)); assertEquals(new Year(2008), s1.getPeriod(1)); } /** * Some checks for the clear() method. */ @Test public void testClear() { OHLCSeries s1 = new OHLCSeries("S1"); s1.addChangeListener(this); s1.clear(); assertNull(this.lastEvent); assertTrue(s1.isEmpty()); s1.add(new Year(2006), 1.0, 1.1, 1.1, 1.1); assertFalse(s1.isEmpty()); s1.clear(); assertNotNull(this.lastEvent); assertTrue(s1.isEmpty()); } }
9,005
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
OHLCTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/ohlc/OHLCTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------- * OHLCTests.java * -------------- * (C) Copyright 2006-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 04-Dec-2006 : Version 1 (DG); * 23-May-2009 : Added testHashCode() (DG); * */ package org.jfree.data.time.ohlc; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; /** * Tests for the {@link OHLC} class. */ public class OHLCTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { OHLC i1 = new OHLC(2.0, 4.0, 1.0, 3.0); OHLC i2 = new OHLC(2.0, 4.0, 1.0, 3.0); assertEquals(i1, i2); i1 = new OHLC(2.2, 4.0, 1.0, 3.0); assertFalse(i1.equals(i2)); i2 = new OHLC(2.2, 4.0, 1.0, 3.0); assertEquals(i1, i2); i1 = new OHLC(2.2, 4.4, 1.0, 3.0); assertFalse(i1.equals(i2)); i2 = new OHLC(2.2, 4.4, 1.0, 3.0); assertEquals(i1, i2); i1 = new OHLC(2.2, 4.4, 1.1, 3.0); assertFalse(i1.equals(i2)); i2 = new OHLC(2.2, 4.4, 1.1, 3.0); assertEquals(i1, i2); i1 = new OHLC(2.2, 4.4, 1.1, 3.3); assertFalse(i1.equals(i2)); i2 = new OHLC(2.2, 4.4, 1.1, 3.3); assertEquals(i1, i2); } /** * This class is immutable. */ @Test public void testCloning() throws CloneNotSupportedException { OHLC i1 = new OHLC(2.0, 4.0, 1.0, 3.0); assertFalse(i1 instanceof Cloneable); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { OHLC i1 = new OHLC(2.0, 4.0, 1.0, 3.0); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(i1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); OHLC i2 = (OHLC) in.readObject(); in.close(); assertEquals(i1, i2); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashcode() { OHLC i1 = new OHLC(2.0, 4.0, 1.0, 3.0); OHLC i2 = new OHLC(2.0, 4.0, 1.0, 3.0); assertEquals(i1, i2); int h1 = i1.hashCode(); int h2 = i2.hashCode(); assertEquals(h1, h2); } }
4,121
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
OHLCSeriesCollectionTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/ohlc/OHLCSeriesCollectionTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------------ * OHLCSeriesCollectionTests.java * ------------------------------ * (C) Copyright 2006-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 04-Dec-2006 : Version 1 (DG); * 10-Jul-2008 : Updated testEquals() method (DG); * 26-Jun-2009 : Added tests for removeSeries() methods (DG); * */ package org.jfree.data.time.ohlc; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.DatasetChangeListener; import org.jfree.data.time.TimePeriodAnchor; import org.jfree.data.time.Year; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; /** * Tests for the {@link OHLCSeriesCollection} class. */ public class OHLCSeriesCollectionTest implements DatasetChangeListener { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { OHLCSeriesCollection c1 = new OHLCSeriesCollection(); OHLCSeriesCollection c2 = new OHLCSeriesCollection(); assertEquals(c1, c2); // add a series OHLCSeries s1 = new OHLCSeries("Series"); s1.add(new Year(2006), 1.0, 1.1, 1.2, 1.3); c1.addSeries(s1); assertFalse(c1.equals(c2)); OHLCSeries s2 = new OHLCSeries("Series"); s2.add(new Year(2006), 1.0, 1.1, 1.2, 1.3); c2.addSeries(s2); assertEquals(c1, c2); // add an empty series c1.addSeries(new OHLCSeries("Empty Series")); assertFalse(c1.equals(c2)); c2.addSeries(new OHLCSeries("Empty Series")); assertEquals(c1, c2); c1.setXPosition(TimePeriodAnchor.END); assertFalse(c1.equals(c2)); c2.setXPosition(TimePeriodAnchor.END); assertEquals(c1, c2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { OHLCSeriesCollection c1 = new OHLCSeriesCollection(); OHLCSeries s1 = new OHLCSeries("Series"); s1.add(new Year(2006), 1.0, 1.1, 1.2, 1.3); c1.addSeries(s1); OHLCSeriesCollection c2 = (OHLCSeriesCollection) c1.clone(); assertNotSame(c1, c2); assertSame(c1.getClass(), c2.getClass()); assertEquals(c1, c2); // check independence s1.setDescription("XYZ"); assertFalse(c1.equals(c2)); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { OHLCSeriesCollection c1 = new OHLCSeriesCollection(); OHLCSeries s1 = new OHLCSeries("Series"); s1.add(new Year(2006), 1.0, 1.1, 1.2, 1.3); c1.addSeries(s1); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(c1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); OHLCSeriesCollection c2 = (OHLCSeriesCollection) in.readObject(); in.close(); assertEquals(c1, c2); } /** * A test for bug report 1170825 (originally affected XYSeriesCollection, * this test is just copied over). */ @Test public void test1170825() { OHLCSeries s1 = new OHLCSeries("Series1"); OHLCSeriesCollection dataset = new OHLCSeriesCollection(); dataset.addSeries(s1); try { /* XYSeries s = */ dataset.getSeries(1); fail("Should have thrown on IllegalArgumentException on index out of bounds"); } catch (IllegalArgumentException e) { assertEquals("Series index out of bounds", e.getMessage()); } } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashcode() { OHLCSeriesCollection c1 = new OHLCSeriesCollection(); OHLCSeries s1 = new OHLCSeries("S"); s1.add(new Year(2009), 1.0, 4.0, 0.5, 2.0); c1.addSeries(s1); OHLCSeriesCollection c2 = new OHLCSeriesCollection(); OHLCSeries s2 = new OHLCSeries("S"); s2.add(new Year(2009), 1.0, 4.0, 0.5, 2.0); c2.addSeries(s2); assertEquals(c1, c2); int h1 = c1.hashCode(); int h2 = c2.hashCode(); assertEquals(h1, h2); } /** * Some checks for the {@link OHLCSeriesCollection#removeSeries(int)} * method. */ @Test public void testRemoveSeries_int() { OHLCSeriesCollection c1 = new OHLCSeriesCollection(); OHLCSeries s1 = new OHLCSeries("Series 1"); OHLCSeries s2 = new OHLCSeries("Series 2"); OHLCSeries s3 = new OHLCSeries("Series 3"); OHLCSeries s4 = new OHLCSeries("Series 4"); c1.addSeries(s1); c1.addSeries(s2); c1.addSeries(s3); c1.addSeries(s4); c1.removeSeries(2); assertEquals(c1.getSeries(2), s4); c1.removeSeries(0); assertEquals(c1.getSeries(0), s2); assertEquals(2, c1.getSeriesCount()); } /** * Some checks for the * {@link OHLCSeriesCollection#removeSeries(OHLCSeries)} method. */ @Test public void testRemoveSeries() { OHLCSeriesCollection c1 = new OHLCSeriesCollection(); OHLCSeries s1 = new OHLCSeries("Series 1"); OHLCSeries s2 = new OHLCSeries("Series 2"); OHLCSeries s3 = new OHLCSeries("Series 3"); OHLCSeries s4 = new OHLCSeries("Series 4"); c1.addSeries(s1); c1.addSeries(s2); c1.addSeries(s3); c1.addSeries(s4); c1.removeSeries(s3); assertEquals(c1.getSeries(2), s4); c1.removeSeries(s1); assertEquals(c1.getSeries(0), s2); assertEquals(2, c1.getSeriesCount()); } /** * A simple check for the removeAllSeries() method. */ @Test public void testRemoveAllSeries() { OHLCSeriesCollection c1 = new OHLCSeriesCollection(); c1.addChangeListener(this); // there should be no change event when clearing an empty series this.lastEvent = null; c1.removeAllSeries(); assertNull(this.lastEvent); OHLCSeries s1 = new OHLCSeries("Series 1"); OHLCSeries s2 = new OHLCSeries("Series 2"); c1.addSeries(s1); c1.addSeries(s2); c1.removeAllSeries(); assertEquals(0, c1.getSeriesCount()); assertNotNull(this.lastEvent); this.lastEvent = null; // clean up } /** The last received event. */ private DatasetChangeEvent lastEvent; /** * Receives dataset change events. * * @param event the event. */ @Override public void datasetChanged(DatasetChangeEvent event) { this.lastEvent = event; } }
8,742
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
OHLCItemTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/time/ohlc/OHLCItemTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------ * OHLCItemTests.java * ------------------ * (C) Copyright 2006-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 04-Dec-2006 : Version 1 (DG); * 23-May-2009 : Added testHashCode() (DG); * */ package org.jfree.data.time.ohlc; import org.jfree.data.time.Year; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; /** * Tests for the {@link OHLCItem} class. */ public class OHLCItemTest { private static final double EPSILON = 0.00000000001; /** * Some checks for the constructor. */ @Test public void testConstructor1() { OHLCItem item1 = new OHLCItem(new Year(2006), 2.0, 4.0, 1.0, 3.0); assertEquals(new Year(2006), item1.getPeriod()); assertEquals(2.0, item1.getOpenValue(), EPSILON); assertEquals(4.0, item1.getHighValue(), EPSILON); assertEquals(1.0, item1.getLowValue(), EPSILON); assertEquals(3.0, item1.getCloseValue(), EPSILON); } /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { OHLCItem item1 = new OHLCItem(new Year(2006), 2.0, 4.0, 1.0, 3.0); OHLCItem item2 = new OHLCItem(new Year(2006), 2.0, 4.0, 1.0, 3.0); assertEquals(item1, item2); assertEquals(item2, item1); // period item1 = new OHLCItem(new Year(2007), 2.0, 4.0, 1.0, 3.0); assertFalse(item1.equals(item2)); item2 = new OHLCItem(new Year(2007), 2.0, 4.0, 1.0, 3.0); assertEquals(item1, item2); // open item1 = new OHLCItem(new Year(2007), 2.2, 4.0, 1.0, 3.0); assertFalse(item1.equals(item2)); item2 = new OHLCItem(new Year(2007), 2.2, 4.0, 1.0, 3.0); assertEquals(item1, item2); // high item1 = new OHLCItem(new Year(2007), 2.2, 4.4, 1.0, 3.0); assertFalse(item1.equals(item2)); item2 = new OHLCItem(new Year(2007), 2.2, 4.4, 1.0, 3.0); assertEquals(item1, item2); // low item1 = new OHLCItem(new Year(2007), 2.2, 4.4, 1.1, 3.0); assertFalse(item1.equals(item2)); item2 = new OHLCItem(new Year(2007), 2.2, 4.4, 1.1, 3.0); assertEquals(item1, item2); // close item1 = new OHLCItem(new Year(2007), 2.2, 4.4, 1.1, 3.3); assertFalse(item1.equals(item2)); item2 = new OHLCItem(new Year(2007), 2.2, 4.4, 1.1, 3.3); assertEquals(item1, item2); } /** * Some checks for the clone() method. */ @Test public void testCloning() throws CloneNotSupportedException { OHLCItem item1 = new OHLCItem(new Year(2006), 2.0, 4.0, 1.0, 3.0); OHLCItem item2 = (OHLCItem) item1.clone(); assertNotSame(item1, item2); assertSame(item1.getClass(), item2.getClass()); assertEquals(item1, item2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { OHLCItem item1 = new OHLCItem(new Year(2006), 2.0, 4.0, 1.0, 3.0); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(item1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); OHLCItem item2 = (OHLCItem) in.readObject(); in.close(); assertEquals(item1, item2); } /** * Two objects that are equal are required to return the same hashCode. */ @Test public void testHashcode() { OHLCItem i1 = new OHLCItem(new Year(2009), 2.0, 4.0, 1.0, 3.0); OHLCItem i2 = new OHLCItem(new Year(2009), 2.0, 4.0, 1.0, 3.0); assertEquals(i1, i2); int h1 = i1.hashCode(); int h2 = i2.hashCode(); assertEquals(h1, h2); } }
5,681
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
package-info.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/statistics/package-info.java
/** * Tests for the classes in the <code>org.jfree.data.statistics</code> package. */ package org.jfree.data.statistics;
123
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
SimpleHistogramBinTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/statistics/SimpleHistogramBinTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------------- * SimpleHistogramBinTests.java * ---------------------------- * (C) Copyright 2005-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 10-Jan-2005 : Version 1 (DG); * */ package org.jfree.data.statistics; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for the {@link SimpleHistogramBin} class. */ public class SimpleHistogramBinTest { /** * Some checks for the accepts() method. */ @Test public void testAccepts() { SimpleHistogramBin bin1 = new SimpleHistogramBin(1.0, 2.0); assertFalse(bin1.accepts(0.0)); assertTrue(bin1.accepts(1.0)); assertTrue(bin1.accepts(1.5)); assertTrue(bin1.accepts(2.0)); assertFalse(bin1.accepts(2.1)); assertFalse(bin1.accepts(Double.NaN)); SimpleHistogramBin bin2 = new SimpleHistogramBin(1.0, 2.0, false, false); assertFalse(bin2.accepts(0.0)); assertFalse(bin2.accepts(1.0)); assertTrue(bin2.accepts(1.5)); assertFalse(bin2.accepts(2.0)); assertFalse(bin2.accepts(2.1)); assertFalse(bin2.accepts(Double.NaN)); } /** * Some checks for the overlapsWith() method. */ @Test public void testOverlapsWidth() { SimpleHistogramBin b1 = new SimpleHistogramBin(1.0, 2.0); SimpleHistogramBin b2 = new SimpleHistogramBin(2.0, 3.0); SimpleHistogramBin b3 = new SimpleHistogramBin(3.0, 4.0); SimpleHistogramBin b4 = new SimpleHistogramBin(0.0, 5.0); SimpleHistogramBin b5 = new SimpleHistogramBin(2.0, 3.0, false, true); SimpleHistogramBin b6 = new SimpleHistogramBin(2.0, 3.0, true, false); assertTrue(b1.overlapsWith(b2)); assertTrue(b2.overlapsWith(b1)); assertFalse(b1.overlapsWith(b3)); assertFalse(b3.overlapsWith(b1)); assertTrue(b1.overlapsWith(b4)); assertTrue(b4.overlapsWith(b1)); assertFalse(b1.overlapsWith(b5)); assertFalse(b5.overlapsWith(b1)); assertTrue(b1.overlapsWith(b6)); assertTrue(b6.overlapsWith(b1)); } /** * Ensure that the equals() method can distinguish all fields. */ @Test public void testEquals() { SimpleHistogramBin b1 = new SimpleHistogramBin(1.0, 2.0); SimpleHistogramBin b2 = new SimpleHistogramBin(1.0, 2.0); assertEquals(b1, b2); assertEquals(b2, b1); b1 = new SimpleHistogramBin(1.1, 2.0, true, true); assertFalse(b1.equals(b2)); b2 = new SimpleHistogramBin(1.1, 2.0, true, true); assertEquals(b1, b2); b1 = new SimpleHistogramBin(1.1, 2.2, true, true); assertFalse(b1.equals(b2)); b2 = new SimpleHistogramBin(1.1, 2.2, true, true); assertEquals(b1, b2); b1 = new SimpleHistogramBin(1.1, 2.2, false, true); assertFalse(b1.equals(b2)); b2 = new SimpleHistogramBin(1.1, 2.2, false, true); assertEquals(b1, b2); b1 = new SimpleHistogramBin(1.1, 2.2, false, false); assertFalse(b1.equals(b2)); b2 = new SimpleHistogramBin(1.1, 2.2, false, false); assertEquals(b1, b2); b1.setItemCount(99); assertFalse(b1.equals(b2)); b2.setItemCount(99); assertEquals(b1, b2); } /** * Some checks for the clone() method. */ @Test public void testCloning() throws CloneNotSupportedException { SimpleHistogramBin b1 = new SimpleHistogramBin(1.1, 2.2, false, true); b1.setItemCount(99); SimpleHistogramBin b2 = (SimpleHistogramBin) b1.clone(); assertNotSame(b1, b2); assertSame(b1.getClass(), b2.getClass()); assertEquals(b1, b2); // check that clone is independent of the original b2.setItemCount(111); assertFalse(b1.equals(b2)); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { SimpleHistogramBin b1 = new SimpleHistogramBin(1.0, 2.0, false, true); b1.setItemCount(123); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(b1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); SimpleHistogramBin b2 = (SimpleHistogramBin) in.readObject(); in.close(); assertEquals(b1, b2); } }
6,374
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultBoxAndWhiskerCategoryDatasetTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/statistics/DefaultBoxAndWhiskerCategoryDatasetTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------------------------------- * DefaultBoxAndWhiskerCategoryDatasetTests.java * --------------------------------------------- * (C) Copyright 2004-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 01-Mar-2004 : Version 1 (DG); * 17-Apr-2007 : Added a test for bug 1701822 (DG); * 28-Sep-2007 : Enhanced testClone() (DG); * 02-Oct-2007 : Added new tests (DG); * 03-Oct-2007 : Added getTestRangeBounds() and testRemove() (DG); * */ package org.jfree.data.statistics; import org.jfree.data.Range; import org.jfree.data.UnknownKeyException; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.ArrayList; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** * Tests for the {@link DefaultBoxAndWhiskerCategoryDataset} class. */ public class DefaultBoxAndWhiskerCategoryDatasetTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { DefaultBoxAndWhiskerCategoryDataset d1 = new DefaultBoxAndWhiskerCategoryDataset(); d1.add(new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList()), "ROW1", "COLUMN1"); DefaultBoxAndWhiskerCategoryDataset d2 = new DefaultBoxAndWhiskerCategoryDataset(); d2.add(new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList()), "ROW1", "COLUMN1"); assertEquals(d1, d2); assertEquals(d2, d1); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { DefaultBoxAndWhiskerCategoryDataset d1 = new DefaultBoxAndWhiskerCategoryDataset(); d1.add(new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList()), "ROW1", "COLUMN1"); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); DefaultBoxAndWhiskerCategoryDataset d2 = (DefaultBoxAndWhiskerCategoryDataset) in.readObject(); in.close(); assertEquals(d1, d2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { DefaultBoxAndWhiskerCategoryDataset d1 = new DefaultBoxAndWhiskerCategoryDataset(); d1.add(new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList()), "ROW1", "COLUMN1"); DefaultBoxAndWhiskerCategoryDataset d2 = (DefaultBoxAndWhiskerCategoryDataset) d1.clone(); assertNotSame(d1, d2); assertSame(d1.getClass(), d2.getClass()); assertEquals(d1, d2); // test independence d1.add(new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList()), "ROW2", "COLUMN1"); assertFalse(d1.equals(d2)); } /** * A simple test for bug report 1701822. */ @Test public void test1701822() { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); dataset.add(new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, null, 8.0, new ArrayList()), "ROW1", "COLUMN1"); dataset.add(new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, null, new ArrayList()), "ROW1", "COLUMN2"); } private static final double EPSILON = 0.0000000001; /** * Some checks for the add() method. */ @Test public void testAdd() { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); BoxAndWhiskerItem item1 = new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList()); dataset.add(item1, "R1", "C1"); assertEquals(2.0, dataset.getValue("R1", "C1").doubleValue(), EPSILON); assertEquals(1.0, dataset.getMeanValue("R1", "C1").doubleValue(), EPSILON); assertEquals(2.0, dataset.getMedianValue("R1", "C1").doubleValue(), EPSILON); assertEquals(3.0, dataset.getQ1Value("R1", "C1").doubleValue(), EPSILON); assertEquals(4.0, dataset.getQ3Value("R1", "C1").doubleValue(), EPSILON); assertEquals(5.0, dataset.getMinRegularValue("R1", "C1").doubleValue(), EPSILON); assertEquals(6.0, dataset.getMaxRegularValue("R1", "C1").doubleValue(), EPSILON); assertEquals(7.0, dataset.getMinOutlier("R1", "C1").doubleValue(), EPSILON); assertEquals(8.0, dataset.getMaxOutlier("R1", "C1").doubleValue(), EPSILON); assertEquals(new Range(7.0, 8.0), dataset.getRangeBounds(false)); } /** * Some checks for the add() method. */ @Test public void testAddUpdatesCachedRange() { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); BoxAndWhiskerItem item1 = new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList()); dataset.add(item1, "R1", "C1"); // now overwrite this item with another BoxAndWhiskerItem item2 = new BoxAndWhiskerItem(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, new ArrayList()); dataset.add(item2, "R1", "C1"); assertEquals(2.5, dataset.getValue("R1", "C1").doubleValue(), EPSILON); assertEquals(1.5, dataset.getMeanValue("R1", "C1").doubleValue(), EPSILON); assertEquals(2.5, dataset.getMedianValue("R1", "C1").doubleValue(), EPSILON); assertEquals(3.5, dataset.getQ1Value("R1", "C1").doubleValue(), EPSILON); assertEquals(4.5, dataset.getQ3Value("R1", "C1").doubleValue(), EPSILON); assertEquals(5.5, dataset.getMinRegularValue("R1", "C1").doubleValue(), EPSILON); assertEquals(6.5, dataset.getMaxRegularValue("R1", "C1").doubleValue(), EPSILON); assertEquals(7.5, dataset.getMinOutlier("R1", "C1").doubleValue(), EPSILON); assertEquals(8.5, dataset.getMaxOutlier("R1", "C1").doubleValue(), EPSILON); assertEquals(new Range(7.5, 8.5), dataset.getRangeBounds(false)); } /** * Some basic checks for the constructor. */ @Test public void testConstructor() { DefaultBoxAndWhiskerCategoryDataset dataset = new DefaultBoxAndWhiskerCategoryDataset(); assertEquals(0, dataset.getColumnCount()); assertEquals(0, dataset.getRowCount()); assertTrue(Double.isNaN(dataset.getRangeLowerBound(false))); assertTrue(Double.isNaN(dataset.getRangeUpperBound(false))); } /** * Some checks for the getRangeBounds() method. */ @Test public void testGetRangeBounds() { DefaultBoxAndWhiskerCategoryDataset d1 = new DefaultBoxAndWhiskerCategoryDataset(); d1.add(new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList()), "R1", "C1"); assertEquals(new Range(7.0, 8.0), d1.getRangeBounds(false)); assertEquals(new Range(7.0, 8.0), d1.getRangeBounds(true)); d1.add(new BoxAndWhiskerItem(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, new ArrayList()), "R1", "C1"); assertEquals(new Range(7.5, 8.5), d1.getRangeBounds(false)); assertEquals(new Range(7.5, 8.5), d1.getRangeBounds(true)); d1.add(new BoxAndWhiskerItem(2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, new ArrayList()), "R2", "C1"); assertEquals(new Range(7.5, 9.5), d1.getRangeBounds(false)); assertEquals(new Range(7.5, 9.5), d1.getRangeBounds(true)); // this replaces the entry with the current minimum value, but the new // minimum value is now in a different item d1.add(new BoxAndWhiskerItem(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 8.6, 9.6, new ArrayList()), "R1", "C1"); assertEquals(new Range(8.5, 9.6), d1.getRangeBounds(false)); assertEquals(new Range(8.5, 9.6), d1.getRangeBounds(true)); } /** * Some checks for the remove method. */ @Test public void testRemove() { DefaultBoxAndWhiskerCategoryDataset data = new DefaultBoxAndWhiskerCategoryDataset(); try { data.remove("R1", "R2"); fail("UnknownKeyException should have been thrown on negative key"); } catch (UnknownKeyException e) { assertEquals("Row key (R1) not recognised.", e.getMessage()); } data.add(new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList()), "R1", "C1"); assertEquals(new Range(7.0, 8.0), data.getRangeBounds(false)); assertEquals(new Range(7.0, 8.0), data.getRangeBounds(true)); data.add(new BoxAndWhiskerItem(2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, new ArrayList()), "R2", "C1"); assertEquals(new Range(7.0, 9.5), data.getRangeBounds(false)); assertEquals(new Range(7.0, 9.5), data.getRangeBounds(true)); data.remove("R1", "C1"); assertEquals(new Range(8.5, 9.5), data.getRangeBounds(false)); assertEquals(new Range(8.5, 9.5), data.getRangeBounds(true)); } }
11,743
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultStatisticalCategoryDatasetTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/statistics/DefaultStatisticalCategoryDatasetTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------------------------- * DefaultStatisticalCategoryDatasetTests.java * ------------------------------------------- * (C) Copyright 2005-2011, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 05-Feb-2005 : Version 1 (DG); * 03-Aug-2006 : Added testGetRangeBounds() method (DG); * 28-Sep-2007 : Enhanced testCloning() method (DG); * 02-Oct-2007 : Added new bounds tests (DG); * 03-Oct-2007 : Added testRemove() method (DG); * */ package org.jfree.data.statistics; import org.jfree.data.Range; import org.jfree.data.UnknownKeyException; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; /** * Tests for the {@link DefaultStatisticalCategoryDataset} class. */ public class DefaultStatisticalCategoryDatasetTest { /** * Some checks for the getRangeBounds() method. */ @Test public void testGetRangeBounds() { DefaultStatisticalCategoryDataset d = new DefaultStatisticalCategoryDataset(); // an empty dataset should return null for bounds assertNull(d.getRangeBounds(true)); // try a dataset with a single value d.add(4.5, 1.0, "R1", "C1"); assertEquals(new Range(4.5, 4.5), d.getRangeBounds(false)); assertEquals(new Range(3.5, 5.5), d.getRangeBounds(true)); // try a dataset with two values d.add(0.5, 2.0, "R1", "C2"); assertEquals(new Range(0.5, 4.5), d.getRangeBounds(false)); assertEquals(new Range(-1.5, 5.5), d.getRangeBounds(true)); // try a Double.NaN d.add(Double.NaN, 0.0, "R1", "C3"); assertEquals(new Range(0.5, 4.5), d.getRangeBounds(false)); assertEquals(new Range(-1.5, 5.5), d.getRangeBounds(true)); // try a Double.NEGATIVE_INFINITY d.add(Double.NEGATIVE_INFINITY, 0.0, "R1", "C3"); assertEquals(new Range(Double.NEGATIVE_INFINITY, 4.5), d.getRangeBounds(false)); assertEquals(new Range(Double.NEGATIVE_INFINITY, 5.5), d.getRangeBounds(true)); // try a Double.POSITIVE_INFINITY d.add(Double.POSITIVE_INFINITY, 0.0, "R1", "C3"); assertEquals(new Range(0.5, Double.POSITIVE_INFINITY), d.getRangeBounds(false)); assertEquals(new Range(-1.5, Double.POSITIVE_INFINITY), d.getRangeBounds(true)); } /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { DefaultStatisticalCategoryDataset d1 = new DefaultStatisticalCategoryDataset(); DefaultStatisticalCategoryDataset d2 = new DefaultStatisticalCategoryDataset(); assertEquals(d1, d2); assertEquals(d2, d1); } /** * Some checks for cloning. */ @Test public void testCloning() throws CloneNotSupportedException { DefaultStatisticalCategoryDataset d1 = new DefaultStatisticalCategoryDataset(); d1.add(1.1, 2.2, "R1", "C1"); d1.add(3.3, 4.4, "R1", "C2"); d1.add(null, 5.5, "R1", "C3"); d1.add(6.6, null, "R2", "C3"); DefaultStatisticalCategoryDataset d2 = (DefaultStatisticalCategoryDataset) d1.clone(); assertNotSame(d1, d2); assertSame(d1.getClass(), d2.getClass()); assertEquals(d1, d2); // check independence d1.add(1.1, 2.2, "R3", "C1"); assertFalse(d1.equals(d2)); } /** * Check serialization of a default instance. */ @Test public void testSerialization1() throws IOException, ClassNotFoundException { DefaultStatisticalCategoryDataset d1 = new DefaultStatisticalCategoryDataset(); d1.add(1.1, 2.2, "R1", "C1"); d1.add(3.3, 4.4, "R1", "C2"); d1.add(null, 5.5, "R1", "C3"); d1.add(6.6, null, "R2", "C3"); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); DefaultStatisticalCategoryDataset d2 = (DefaultStatisticalCategoryDataset) in.readObject(); in.close(); assertEquals(d1, d2); } /** * Check serialization of a more complex instance. */ @Test public void testSerialization2() throws IOException, ClassNotFoundException { DefaultStatisticalCategoryDataset d1 = new DefaultStatisticalCategoryDataset(); d1.add(1.2, 3.4, "Row 1", "Column 1"); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); DefaultStatisticalCategoryDataset d2 = (DefaultStatisticalCategoryDataset) in.readObject(); in.close(); assertEquals(d1, d2); } private static final double EPSILON = 0.0000000001; /** * Some checks for the add() method. */ @Test public void testAdd() { DefaultStatisticalCategoryDataset d1 = new DefaultStatisticalCategoryDataset(); d1.add(1.0, 2.0, "R1", "C1"); assertEquals(1.0, d1.getValue("R1", "C1").doubleValue(), EPSILON); assertEquals(2.0, d1.getStdDevValue("R1", "C1").doubleValue(), EPSILON); // overwrite the value d1.add(10.0, 20.0, "R1", "C1"); assertEquals(10.0, d1.getValue("R1", "C1").doubleValue(), EPSILON); assertEquals(20.0, d1.getStdDevValue("R1", "C1").doubleValue(), EPSILON); } /** * Some checks for the getRangeLowerBound() method. */ @Test public void testGetRangeLowerBound() { DefaultStatisticalCategoryDataset d1 = new DefaultStatisticalCategoryDataset(); d1.add(1.0, 2.0, "R1", "C1"); assertEquals(1.0, d1.getRangeLowerBound(false), EPSILON); assertEquals(-1.0, d1.getRangeLowerBound(true), EPSILON); } /** * Some checks for the getRangeUpperBound() method. */ @Test public void testGetRangeUpperBound() { DefaultStatisticalCategoryDataset d1 = new DefaultStatisticalCategoryDataset(); d1.add(1.0, 2.0, "R1", "C1"); assertEquals(1.0, d1.getRangeUpperBound(false), EPSILON); assertEquals(3.0, d1.getRangeUpperBound(true), EPSILON); } /** * Some checks for the getRangeBounds() method. */ @Test public void testGetRangeBounds2() { DefaultStatisticalCategoryDataset d1 = new DefaultStatisticalCategoryDataset(); d1.add(1.0, 2.0, "R1", "C1"); assertEquals(new Range(1.0, 1.0), d1.getRangeBounds(false)); assertEquals(new Range(-1.0, 3.0), d1.getRangeBounds(true)); d1.add(10.0, 20.0, "R1", "C1"); assertEquals(new Range(10.0, 10.0), d1.getRangeBounds(false)); assertEquals(new Range(-10.0, 30.0), d1.getRangeBounds(true)); } /** * Some checks for the remove method. */ @Test public void testRemove() { DefaultStatisticalCategoryDataset data = new DefaultStatisticalCategoryDataset(); try { data.remove("R1", "R2"); fail("UnknownKeyException should have been thrown on the unknown key"); } catch (UnknownKeyException e) { assertEquals("Row key (R1) not recognised.", e.getMessage()); } data.add(1.0, 0.5, "R1", "C1"); assertEquals(new Range(1.0, 1.0), data.getRangeBounds(false)); assertEquals(new Range(0.5, 1.5), data.getRangeBounds(true)); data.add(1.4, 0.2, "R2", "C1"); assertEquals(1.0, data.getRangeLowerBound(false), EPSILON); assertEquals(1.4, data.getRangeUpperBound(false), EPSILON); assertEquals(0.5, data.getRangeLowerBound(true), EPSILON); assertEquals(1.6, data.getRangeUpperBound(true), EPSILON); data.remove("R1", "C1"); assertEquals(1.4, data.getRangeLowerBound(false), EPSILON); assertEquals(1.4, data.getRangeUpperBound(false), EPSILON); assertEquals(1.2, data.getRangeLowerBound(true), EPSILON); assertEquals(1.6, data.getRangeUpperBound(true), EPSILON); } /** * A test for bug 3072674. */ @Test public void test3072674() { DefaultStatisticalCategoryDataset dataset = new DefaultStatisticalCategoryDataset(); dataset.add(1.0, Double.NaN, "R1", "C1"); assertEquals(1.0, dataset.getRangeLowerBound(true), EPSILON); assertEquals(1.0, dataset.getRangeUpperBound(true), EPSILON); Range r = dataset.getRangeBounds(true); assertEquals(1.0, r.getLowerBound(), EPSILON); assertEquals(1.0, r.getUpperBound(), EPSILON); } }
10,872
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
StatisticsTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/statistics/StatisticsTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * StatisticsTests.java * -------------------- * (C) Copyright 2004-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 25-Mar-2004 : Version 1 (DG); * 04-Oct-2004 : Eliminated NumberUtils usage (DG); * */ package org.jfree.data.statistics; import org.junit.Test; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** * Tests for the {@link Statistics} class. */ public class StatisticsTest { /** * Some checks for the calculateMean(Number[]) and * calculateMean(Number[], boolean) methods. */ @Test public void testCalculateMean_Array() { // try null array try { Statistics.calculateMean((Number[]) null); fail("IllegalArgumentException should have been thrown on null key"); } catch (IllegalArgumentException e) { assertEquals("Null 'values' argument.", e.getMessage()); } try { Statistics.calculateMean((Number[]) null, false); fail("IllegalArgumentException should have been thrown on negative key"); } catch (IllegalArgumentException e) { assertEquals("Null 'values' argument.", e.getMessage()); } // try an array containing no items assertTrue(Double.isNaN(Statistics.calculateMean(new Number[0]))); assertTrue(Double.isNaN(Statistics.calculateMean(new Number[0], false))); // try an array containing a single Number Number[] values = new Number[] {1.0}; assertEquals(1.0, Statistics.calculateMean(values), EPSILON); assertEquals(1.0, Statistics.calculateMean(values, true), EPSILON); assertEquals(1.0, Statistics.calculateMean(values, false), EPSILON); // try an array containing a single Number and a null values = new Number[] {1.0, null}; assertTrue(Double.isNaN(Statistics.calculateMean(values))); assertTrue(Double.isNaN(Statistics.calculateMean(values, true))); assertEquals(1.0, Statistics.calculateMean(values, false), EPSILON); // try an array containing a single Number and a NaN values = new Number[] {1.0, Double.NaN}; assertTrue(Double.isNaN(Statistics.calculateMean(values))); assertTrue(Double.isNaN(Statistics.calculateMean(values, true))); assertEquals(1.0, Statistics.calculateMean(values, false), EPSILON); } /** * Some checks for the calculateMean(Collection) and * calculateMean(Collection, boolean) methods. */ @Test public void testCalculateMean_Collection() { // try a null collection try { Statistics.calculateMean((Collection<Number>) null); fail("IllegalArgumentException should have been thrown on null key"); } catch (IllegalArgumentException e) { assertEquals("Null 'values' argument.", e.getMessage()); } try { Statistics.calculateMean((Collection<Number>) null, false); fail("IllegalArgumentException should have been thrown on null key"); } catch (IllegalArgumentException e) { assertEquals("Null 'values' argument.", e.getMessage()); } // try an empty collection List<Number> values = new ArrayList<Number>(); assertTrue(Double.isNaN(Statistics.calculateMean(values))); assertTrue(Double.isNaN(Statistics.calculateMean(values, true))); assertTrue(Double.isNaN(Statistics.calculateMean(values, false))); // try a collection with a single number values.add(9.0); assertEquals(9.0, Statistics.calculateMean(values), EPSILON); assertEquals(9.0, Statistics.calculateMean(values, true), EPSILON); assertEquals(9.0, Statistics.calculateMean(values, false), EPSILON); // try a collection with a single number plus a null values.add(null); assertTrue(Double.isNaN(Statistics.calculateMean(values))); assertTrue(Double.isNaN(Statistics.calculateMean(values, true))); assertEquals(9.0, Statistics.calculateMean(values, false), EPSILON); // try a collection with a single number plus a NaN values.clear(); values.add(9.0); values.add(Double.NaN); assertTrue(Double.isNaN(Statistics.calculateMean(values))); assertTrue(Double.isNaN(Statistics.calculateMean(values, true))); assertEquals(9.0, Statistics.calculateMean(values, false), EPSILON); // try a collection with several numbers values = new ArrayList<Number>(); values.add(9.0); values.add(3.0); values.add(2.0); values.add(2.0); double mean = Statistics.calculateMean(values); assertEquals(4.0, mean, EPSILON); // a Collection containing a NaN will return Double.NaN for the result values.add(Double.NaN); assertTrue(Double.isNaN(Statistics.calculateMean(values))); } static final double EPSILON = 0.0000000001; /** * Some checks for the calculateMedian(List, boolean) method. */ @Test public void testCalculateMedian() { // check null list assertTrue(Double.isNaN(Statistics.calculateMedian(null, false))); assertTrue(Double.isNaN(Statistics.calculateMedian(null, true))); // check empty list List <Number>list = new ArrayList<Number>(); assertTrue(Double.isNaN(Statistics.calculateMedian(list, false))); assertTrue(Double.isNaN(Statistics.calculateMedian(list, true))); // check list containing null list.add(null); try { Statistics.calculateMedian(list, false); fail("Should have thrown a NullPointerException"); } catch (NullPointerException e) { //we expect ot go in here } try { Statistics.calculateMedian(list, true); fail("Should have thrown a NullPointerException"); } catch (NullPointerException e) { //we expect to go in here } } /** * A test for the calculateMedian() method. */ @Test public void testCalculateMedian1() { List<Number> values = new ArrayList<Number>(); values.add(1.0); double median = Statistics.calculateMedian(values); assertEquals(1.0, median, 0.0000001); } /** * A test for the calculateMedian() method. */ @Test public void testCalculateMedian2() { List<Number> values = new ArrayList<Number>(); values.add(2.0); values.add(1.0); double median = Statistics.calculateMedian(values); assertEquals(1.5, median, 0.0000001); } /** * A test for the calculateMedian() method. */ @Test public void testCalculateMedian3() { List<Number> values = new ArrayList<Number>(); values.add(1.0); values.add(2.0); values.add(3.0); values.add(6.0); values.add(5.0); values.add(4.0); double median = Statistics.calculateMedian(values); assertEquals(3.5, median, 0.0000001); } /** * A test for the calculateMedian() method. */ @Test public void testCalculateMedian4() { List<Number> values = new ArrayList<Number>(); values.add(7.0); values.add(2.0); values.add(3.0); values.add(5.0); values.add(4.0); values.add(6.0); values.add(1.0); double median = Statistics.calculateMedian(values); assertEquals(4.0, median, 0.0000001); } /** * A test using some real data that caused a problem at one point. */ @Test public void testCalculateMedian5() { List<Number> values = new ArrayList<Number>(); values.add(11.228692993861783); values.add(11.30823353859889); values.add(11.75312904769314); values.add(11.825102897465314); values.add(10.184252778401783); values.add(12.207951828057766); values.add(10.68841994040566); values.add(12.099522004479438); values.add(11.508874945056881); values.add(12.052517729558513); values.add(12.401481645578734); values.add(12.185377793028543); values.add(10.666372951930315); values.add(11.680978041499548); values.add(11.06528277406718); values.add(11.36876492904596); values.add(11.927565516175939); values.add(11.39307785978655); values.add(11.989603679523857); values.add(12.009834360354864); values.add(10.653351822461559); values.add(11.851776254376754); values.add(11.045441544755946); values.add(11.993674040560624); values.add(12.898219965238944); values.add(11.97095782819647); values.add(11.73234406745488); values.add(11.649006017243991); values.add(12.20549704915365); values.add(11.799723639384919); values.add(11.896208658005628); values.add(12.164149111823424); values.add(12.042795103513766); values.add(12.114839532596426); values.add(12.166609097075824); values.add(12.183017546225935); values.add(11.622009125845342); values.add(11.289365786738633); values.add(12.462984323671568); values.add(11.573494921030598); values.add(10.862867940485804); values.add(12.018186939664872); values.add(10.418046849313018); values.add(11.326344465881341); double median = Statistics.calculateMedian(values, true); assertEquals(11.812413268425116, median, 0.000001); Collections.sort((List) values); double median2 = Statistics.calculateMedian(values, false); assertEquals(11.812413268425116, median2, 0.000001); } /** * A test for the calculateMedian() method. */ @Test public void testCalculateMedian6() { List<Number> values = new ArrayList<Number>(); values.add(7.0); values.add(2.0); values.add(3.0); values.add(5.0); values.add(4.0); values.add(6.0); values.add(1.0); double median = Statistics.calculateMedian(values, 0, 2); assertEquals(3.0, median, 0.0000001); } /** * A simple test for the correlation calculation. */ @Test public void testCorrelation1() { Number[] data1 = new Number[3]; data1[0] = (double) 1; data1[1] = (double) 2; data1[2] = (double) 3; Number[] data2 = new Number[3]; data2[0] = (double) 1; data2[1] = (double) 2; data2[2] = (double) 3; double r = Statistics.getCorrelation(data1, data2); assertEquals(1.0, r, 0.00000001); } /** * A simple test for the correlation calculation. * * http://trochim.human.cornell.edu/kb/statcorr.htm */ @Test public void testCorrelation2() { Number[] data1 = new Number[20]; data1[0] = (double) 68; data1[1] = (double) 71; data1[2] = (double) 62; data1[3] = (double) 75; data1[4] = (double) 58; data1[5] = (double) 60; data1[6] = (double) 67; data1[7] = (double) 68; data1[8] = (double) 71; data1[9] = (double) 69; data1[10] = (double) 68; data1[11] = (double) 67; data1[12] = (double) 63; data1[13] = (double) 62; data1[14] = (double) 60; data1[15] = (double) 63; data1[16] = (double) 65; data1[17] = (double) 67; data1[18] = (double) 63; data1[19] = (double) 61; Number[] data2 = new Number[20]; data2[0] = 4.1; data2[1] = 4.6; data2[2] = 3.8; data2[3] = 4.4; data2[4] = 3.2; data2[5] = 3.1; data2[6] = 3.8; data2[7] = 4.1; data2[8] = 4.3; data2[9] = 3.7; data2[10] = 3.5; data2[11] = 3.2; data2[12] = 3.7; data2[13] = 3.3; data2[14] = 3.4; data2[15] = 4.0; data2[16] = 4.1; data2[17] = 3.8; data2[18] = 3.4; data2[19] = 3.6; double r = Statistics.getCorrelation(data1, data2); assertEquals(0.7306356862792885, r, 0.000000000001); } /** * Some checks for the getStdDev() method. */ @Test public void testGetStdDev() { // try null argument try { Statistics.getStdDev(null); fail("IllegalArgumentException should have been thrown on null key"); } catch (IllegalArgumentException e) { assertEquals("Null 'data' array.", e.getMessage()); } // try zero length array try { Statistics.getStdDev(new Double[0]); fail("IllegalArgumentException should have been thrown on empty key"); } catch (IllegalArgumentException e) { assertEquals("Zero length 'data' array.", e.getMessage()); } // try single value assertTrue(Double.isNaN(Statistics.getStdDev(new Double[] {1.0}))); } }
14,747
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultMultiValueCategoryDatasetTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/statistics/DefaultMultiValueCategoryDatasetTest.java
/* =========================================================== /* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------------------------ * DefaultMultiValueCategoryDatasetTests.java * ------------------------------------------ * (C) Copyright 2007, 2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 28-Sep-2007 : Version 1 (DG); * */ package org.jfree.data.statistics; import org.jfree.data.UnknownKeyException; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.List; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; /** * Tests for the {@link DefaultMultiValueCategoryDataset} class. */ public class DefaultMultiValueCategoryDatasetTest { /** * Some checks for the getValue() method. */ @Test public void testGetValue() { DefaultMultiValueCategoryDataset d = new DefaultMultiValueCategoryDataset(); List<Number> values = new ArrayList<Number>(); values.add(1); values.add(2); d.add(values, "R1", "C1"); assertEquals(1.5, d.getValue("R1", "C1")); try { d.getValue("XX", "C1"); fail("UnknownKeyException should have been thrown on an unknown key"); } catch (UnknownKeyException e) { assertEquals("Row key (XX) not recognised.", e.getMessage()); } try { d.getValue("R1", "XX"); fail("UnknownKeyException should have been thrown on an unknown key"); } catch (UnknownKeyException e) { assertEquals("Column key (XX) not recognised.", e.getMessage()); } } /** * A simple check for the getValue(int, int) method. */ @Test public void testGetValue2() { DefaultMultiValueCategoryDataset d = new DefaultMultiValueCategoryDataset(); try { /* Number n =*/ d.getValue(0, 0); fail("IndexOutOfBoundsException should have been thrown on key out of range"); } catch (IndexOutOfBoundsException e) { assertEquals("Index: 0, Size: 0", e.getMessage()); } } /** * Some tests for the getRowCount() method. */ @Test public void testGetRowCount() { DefaultMultiValueCategoryDataset d = new DefaultMultiValueCategoryDataset(); assertSame(d.getRowCount(), 0); List values = new ArrayList(); d.add(values, "R1", "C1"); assertSame(d.getRowCount(), 1); d.add(values, "R2", "C1"); assertSame(d.getRowCount(), 2); d.add(values, "R2", "C1"); assertSame(d.getRowCount(), 2); } /** * Some tests for the getColumnCount() method. */ @Test public void testGetColumnCount() { DefaultMultiValueCategoryDataset d = new DefaultMultiValueCategoryDataset(); assertSame(d.getColumnCount(), 0); List values = new ArrayList(); d.add(values, "R1", "C1"); assertSame(d.getColumnCount(), 1); d.add(values, "R1", "C2"); assertSame(d.getColumnCount(), 2); d.add(values, "R1", "C2"); assertSame(d.getColumnCount(), 2); } /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { DefaultMultiValueCategoryDataset d1 = new DefaultMultiValueCategoryDataset(); DefaultMultiValueCategoryDataset d2 = new DefaultMultiValueCategoryDataset(); assertEquals(d1, d2); assertEquals(d2, d1); List<Number> values = new ArrayList<Number>(); d1.add(values, "R1", "C1"); assertFalse(d1.equals(d2)); d2.add(values, "R1", "C1"); assertEquals(d1, d2); values.add(99); d1.add(values, "R1", "C1"); assertFalse(d1.equals(d2)); d2.add(values, "R1", "C1"); assertEquals(d1, d2); values.add(99); d1.add(values, "R1", "C2"); assertFalse(d1.equals(d2)); d2.add(values, "R1", "C2"); assertEquals(d1, d2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { DefaultMultiValueCategoryDataset d1 = new DefaultMultiValueCategoryDataset(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); DefaultMultiValueCategoryDataset d2 = (DefaultMultiValueCategoryDataset) in.readObject(); in.close(); assertEquals(d1, d2); } /** * Some checks for the add() method. */ @Test public void testAddValue() { DefaultMultiValueCategoryDataset d1 = new DefaultMultiValueCategoryDataset(); try { d1.add(null, "R1", "C1"); fail("IllegalArgumentException should have been thrown on a null key"); } catch (IllegalArgumentException e) { assertEquals("Null 'values' argument.", e.getMessage()); } List values = new ArrayList(); d1.add(values, "R2", "C1"); assertEquals(values, d1.getValues("R2", "C1")); try { d1.add(values, null, "C2"); fail("IllegalArgumentException should have been thrown on a null key"); } catch (IllegalArgumentException e) { assertEquals("Null 'rowKey' argument.", e.getMessage()); } } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { DefaultMultiValueCategoryDataset d1 = new DefaultMultiValueCategoryDataset(); DefaultMultiValueCategoryDataset d2 = (DefaultMultiValueCategoryDataset) d1.clone(); assertNotSame(d1, d2); assertSame(d1.getClass(), d2.getClass()); assertEquals(d1, d2); // try a dataset with some content... List<Number> values = new ArrayList<Number>(); values.add(99); d1.add(values, "R1", "C1"); d2 = (DefaultMultiValueCategoryDataset) d1.clone(); assertNotSame(d1, d2); assertSame(d1.getClass(), d2.getClass()); assertEquals(d1, d2); // check that the clone doesn't share the same underlying arrays. List<Number> values2 = new ArrayList<Number>(); values2.add(111); d1.add(values2, "R2", "C2"); assertFalse(d1.equals(d2)); d2.add(values2, "R2", "C2"); assertEquals(d1, d2); } }
8,515
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
BoxAndWhiskerCalculatorTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/statistics/BoxAndWhiskerCalculatorTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------------------- * BoxAndWhiskerCalculatorTests.java * --------------------------------- * (C) Copyright 2003-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 28-Aug-2003 : Version 1 (DG); * */ package org.jfree.data.statistics; import org.junit.Test; import java.util.ArrayList; import java.util.List; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** * Tests for the {@link BoxAndWhiskerCalculator} class. */ public class BoxAndWhiskerCalculatorTest { /** * Some checks for the calculateBoxAndWhiskerStatistics() method. */ @Test public void testCalculateBoxAndWhiskerStatistics() { // try null list try { BoxAndWhiskerCalculator.calculateBoxAndWhiskerStatistics(null); fail("IllegalArgumentException should have been thrown on a null key"); } catch (IllegalArgumentException e) { assertEquals("Null 'values' argument.", e.getMessage()); } // try a list containing a single value List<Number> values = new ArrayList<Number>(); values.add(1.1); BoxAndWhiskerItem item = BoxAndWhiskerCalculator.calculateBoxAndWhiskerStatistics(values); assertEquals(1.1, item.getMean().doubleValue(), EPSILON); assertEquals(1.1, item.getMedian().doubleValue(), EPSILON); assertEquals(1.1, item.getQ1().doubleValue(), EPSILON); assertEquals(1.1, item.getQ3().doubleValue(), EPSILON); } private static final double EPSILON = 0.000000001; /** * Tests the Q1 calculation. */ @Test public void testCalculateQ1() { // try null argument try { BoxAndWhiskerCalculator.calculateQ1(null); fail("IllegalArgumentException should have been thrown on a null key"); } catch (IllegalArgumentException e) { assertEquals("Null 'values' argument.", e.getMessage()); } List<Number> values = new ArrayList<Number>(); double q1 = BoxAndWhiskerCalculator.calculateQ1(values); assertTrue(Double.isNaN(q1)); values.add(1.0); q1 = BoxAndWhiskerCalculator.calculateQ1(values); assertEquals(q1, 1.0, EPSILON); values.add(2.0); q1 = BoxAndWhiskerCalculator.calculateQ1(values); assertEquals(q1, 1.0, EPSILON); values.add(3.0); q1 = BoxAndWhiskerCalculator.calculateQ1(values); assertEquals(q1, 1.5, EPSILON); values.add(4.0); q1 = BoxAndWhiskerCalculator.calculateQ1(values); assertEquals(q1, 1.5, EPSILON); } /** * Tests the Q3 calculation. */ @Test public void testCalculateQ3() { // try null argument try { BoxAndWhiskerCalculator.calculateQ3(null); fail("IllegalArgumentException should have been thrown on a null key"); } catch (IllegalArgumentException e) { assertEquals("Null 'values' argument.", e.getMessage()); } List<Number> values = new ArrayList<Number>(); double q3 = BoxAndWhiskerCalculator.calculateQ3(values); assertTrue(Double.isNaN(q3)); values.add(1.0); q3 = BoxAndWhiskerCalculator.calculateQ3(values); assertEquals(q3, 1.0, EPSILON); values.add(2.0); q3 = BoxAndWhiskerCalculator.calculateQ3(values); assertEquals(q3, 2.0, EPSILON); values.add(3.0); q3 = BoxAndWhiskerCalculator.calculateQ3(values); assertEquals(q3, 2.5, EPSILON); values.add(4.0); q3 = BoxAndWhiskerCalculator.calculateQ3(values); assertEquals(q3, 3.5, EPSILON); } /** * The test case included in bug report 1593149. */ @Test public void test1593149() { ArrayList<Number> theList = new ArrayList<Number>(5); theList.add(0, 1.0); theList.add(1, 2.0); theList.add(2, Double.NaN); theList.add(3, 3.0); theList.add(4, 4.0); BoxAndWhiskerItem theItem = BoxAndWhiskerCalculator.calculateBoxAndWhiskerStatistics(theList); assertEquals(1.0, theItem.getMinRegularValue().doubleValue(), EPSILON); assertEquals(4.0, theItem.getMaxRegularValue().doubleValue(), EPSILON); } }
5,718
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
DefaultBoxAndWhiskerXYDatasetTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/statistics/DefaultBoxAndWhiskerXYDatasetTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------------------------- * DefaultBoxAndWhiskerXYDatasetTests.java * --------------------------------------- * (C) Copyright 2007, 2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 12-Nov-2007 : Version 1 (DG); * */ package org.jfree.data.statistics; import org.jfree.data.Range; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.ArrayList; import java.util.Date; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for the {@link DefaultBoxAndWhiskerXYDataset} class. */ public class DefaultBoxAndWhiskerXYDatasetTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { DefaultBoxAndWhiskerXYDataset d1 = new DefaultBoxAndWhiskerXYDataset( "Series"); DefaultBoxAndWhiskerXYDataset d2 = new DefaultBoxAndWhiskerXYDataset( "Series"); assertEquals(d1, d2); d1.add(new Date(1L), new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList())); assertFalse(d1.equals(d2)); d2.add(new Date(1L), new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList())); assertEquals(d1, d2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { DefaultBoxAndWhiskerXYDataset d1 = new DefaultBoxAndWhiskerXYDataset( "Series"); d1.add(new Date(1L), new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList())); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); DefaultBoxAndWhiskerXYDataset d2 = (DefaultBoxAndWhiskerXYDataset) in.readObject(); in.close(); assertEquals(d1, d2); // test independence d1.add(new Date(2L), new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList())); assertFalse(d1.equals(d2)); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { DefaultBoxAndWhiskerXYDataset d1 = new DefaultBoxAndWhiskerXYDataset( "Series"); d1.add(new Date(1L), new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList())); DefaultBoxAndWhiskerXYDataset d2 = (DefaultBoxAndWhiskerXYDataset) d1.clone(); assertNotSame(d1, d2); assertSame(d1.getClass(), d2.getClass()); assertEquals(d1, d2); // test independence d1.add(new Date(2L), new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList())); assertFalse(d1.equals(d2)); } private static final double EPSILON = 0.0000000001; /** * Some checks for the add() method. */ @Test public void testAdd() { DefaultBoxAndWhiskerXYDataset dataset = new DefaultBoxAndWhiskerXYDataset("S1"); BoxAndWhiskerItem item1 = new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList()); dataset.add(new Date(33L), item1); assertEquals(1.0, dataset.getY(0, 0).doubleValue(), EPSILON); assertEquals(1.0, dataset.getMeanValue(0, 0).doubleValue(), EPSILON); assertEquals(2.0, dataset.getMedianValue(0, 0).doubleValue(), EPSILON); assertEquals(3.0, dataset.getQ1Value(0, 0).doubleValue(), EPSILON); assertEquals(4.0, dataset.getQ3Value(0, 0).doubleValue(), EPSILON); assertEquals(5.0, dataset.getMinRegularValue(0, 0).doubleValue(), EPSILON); assertEquals(6.0, dataset.getMaxRegularValue(0, 0).doubleValue(), EPSILON); assertEquals(7.0, dataset.getMinOutlier(0, 0).doubleValue(), EPSILON); assertEquals(8.0, dataset.getMaxOutlier(0, 0).doubleValue(), EPSILON); assertEquals(new Range(5.0, 6.0), dataset.getRangeBounds(false)); } /** * Some basic checks for the constructor. */ @Test public void testConstructor() { DefaultBoxAndWhiskerXYDataset dataset = new DefaultBoxAndWhiskerXYDataset("S1"); assertEquals(1, dataset.getSeriesCount()); assertEquals(0, dataset.getItemCount(0)); assertTrue(Double.isNaN(dataset.getRangeLowerBound(false))); assertTrue(Double.isNaN(dataset.getRangeUpperBound(false))); } /** * Some checks for the getRangeBounds() method. */ @Test public void testGetRangeBounds() { DefaultBoxAndWhiskerXYDataset d1 = new DefaultBoxAndWhiskerXYDataset("S"); d1.add(new Date(1L), new BoxAndWhiskerItem(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList())); assertEquals(new Range(5.0, 6.0), d1.getRangeBounds(false)); assertEquals(new Range(5.0, 6.0), d1.getRangeBounds(true)); d1.add(new Date(1L), new BoxAndWhiskerItem(1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, new ArrayList())); assertEquals(new Range(5.0, 6.5), d1.getRangeBounds(false)); assertEquals(new Range(5.0, 6.5), d1.getRangeBounds(true)); d1.add(new Date(2L), new BoxAndWhiskerItem(2.5, 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, new ArrayList())); assertEquals(new Range(5.0, 7.5), d1.getRangeBounds(false)); assertEquals(new Range(5.0, 7.5), d1.getRangeBounds(true)); } }
7,553
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
HistogramDatasetTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/statistics/HistogramDatasetTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------------- * HistogramDatasetTests.java * -------------------------- * (C) Copyright 2004-2009, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 01-Mar-2004 : Version 1 (DG); * 08-Jun-2005 : Added test for getSeriesKey(int) bug (DG); * 03-Aug-2006 : Added testAddSeries() and testBinBoundaries() method (DG); * 22-May-2008 : Added testAddSeries2() and enhanced testCloning() (DG); * 08-Dec-2009 : Added test2902842() for patch at SourceForge (DG); * */ package org.jfree.data.statistics; import org.jfree.data.general.DatasetChangeEvent; import org.jfree.data.general.DatasetChangeListener; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for the {@link HistogramDataset} class. */ public class HistogramDatasetTest implements DatasetChangeListener { private static final double EPSILON = 0.0000000001; /** * Some checks that the correct values are assigned to bins. */ @Test public void testBins() { double[] values = {1.0, 2.0, 3.0, 4.0, 6.0, 12.0, 5.0, 6.3, 4.5}; HistogramDataset hd = new HistogramDataset(); hd.addSeries("Series 1", values, 5); assertEquals(hd.getYValue(0, 0), 3.0, EPSILON); assertEquals(hd.getYValue(0, 1), 3.0, EPSILON); assertEquals(hd.getYValue(0, 2), 2.0, EPSILON); assertEquals(hd.getYValue(0, 3), 0.0, EPSILON); assertEquals(hd.getYValue(0, 4), 1.0, EPSILON); } /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { double[] values = {1.0, 2.0, 3.0, 4.0, 6.0, 12.0, 5.0, 6.3, 4.5}; HistogramDataset d1 = new HistogramDataset(); d1.addSeries("Series 1", values, 5); HistogramDataset d2 = new HistogramDataset(); d2.addSeries("Series 1", values, 5); assertEquals(d1, d2); assertEquals(d2, d1); d1.addSeries("Series 2", new double[] {1.0, 2.0, 3.0}, 2); assertFalse(d1.equals(d2)); d2.addSeries("Series 2", new double[] {1.0, 2.0, 3.0}, 2); assertEquals(d1, d2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { double[] values = {1.0, 2.0, 3.0, 4.0, 6.0, 12.0, 5.0, 6.3, 4.5}; HistogramDataset d1 = new HistogramDataset(); d1.addSeries("Series 1", values, 5); HistogramDataset d2 = (HistogramDataset) d1.clone(); assertNotSame(d1, d2); assertSame(d1.getClass(), d2.getClass()); assertEquals(d1, d2); // simple check for independence d1.addSeries("Series 2", new double[] {1.0, 2.0, 3.0}, 2); assertFalse(d1.equals(d2)); d2.addSeries("Series 2", new double[] {1.0, 2.0, 3.0}, 2); assertEquals(d1, d2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { double[] values = {1.0, 2.0, 3.0, 4.0, 6.0, 12.0, 5.0, 6.3, 4.5}; HistogramDataset d1 = new HistogramDataset(); d1.addSeries("Series 1", values, 5); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); HistogramDataset d2 = (HistogramDataset) in.readObject(); in.close(); assertEquals(d1, d2); // simple check for independence d1.addSeries("Series 2", new double[] {1.0, 2.0, 3.0}, 2); assertFalse(d1.equals(d2)); d2.addSeries("Series 2", new double[] {1.0, 2.0, 3.0}, 2); assertEquals(d1, d2); } /** * A test for a bug reported in the forum where the series name isn't being * returned correctly. */ @Test public void testGetSeriesKey() { double[] values = {1.0, 2.0, 3.0, 4.0, 6.0, 12.0, 5.0, 6.3, 4.5}; HistogramDataset d1 = new HistogramDataset(); d1.addSeries("Series 1", values, 5); assertEquals("Series 1", d1.getSeriesKey(0)); } /** * Some checks for the addSeries() method. */ @Test public void testAddSeries() { double[] values = {-1.0, 0.0, 0.1, 0.9, 1.0, 1.1, 1.9, 2.0, 3.0}; HistogramDataset d = new HistogramDataset(); d.addSeries("S1", values, 2, 0.0, 2.0); assertEquals(0.0, d.getStartXValue(0, 0), EPSILON); assertEquals(1.0, d.getEndXValue(0, 0), EPSILON); assertEquals(4.0, d.getYValue(0, 0), EPSILON); assertEquals(1.0, d.getStartXValue(0, 1), EPSILON); assertEquals(2.0, d.getEndXValue(0, 1), EPSILON); assertEquals(5.0, d.getYValue(0, 1), EPSILON); } /** * Another check for the addSeries() method. */ @Test public void testAddSeries2() { double[] values = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0}; HistogramDataset hd = new HistogramDataset(); hd.addSeries("S1", values, 5); assertEquals(0.0, hd.getStartXValue(0, 0), EPSILON); assertEquals(1.0, hd.getEndXValue(0, 0), EPSILON); assertEquals(1.0, hd.getYValue(0, 0), EPSILON); assertEquals(1.0, hd.getStartXValue(0, 1), EPSILON); assertEquals(2.0, hd.getEndXValue(0, 1), EPSILON); assertEquals(1.0, hd.getYValue(0, 1), EPSILON); assertEquals(2.0, hd.getStartXValue(0, 2), EPSILON); assertEquals(3.0, hd.getEndXValue(0, 2), EPSILON); assertEquals(1.0, hd.getYValue(0, 2), EPSILON); assertEquals(3.0, hd.getStartXValue(0, 3), EPSILON); assertEquals(4.0, hd.getEndXValue(0, 3), EPSILON); assertEquals(1.0, hd.getYValue(0, 3), EPSILON); assertEquals(4.0, hd.getStartXValue(0, 4), EPSILON); assertEquals(5.0, hd.getEndXValue(0, 4), EPSILON); assertEquals(2.0, hd.getYValue(0, 4), EPSILON); } /** * This test is derived from a reported bug. */ @Test public void testBinBoundaries() { double[] values = {-5.000000000000286E-5}; int bins = 1260; double minimum = -0.06307522528160199; double maximum = 0.06297522528160199; HistogramDataset d = new HistogramDataset(); d.addSeries("S1", values, bins, minimum, maximum); assertEquals(0.0, d.getYValue(0, 629), EPSILON); assertEquals(1.0, d.getYValue(0, 630), EPSILON); assertEquals(0.0, d.getYValue(0, 631), EPSILON); assertTrue(values[0] > d.getStartXValue(0, 630)); assertTrue(values[0] < d.getEndXValue(0, 630)); } /** * Some checks for bug 1553088. An IndexOutOfBoundsException is thrown * when a data value is *very* close to the upper limit of the last bin. */ @Test public void test1553088() { double[] values = {-1.0, 0.0, -Double.MIN_VALUE, 3.0}; HistogramDataset d = new HistogramDataset(); d.addSeries("S1", values, 2, -1.0, 0.0); assertEquals(-1.0, d.getStartXValue(0, 0), EPSILON); assertEquals(-0.5, d.getEndXValue(0, 0), EPSILON); assertEquals(1.0, d.getYValue(0, 0), EPSILON); assertEquals(-0.5, d.getStartXValue(0, 1), EPSILON); assertEquals(0.0, d.getEndXValue(0, 1), EPSILON); assertEquals(3.0, d.getYValue(0, 1), EPSILON); } /** * A test to show the limitation addressed by patch 2902842. */ @Test public void test2902842() { this.lastEvent = null; double[] values = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0}; HistogramDataset hd = new HistogramDataset(); hd.addChangeListener(this); hd.addSeries("S1", values, 5); assertNotNull(this.lastEvent); } /** * A reference to the last event received by the datasetChanged() method. */ private DatasetChangeEvent lastEvent; /** * Receives event notification. * * @param event the event. */ @Override public void datasetChanged(DatasetChangeEvent event) { this.lastEvent = event; } }
10,008
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
HistogramBinTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/statistics/HistogramBinTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------- * HistogramBinTests.java * ---------------------- * (C) Copyright 2004-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 01-Mar-2004 : Version 1 (DG); * */ package org.jfree.data.statistics; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; /** * Tests for the {@link HistogramBin} class. */ public class HistogramBinTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { double start = 10.0; double end = 20.0; HistogramBin b1 = new HistogramBin(start, end); HistogramBin b2 = new HistogramBin(start, end); assertEquals(b1, b2); assertEquals(b2, b1); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { double start = 10.0; double end = 20.0; HistogramBin b1 = new HistogramBin(start, end); HistogramBin b2 = (HistogramBin) b1.clone(); assertNotSame(b1, b2); assertSame(b1.getClass(), b2.getClass()); assertEquals(b1, b2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { double start = 10.0; double end = 20.0; HistogramBin b1 = new HistogramBin(start, end); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(b1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); HistogramBin b2 = (HistogramBin) in.readObject(); in.close(); assertEquals(b1, b2); } }
3,551
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
SimpleHistogramDatasetTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/statistics/SimpleHistogramDatasetTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------------------- * SimpleHistogramDatasetTests.java * -------------------------------- * (C) Copyright 2005-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 10-Jan-2005 : Version 1 (DG); * 21-May-2007 : Added testClearObservations (DG); * */ package org.jfree.data.statistics; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; /** * Tests for the {@link SimpleHistogramDataset} class. */ public class SimpleHistogramDatasetTest { /** * Ensure that the equals() method can distinguish all fields. */ @Test public void testEquals() { SimpleHistogramDataset d1 = new SimpleHistogramDataset("Dataset 1"); SimpleHistogramDataset d2 = new SimpleHistogramDataset("Dataset 1"); assertEquals(d1, d2); d1.addBin(new SimpleHistogramBin(1.0, 2.0)); assertFalse(d1.equals(d2)); d2.addBin(new SimpleHistogramBin(1.0, 2.0)); assertEquals(d1, d2); } /** * Some checks for the clone() method. */ @Test public void testCloning() throws CloneNotSupportedException { SimpleHistogramDataset d1 = new SimpleHistogramDataset("Dataset 1"); SimpleHistogramDataset d2 = (SimpleHistogramDataset) d1.clone(); assertNotSame(d1, d2); assertSame(d1.getClass(), d2.getClass()); assertEquals(d1, d2); // check that clone is independent of the original d2.addBin(new SimpleHistogramBin(2.0, 3.0)); d2.addObservation(2.3); assertFalse(d1.equals(d2)); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { SimpleHistogramDataset d1 = new SimpleHistogramDataset("D1"); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); SimpleHistogramDataset d2 = (SimpleHistogramDataset) in.readObject(); in.close(); assertEquals(d1, d2); } private static final double EPSILON = 0.0000000001; /** * Some checks for the clearObservations() method. */ @Test public void testClearObservations() { SimpleHistogramDataset d1 = new SimpleHistogramDataset("D1"); d1.clearObservations(); assertEquals(0, d1.getItemCount(0)); d1.addBin(new SimpleHistogramBin(0.0, 1.0)); d1.addObservation(0.5); assertEquals(1.0, d1.getYValue(0, 0), EPSILON); } /** * Some checks for the removeAllBins() method. */ @Test public void testRemoveAllBins() { SimpleHistogramDataset d1 = new SimpleHistogramDataset("D1"); d1.addBin(new SimpleHistogramBin(0.0, 1.0)); d1.addObservation(0.5); d1.addBin(new SimpleHistogramBin(2.0, 3.0)); assertEquals(2, d1.getItemCount(0)); d1.removeAllBins(); assertEquals(0, d1.getItemCount(0)); } }
4,890
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
RegressionTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/statistics/RegressionTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * RegressionTests.java * -------------------- * (C) Copyright 2002-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 30-Sep-2002 : Version 1 (DG); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * */ package org.jfree.data.statistics; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.junit.Test; import static org.junit.Assert.assertEquals; /** * Tests for the {@link Regression} class. */ public class RegressionTest { /** * Checks the results of an OLS regression on sample dataset 1. */ @Test public void testOLSRegression1a() { double[][] data = createSampleData1(); double[] result1 = Regression.getOLSRegression(data); assertEquals(.25680930, result1[0], 0.0000001); assertEquals(0.72792106, result1[1], 0.0000001); } /** * Checks the results of an OLS regression on sample dataset 1 AFTER * converting it to an XYSeries. */ @Test public void testOLSRegression1b() { double[][] data = createSampleData1(); XYSeries series = new XYSeries("Test"); for (int i = 0; i < 11; i++) { series.add(data[i][0], data[i][1]); } XYDataset ds = new XYSeriesCollection(series); double[] result2 = Regression.getOLSRegression(ds, 0); assertEquals(.25680930, result2[0], 0.0000001); assertEquals(0.72792106, result2[1], 0.0000001); } /** * Checks the results of a power regression on sample dataset 1. */ @Test public void testPowerRegression1a() { double[][] data = createSampleData1(); double[] result = Regression.getPowerRegression(data); assertEquals(0.91045813, result[0], 0.0000001); assertEquals(0.88918346, result[1], 0.0000001); } /** * Checks the results of a power regression on sample dataset 1 AFTER * converting it to an XYSeries. */ @Test public void testPowerRegression1b() { double[][] data = createSampleData1(); XYSeries series = new XYSeries("Test"); for (int i = 0; i < 11; i++) { series.add(data[i][0], data[i][1]); } XYDataset ds = new XYSeriesCollection(series); double[] result = Regression.getPowerRegression(ds, 0); assertEquals(0.91045813, result[0], 0.0000001); assertEquals(0.88918346, result[1], 0.0000001); } /** * Checks the results of an OLS regression on sample dataset 2. */ @Test public void testOLSRegression2a() { double[][] data = createSampleData2(); double[] result = Regression.getOLSRegression(data); assertEquals(53.9729697, result[0], 0.0000001); assertEquals(-4.1823030, result[1], 0.0000001); } /** * Checks the results of an OLS regression on sample dataset 2 AFTER * converting it to an XYSeries. */ @Test public void testOLSRegression2b() { double[][] data = createSampleData2(); XYSeries series = new XYSeries("Test"); for (int i = 0; i < 10; i++) { series.add(data[i][0], data[i][1]); } XYDataset ds = new XYSeriesCollection(series); double[] result = Regression.getOLSRegression(ds, 0); assertEquals(53.9729697, result[0], 0.0000001); assertEquals(-4.1823030, result[1], 0.0000001); } /** * Checks the results of a power regression on sample dataset 2. */ @Test public void testPowerRegression2a() { double[][] data = createSampleData2(); double[] result = Regression.getPowerRegression(data); assertEquals(106.1241681, result[0], 0.0000001); assertEquals(-0.8466615, result[1], 0.0000001); } /** * Checks the results of a power regression on sample dataset 2 AFTER * converting it to an XYSeries. */ @Test public void testPowerRegression2b() { double[][] data = createSampleData2(); XYSeries series = new XYSeries("Test"); for (int i = 0; i < 10; i++) { series.add(data[i][0], data[i][1]); } XYDataset ds = new XYSeriesCollection(series); double[] result = Regression.getPowerRegression(ds, 0); assertEquals(106.1241681, result[0], 0.0000001); assertEquals(-0.8466615, result[1], 0.0000001); } /** * Creates and returns a sample dataset. * <P> * The data is taken from Table 11.2, page 313 of "Understanding Statistics" * by Ott and Mendenhall (Duxbury Press). * * @return The sample data. */ private double[][] createSampleData1() { double[][] result = new double[11][2]; result[0][0] = 2.00; result[0][1] = 1.60; result[1][0] = 2.25; result[1][1] = 2.00; result[2][0] = 2.60; result[2][1] = 1.80; result[3][0] = 2.65; result[3][1] = 2.80; result[4][0] = 2.80; result[4][1] = 2.10; result[5][0] = 3.10; result[5][1] = 2.00; result[6][0] = 2.90; result[6][1] = 2.65; result[7][0] = 3.25; result[7][1] = 2.25; result[8][0] = 3.30; result[8][1] = 2.60; result[9][0] = 3.60; result[9][1] = 3.00; result[10][0] = 3.25; result[10][1] = 3.10; return result; } /** * Creates a sample data set. * * @return The sample data. */ private double[][] createSampleData2() { double[][] result = new double[10][2]; result[0][0] = 2; result[0][1] = 56.27; result[1][0] = 3; result[1][1] = 41.32; result[2][0] = 4; result[2][1] = 31.45; result[3][0] = 5; result[3][1] = 30.05; result[4][0] = 6; result[4][1] = 24.69; result[5][0] = 7; result[5][1] = 19.78; result[6][0] = 8; result[6][1] = 20.94; result[7][0] = 9; result[7][1] = 16.73; result[8][0] = 10; result[8][1] = 14.21; result[9][0] = 11; result[9][1] = 12.44; return result; } }
7,589
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
BoxAndWhiskerItemTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/statistics/BoxAndWhiskerItemTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------------- * BoxAndWhiskerItemTests.java * --------------------------- * (C) Copyright 2004-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 01-Mar-2004 : Version 1 (DG); * */ package org.jfree.data.statistics; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.ArrayList; import static org.junit.Assert.assertEquals; /** * Tests for the {@link BoxAndWhiskerItem} class. */ public class BoxAndWhiskerItemTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { BoxAndWhiskerItem i1 = new BoxAndWhiskerItem( 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList() ); BoxAndWhiskerItem i2 = new BoxAndWhiskerItem( 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList() ); assertEquals(i1, i2); assertEquals(i2, i1); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { BoxAndWhiskerItem i1 = new BoxAndWhiskerItem( 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, new ArrayList() ); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(i1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); BoxAndWhiskerItem i2 = (BoxAndWhiskerItem) in.readObject(); in.close(); assertEquals(i1, i2); } }
3,313
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
MeanAndStandardDeviationTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/statistics/MeanAndStandardDeviationTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------------------- * MeanAndStandardDeviationTests.java * ---------------------------------- * (C) Copyright 2005-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 05-Feb-2005 : Version 1 (DG); * */ package org.jfree.data.statistics; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; /** * Tests for the {@link MeanAndStandardDeviation} class. */ public class MeanAndStandardDeviationTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { MeanAndStandardDeviation m1 = new MeanAndStandardDeviation(1.2, 3.4); MeanAndStandardDeviation m2 = new MeanAndStandardDeviation(1.2, 3.4); assertEquals(m1, m2); assertEquals(m2, m1); m1 = new MeanAndStandardDeviation(1.0, 3.4); assertFalse(m1.equals(m2)); m2 = new MeanAndStandardDeviation(1.0, 3.4); assertEquals(m1, m2); m1 = new MeanAndStandardDeviation(1.0, 3.0); assertFalse(m1.equals(m2)); m2 = new MeanAndStandardDeviation(1.0, 3.0); assertEquals(m1, m2); } /** * Immutable class - should not be cloneable. */ @Test public void testCloning() throws CloneNotSupportedException { MeanAndStandardDeviation m1 = new MeanAndStandardDeviation(1.2, 3.4); assertFalse(m1 instanceof Cloneable); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { MeanAndStandardDeviation m1 = new MeanAndStandardDeviation(1.2, 3.4); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(m1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); MeanAndStandardDeviation m2 = (MeanAndStandardDeviation) in.readObject(); in.close(); assertEquals(m1, m2); } }
3,765
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
LineFunction2DTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/function/LineFunction2DTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------ * LineFunction2DTests.java * ------------------------ * (C) Copyright 2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 28-May-2009 : Version 1 (DG); * */ package org.jfree.data.function; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; /** * Tests for the {@link LineFunction2D} class. */ public class LineFunction2DTest { private static final double EPSILON = 0.000000001; /** * Some tests for the constructor. */ @Test public void testConstructor() { LineFunction2D f = new LineFunction2D(1.0, 2.0); assertEquals(1.0, f.getIntercept(), EPSILON); assertEquals(2.0, f.getSlope(), EPSILON); } /** * For datasets, the equals() method just checks keys and values. */ @Test public void testEquals() { LineFunction2D f1 = new LineFunction2D(1.0, 2.0); LineFunction2D f2 = new LineFunction2D(1.0, 2.0); assertEquals(f1, f2); f1 = new LineFunction2D(2.0, 3.0); assertFalse(f1.equals(f2)); f2 = new LineFunction2D(2.0, 3.0); assertEquals(f1, f2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { LineFunction2D f1 = new LineFunction2D(1.0, 2.0); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(f1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); LineFunction2D f2 = (LineFunction2D) in.readObject(); in.close(); assertEquals(f1, f2); } /** * Objects that are equal should have the same hash code otherwise FindBugs * will tell on us... */ @Test public void testHashCode() { LineFunction2D f1 = new LineFunction2D(1.0, 2.0); LineFunction2D f2 = new LineFunction2D(1.0, 2.0); assertEquals(f1.hashCode(), f2.hashCode()); } }
3,744
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
PolynomialFunction2DTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/function/PolynomialFunction2DTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------------ * PolynomialFunction2DTests.java * ------------------------------ * (C) Copyright 2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 28-May-2009 : Version 1 (DG); * */ package org.jfree.data.function; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.fail; /** * Tests for the {@link PolynomialFunction2D} class. */ public class PolynomialFunction2DTest { /** * Some tests for the constructor. */ @Test public void testConstructor() { PolynomialFunction2D f = new PolynomialFunction2D(new double[] {1.0, 2.0}); assertArrayEquals(new double[]{1.0, 2.0}, f.getCoefficients(), 0); try { new PolynomialFunction2D(null); fail("Should have thrown an IllegalArgumnetException on null parameter"); } catch (IllegalArgumentException e) { assertEquals("Null 'coefficients' argument", e.getMessage()); } } /** * Some checks for the getCoefficients() method. */ @Test public void testGetCoefficients() { PolynomialFunction2D f = new PolynomialFunction2D(new double[] {1.0, 2.0}); double[] c = f.getCoefficients(); assertArrayEquals(new double[]{1.0, 2.0}, c, 0); // make sure that modifying the returned array doesn't change the // function c[0] = 99.9; assertArrayEquals(new double[]{1.0, 2.0}, f.getCoefficients(), 0); } /** * Some checks for the getOrder() method. */ @Test public void testGetOrder() { PolynomialFunction2D f = new PolynomialFunction2D(new double[] {1.0, 2.0}); assertEquals(1, f.getOrder()); } /** * For datasets, the equals() method just checks keys and values. */ @Test public void testEquals() { PolynomialFunction2D f1 = new PolynomialFunction2D(new double[] {1.0, 2.0}); PolynomialFunction2D f2 = new PolynomialFunction2D(new double[] {1.0, 2.0}); assertEquals(f1, f2); f1 = new PolynomialFunction2D(new double[] {2.0, 3.0}); assertFalse(f1.equals(f2)); f2 = new PolynomialFunction2D(new double[] {2.0, 3.0}); assertEquals(f1, f2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { PolynomialFunction2D f1 = new PolynomialFunction2D(new double[] {1.0, 2.0}); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(f1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); PolynomialFunction2D f2 = (PolynomialFunction2D) in.readObject(); in.close(); assertEquals(f1, f2); } /** * Objects that are equal should have the same hash code otherwise FindBugs * will tell on us... */ @Test public void testHashCode() { PolynomialFunction2D f1 = new PolynomialFunction2D(new double[] {1.0, 2.0}); PolynomialFunction2D f2 = new PolynomialFunction2D(new double[] {1.0, 2.0}); assertEquals(f1.hashCode(), f2.hashCode()); } }
5,176
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
PowerFunction2DTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/function/PowerFunction2DTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------- * PowerFunction2DTests.java * ------------------------- * (C) Copyright 2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 28-May-2009 : Version 1 (DG); * */ package org.jfree.data.function; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; /** * Tests for the {@link PowerFunction2D} class. */ public class PowerFunction2DTest { private static final double EPSILON = 0.000000001; /** * Some tests for the constructor. */ @Test public void testConstructor() { PowerFunction2D f = new PowerFunction2D(1.0, 2.0); assertEquals(1.0, f.getA(), EPSILON); assertEquals(2.0, f.getB(), EPSILON); } /** * For datasets, the equals() method just checks keys and values. */ @Test public void testEquals() { PowerFunction2D f1 = new PowerFunction2D(1.0, 2.0); PowerFunction2D f2 = new PowerFunction2D(1.0, 2.0); assertEquals(f1, f2); f1 = new PowerFunction2D(2.0, 3.0); assertFalse(f1.equals(f2)); f2 = new PowerFunction2D(2.0, 3.0); assertEquals(f1, f2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { PowerFunction2D f1 = new PowerFunction2D(1.0, 2.0); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(f1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); PowerFunction2D f2 = (PowerFunction2D) in.readObject(); in.close(); assertEquals(f1, f2); } /** * Objects that are equal should have the same hash code otherwise FindBugs * will tell on us... */ @Test public void testHashCode() { PowerFunction2D f1 = new PowerFunction2D(1.0, 2.0); PowerFunction2D f2 = new PowerFunction2D(1.0, 2.0); assertEquals(f1.hashCode(), f2.hashCode()); } }
3,791
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
NormalDistributionFunction2DTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/function/NormalDistributionFunction2DTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------------------------- * NormalDistributionFunction2DTests.java * -------------------------------------- * (C) Copyright 2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 28-May-2009 : Version 1 (DG); * */ package org.jfree.data.function; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; /** * Tests for the {@link NormalDistributionFunction2D} class. */ public class NormalDistributionFunction2DTest { private static final double EPSILON = 0.000000001; /** * Some tests for the constructor. */ @Test public void testConstructor() { NormalDistributionFunction2D f = new NormalDistributionFunction2D(1.0, 2.0); assertEquals(1.0, f.getMean(), EPSILON); assertEquals(2.0, f.getStandardDeviation(), EPSILON); } /** * For datasets, the equals() method just checks keys and values. */ @Test public void testEquals() { NormalDistributionFunction2D f1 = new NormalDistributionFunction2D(1.0, 2.0); NormalDistributionFunction2D f2 = new NormalDistributionFunction2D(1.0, 2.0); assertEquals(f1, f2); f1 = new NormalDistributionFunction2D(2.0, 3.0); assertFalse(f1.equals(f2)); f2 = new NormalDistributionFunction2D(2.0, 3.0); assertEquals(f1, f2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { NormalDistributionFunction2D f1 = new NormalDistributionFunction2D(1.0, 2.0); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(f1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); NormalDistributionFunction2D f2 = (NormalDistributionFunction2D) in.readObject(); in.close(); assertEquals(f1, f2); } /** * Objects that are equal should have the same hash code otherwise FindBugs * will tell on us... */ @Test public void testHashCode() { NormalDistributionFunction2D f1 = new NormalDistributionFunction2D(1.0, 2.0); NormalDistributionFunction2D f2 = new NormalDistributionFunction2D(1.0, 2.0); assertEquals(f1.hashCode(), f2.hashCode()); } }
4,179
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TaskSeriesCollectionTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/gantt/TaskSeriesCollectionTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------------ * TaskSeriesCollectionTests.java * ------------------------------ * (C) Copyright 2004-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 30-Jul-2004 : Version 1 (DG); * 12-Jan-2005 : Added tests from TaskSeriesCollectionTests2.java (DG); * 08-Mar-2007 : Added testRemove() (DG); * */ package org.jfree.data.gantt; import org.jfree.data.time.SimpleTimePeriod; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.Date; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; /** * Tests for the {@link TaskSeriesCollection} class. */ public class TaskSeriesCollectionTest { /** * Creates a sample collection for testing purposes. * * @return A sample collection. */ private TaskSeriesCollection createCollection1() { TaskSeriesCollection result = new TaskSeriesCollection(); TaskSeries s1 = new TaskSeries("S1"); s1.add(new Task("Task 1", new Date(1), new Date(2))); s1.add(new Task("Task 2", new Date(3), new Date(4))); result.add(s1); TaskSeries s2 = new TaskSeries("S2"); s2.add(new Task("Task 3", new Date(5), new Date(6))); result.add(s2); return result; } /** * Creates a sample collection for testing purposes. * * @return A sample collection. */ private TaskSeriesCollection createCollection2() { TaskSeriesCollection result = new TaskSeriesCollection(); TaskSeries s1 = new TaskSeries("S1"); Task t1 = new Task("Task 1", new Date(10), new Date(20)); t1.addSubtask(new Task("Task 1A", new Date(10), new Date(15))); t1.addSubtask(new Task("Task 1B", new Date(16), new Date(20))); t1.setPercentComplete(0.10); s1.add(t1); Task t2 = new Task("Task 2", new Date(30), new Date(40)); t2.addSubtask(new Task("Task 2A", new Date(30), new Date(35))); t2.addSubtask(new Task("Task 2B", new Date(36), new Date(40))); t2.setPercentComplete(0.20); s1.add(t2); result.add(s1); TaskSeries s2 = new TaskSeries("S2"); Task t3 = new Task("Task 3", new Date(50), new Date(60)); t3.addSubtask(new Task("Task 3A", new Date(50), new Date(55))); t3.addSubtask(new Task("Task 3B", new Date(56), new Date(60))); t3.setPercentComplete(0.30); s2.add(t3); result.add(s2); return result; } /** * Creates a sample collection for testing purposes. * * @return A sample collection. */ private TaskSeriesCollection createCollection3() { // define subtasks Task sub1 = new Task("Sub1", new Date(11), new Date(111)); Task sub2 = new Task("Sub2", new Date(22), new Date(222)); Task sub3 = new Task("Sub3", new Date(33), new Date(333)); Task sub4 = new Task("Sub4", new Date(44), new Date(444)); Task sub5 = new Task("Sub5", new Date(55), new Date(555)); Task sub6 = new Task("Sub6", new Date(66), new Date(666)); sub1.setPercentComplete(0.111); sub2.setPercentComplete(0.222); sub3.setPercentComplete(0.333); sub4.setPercentComplete(0.444); sub5.setPercentComplete(0.555); sub6.setPercentComplete(0.666); TaskSeries seriesA = new TaskSeries("Series A"); Task taskA1 = new Task("Task 1", new SimpleTimePeriod(new Date(100), new Date(200))); taskA1.setPercentComplete(0.1); taskA1.addSubtask(sub1); Task taskA2 = new Task("Task 2", new SimpleTimePeriod(new Date(220), new Date(350))); taskA2.setPercentComplete(0.2); taskA2.addSubtask(sub2); taskA2.addSubtask(sub3); seriesA.add(taskA1); seriesA.add(taskA2); TaskSeries seriesB = new TaskSeries("Series B"); // note that we don't define taskB1 Task taskB2 = new Task("Task 2", new SimpleTimePeriod(new Date(2220), new Date(3350))); taskB2.setPercentComplete(0.3); taskB2.addSubtask(sub4); taskB2.addSubtask(sub5); taskB2.addSubtask(sub6); seriesB.add(taskB2); TaskSeriesCollection tsc = new TaskSeriesCollection(); tsc.add(seriesA); tsc.add(seriesB); return tsc; } /** * A test for the getSeriesCount() method. */ @Test public void testGetSeriesCount() { TaskSeriesCollection c = createCollection1(); assertEquals(2, c.getSeriesCount()); } /** * Some tests for the getSeriesKey() method. */ @Test public void testGetSeriesKey() { TaskSeriesCollection c = createCollection1(); assertEquals("S1", c.getSeriesKey(0)); assertEquals("S2", c.getSeriesKey(1)); } /** * A test for the getRowCount() method. */ @Test public void testGetRowCount() { TaskSeriesCollection c = createCollection1(); assertEquals(2, c.getRowCount()); } /** * Some tests for the getRowKey() method. */ @Test public void testGetRowKey() { TaskSeriesCollection c = createCollection1(); assertEquals("S1", c.getRowKey(0)); assertEquals("S2", c.getRowKey(1)); } /** * Some tests for the getRowIndex() method. */ @Test public void testGetRowIndex() { TaskSeriesCollection c = createCollection1(); assertEquals(0, c.getRowIndex("S1")); assertEquals(1, c.getRowIndex("S2")); } /** * Some tests for the getValue() method. */ @Test public void testGetValue() { TaskSeriesCollection c = createCollection1(); assertEquals(1L, c.getValue("S1", "Task 1")); assertEquals(3L, c.getValue("S1", "Task 2")); assertEquals(5L, c.getValue("S2", "Task 3")); assertEquals(1L, c.getValue(0, 0)); assertEquals(3L, c.getValue(0, 1)); assertEquals(null, c.getValue(0, 2)); assertEquals(null, c.getValue(1, 0)); assertEquals(null, c.getValue(1, 1)); assertEquals(5L, c.getValue(1, 2)); } /** * Some tests for the getStartValue() method. */ @Test public void testGetStartValue() { TaskSeriesCollection c = createCollection1(); assertEquals(1L, c.getStartValue("S1", "Task 1")); assertEquals(3L, c.getStartValue("S1", "Task 2")); assertEquals(5L, c.getStartValue("S2", "Task 3")); assertEquals(1L, c.getStartValue(0, 0)); assertEquals(3L, c.getStartValue(0, 1)); assertEquals(null, c.getStartValue(0, 2)); assertEquals(null, c.getStartValue(1, 0)); assertEquals(null, c.getStartValue(1, 1)); assertEquals(5L, c.getStartValue(1, 2)); // test collection 3, which doesn't define all tasks in all series TaskSeriesCollection c3 = createCollection3(); assertEquals((long) 100, c3.getStartValue(0, 0)); assertEquals((long) 220, c3.getStartValue(0, 1)); assertNull(c3.getStartValue(1, 0)); assertEquals((long) 2220, c3.getStartValue(1, 1)); } /** * Some tests for the getStartValue() method for sub-intervals. */ @Test public void testGetStartValue2() { TaskSeriesCollection c = createCollection2(); assertEquals(10L, c.getStartValue("S1", "Task 1", 0)); assertEquals(16L, c.getStartValue("S1", "Task 1", 1)); assertEquals(30L, c.getStartValue("S1", "Task 2", 0)); assertEquals(36L, c.getStartValue("S1", "Task 2", 1)); assertEquals(50L, c.getStartValue("S2", "Task 3", 0)); assertEquals(56L, c.getStartValue("S2", "Task 3", 1)); assertEquals(10L, c.getStartValue(0, 0, 0)); assertEquals(16L, c.getStartValue(0, 0, 1)); assertEquals(30L, c.getStartValue(0, 1, 0)); assertEquals(36L, c.getStartValue(0, 1, 1)); assertEquals(50L, c.getStartValue(1, 2, 0)); assertEquals(56L, c.getStartValue(1, 2, 1)); TaskSeriesCollection c3 = createCollection3(); assertEquals((long) 11, c3.getStartValue(0, 0, 0)); assertEquals((long) 22, c3.getStartValue(0, 1, 0)); assertEquals((long) 33, c3.getStartValue(0, 1, 1)); assertNull(c3.getStartValue(1, 0, 0)); assertEquals((long) 44, c3.getStartValue(1, 1, 0)); assertEquals((long) 55, c3.getStartValue(1, 1, 1)); assertEquals((long) 66, c3.getStartValue(1, 1, 2)); } /** * A check for a null task duration. */ @Test public void testGetStartValue3() { TaskSeriesCollection c = new TaskSeriesCollection(); TaskSeries s = new TaskSeries("Series 1"); s.add(new Task("Task with null duration", null)); c.add(s); Number millis = c.getStartValue("Series 1", "Task with null duration"); assertNull(millis); } /** * Some tests for the getEndValue() method. */ @Test public void testGetEndValue() { TaskSeriesCollection c = createCollection1(); assertEquals(2L, c.getEndValue("S1", "Task 1")); assertEquals(4L, c.getEndValue("S1", "Task 2")); assertEquals(6L, c.getEndValue("S2", "Task 3")); assertEquals(2L, c.getEndValue(0, 0)); assertEquals(4L, c.getEndValue(0, 1)); assertEquals(null, c.getEndValue(0, 2)); assertEquals(null, c.getEndValue(1, 0)); assertEquals(null, c.getEndValue(1, 1)); assertEquals(6L, c.getEndValue(1, 2)); // test collection 3, which doesn't define all tasks in all series TaskSeriesCollection c3 = createCollection3(); assertEquals((long) 200, c3.getEndValue(0, 0)); assertEquals((long) 350, c3.getEndValue(0, 1)); assertNull(c3.getEndValue(1, 0)); assertEquals((long) 3350, c3.getEndValue(1, 1)); } /** * Some tests for the getEndValue() method for sub-intervals. */ @Test public void testGetEndValue2() { TaskSeriesCollection c = createCollection2(); assertEquals(15L, c.getEndValue("S1", "Task 1", 0)); assertEquals(20L, c.getEndValue("S1", "Task 1", 1)); assertEquals(35L, c.getEndValue("S1", "Task 2", 0)); assertEquals(40L, c.getEndValue("S1", "Task 2", 1)); assertEquals(55L, c.getEndValue("S2", "Task 3", 0)); assertEquals(60L, c.getEndValue("S2", "Task 3", 1)); assertEquals(15L, c.getEndValue(0, 0, 0)); assertEquals(20L, c.getEndValue(0, 0, 1)); assertEquals(35L, c.getEndValue(0, 1, 0)); assertEquals(40L, c.getEndValue(0, 1, 1)); assertEquals(55L, c.getEndValue(1, 2, 0)); assertEquals(60L, c.getEndValue(1, 2, 1)); TaskSeriesCollection c3 = createCollection3(); assertEquals((long) 111, c3.getEndValue(0, 0, 0)); assertEquals((long) 222, c3.getEndValue(0, 1, 0)); assertEquals((long) 333, c3.getEndValue(0, 1, 1)); assertNull(c3.getEndValue(1, 0, 0)); assertEquals((long) 444, c3.getEndValue(1, 1, 0)); assertEquals((long) 555, c3.getEndValue(1, 1, 1)); assertEquals((long) 666, c3.getEndValue(1, 1, 2)); } /** * A check for a null task duration. */ @Test public void testGetEndValue3() { TaskSeriesCollection c = new TaskSeriesCollection(); TaskSeries s = new TaskSeries("Series 1"); s.add(new Task("Task with null duration", null)); c.add(s); Number millis = c.getEndValue("Series 1", "Task with null duration"); assertNull(millis); } /** * Some tests for the getPercentComplete() method. */ @Test public void testGetPercentComplete() { TaskSeriesCollection c = createCollection2(); assertEquals(0.10, c.getPercentComplete("S1", "Task 1")); assertEquals(0.20, c.getPercentComplete("S1", "Task 2")); assertEquals(0.30, c.getPercentComplete("S2", "Task 3")); assertEquals(0.10, c.getPercentComplete(0, 0)); assertEquals(0.20, c.getPercentComplete(0, 1)); assertEquals(null, c.getPercentComplete(0, 2)); assertEquals(null, c.getPercentComplete(1, 0)); assertEquals(null, c.getPercentComplete(1, 1)); assertEquals(0.30, c.getPercentComplete(1, 2)); // test collection 3, which doesn't define all tasks in all series TaskSeriesCollection c3 = createCollection3(); assertEquals(0.1, c3.getPercentComplete(0, 0)); assertEquals(0.2, c3.getPercentComplete(0, 1)); assertNull(c3.getPercentComplete(1, 0)); assertEquals(0.3, c3.getPercentComplete(1, 1)); assertEquals(0.111, c3.getPercentComplete(0, 0, 0)); assertEquals(0.222, c3.getPercentComplete(0, 1, 0)); assertEquals(0.333, c3.getPercentComplete(0, 1, 1)); assertEquals(0.444, c3.getPercentComplete(1, 1, 0)); assertEquals(0.555, c3.getPercentComplete(1, 1, 1)); assertEquals(0.666, c3.getPercentComplete(1, 1, 2)); } /** * A test for the getColumnCount() method. */ @Test public void testGetColumnCount() { TaskSeriesCollection c = createCollection1(); assertEquals(3, c.getColumnCount()); } /** * Some tests for the getColumnKey() method. */ @Test public void testGetColumnKey() { TaskSeriesCollection c = createCollection1(); assertEquals("Task 1", c.getColumnKey(0)); assertEquals("Task 2", c.getColumnKey(1)); assertEquals("Task 3", c.getColumnKey(2)); } /** * Some tests for the getColumnIndex() method. */ @Test public void testGetColumnIndex() { TaskSeriesCollection c = createCollection1(); assertEquals(0, c.getColumnIndex("Task 1")); assertEquals(1, c.getColumnIndex("Task 2")); assertEquals(2, c.getColumnIndex("Task 3")); } /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { TaskSeries s1 = new TaskSeries("S"); s1.add(new Task("T1", new Date(1), new Date(2))); s1.add(new Task("T2", new Date(11), new Date(22))); TaskSeries s2 = new TaskSeries("S"); s2.add(new Task("T1", new Date(1), new Date(2))); s2.add(new Task("T2", new Date(11), new Date(22))); TaskSeriesCollection c1 = new TaskSeriesCollection(); c1.add(s1); c1.add(s2); TaskSeries s1b = new TaskSeries("S"); s1b.add(new Task("T1", new Date(1), new Date(2))); s1b.add(new Task("T2", new Date(11), new Date(22))); TaskSeries s2b = new TaskSeries("S"); s2b.add(new Task("T1", new Date(1), new Date(2))); s2b.add(new Task("T2", new Date(11), new Date(22))); TaskSeriesCollection c2 = new TaskSeriesCollection(); c2.add(s1b); c2.add(s2b); assertEquals(c1, c2); assertEquals(c2, c1); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { TaskSeries s1 = new TaskSeries("S1"); s1.add(new Task("T1", new Date(1), new Date(2))); s1.add(new Task("T2", new Date(11), new Date(22))); TaskSeries s2 = new TaskSeries("S2"); s2.add(new Task("T1", new Date(33), new Date(44))); s2.add(new Task("T2", new Date(55), new Date(66))); TaskSeriesCollection c1 = new TaskSeriesCollection(); c1.add(s1); c1.add(s2); TaskSeriesCollection c2 = (TaskSeriesCollection) c1.clone(); assertNotSame(c1, c2); assertSame(c1.getClass(), c2.getClass()); assertEquals(c1, c2); // basic check for independence s1.add(new Task("T3", new Date(21), new Date(33))); assertFalse(c1.equals(c2)); TaskSeries series = c2.getSeries("S1"); series.add(new Task("T3", new Date(21), new Date(33))); assertEquals(c1, c2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { TaskSeries s1 = new TaskSeries("S"); s1.add(new Task("T1", new Date(1), new Date(2))); s1.add(new Task("T2", new Date(11), new Date(22))); TaskSeries s2 = new TaskSeries("S"); s2.add(new Task("T1", new Date(1), new Date(2))); s2.add(new Task("T2", new Date(11), new Date(22))); TaskSeriesCollection c1 = new TaskSeriesCollection(); c1.add(s1); c1.add(s2); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(c1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); TaskSeriesCollection c2 = (TaskSeriesCollection) in.readObject(); in.close(); assertEquals(c1, c2); } /** * A test for bug report 697153. */ @Test public void test697153() { TaskSeries s1 = new TaskSeries("S1"); s1.add(new Task("Task 1", new SimpleTimePeriod(new Date(), new Date()))); s1.add(new Task("Task 2", new SimpleTimePeriod(new Date(), new Date()))); s1.add(new Task("Task 3", new SimpleTimePeriod(new Date(), new Date()))); TaskSeries s2 = new TaskSeries("S2"); s2.add(new Task("Task 2", new SimpleTimePeriod(new Date(), new Date()))); s2.add(new Task("Task 3", new SimpleTimePeriod(new Date(), new Date()))); s2.add(new Task("Task 4", new SimpleTimePeriod(new Date(), new Date()))); TaskSeriesCollection tsc = new TaskSeriesCollection(); tsc.add(s1); tsc.add(s2); s1.removeAll(); int taskCount = tsc.getColumnCount(); assertEquals(3, taskCount); } /** * A test for bug report 800324. */ @Test public void test800324() { TaskSeries s1 = new TaskSeries("S1"); s1.add(new Task("Task 1", new SimpleTimePeriod(new Date(), new Date()))); s1.add(new Task("Task 2", new SimpleTimePeriod(new Date(), new Date()))); s1.add(new Task("Task 3", new SimpleTimePeriod(new Date(), new Date()))); TaskSeriesCollection tsc = new TaskSeriesCollection(); tsc.add(s1); // these methods should throw an IndexOutOfBoundsException since the // column is too high... try { /* Number start = */ tsc.getStartValue(0, 3); fail("Should have thrown an IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException e) { // expected } try { /* Number end = */ tsc.getEndValue(0, 3); fail("Should have thrown an IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException e) { // expected } try { /* int count = */ tsc.getSubIntervalCount(0, 3); fail("Should have thrown an IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException e) { // expected } } /** * Some tests for the bug report 1099331. We create a TaskSeriesCollection * with two series - the first series has two tasks, but the second has * only one. The key is to ensure that the methods in TaskSeriesCollection * translate the index values to key values *before* accessing the tasks * in the series. */ @Test public void testGetSubIntervalCount() { TaskSeriesCollection tsc = createCollection3(); assertEquals(1, tsc.getSubIntervalCount(0, 0)); assertEquals(2, tsc.getSubIntervalCount(0, 1)); assertEquals(0, tsc.getSubIntervalCount(1, 0)); assertEquals(3, tsc.getSubIntervalCount(1, 1)); } /** * Some basic tests for the getSeries() methods. */ @Test public void testGetSeries() { TaskSeries s1 = new TaskSeries("S1"); TaskSeries s2 = new TaskSeries("S2"); TaskSeriesCollection c = new TaskSeriesCollection(); c.add(s1); assertEquals(c.getSeries(0), s1); assertEquals(c.getSeries("S1"), s1); assertEquals(c.getSeries("XX"), null); c.add(s2); assertEquals(c.getSeries(1), s2); assertEquals(c.getSeries("S2"), s2); try { c.getSeries(null); fail("NullPointerException should have been thrown by passing null parameter"); } catch (NullPointerException e) { //expected } } /** * Some basic checks for the remove() method. */ @Test public void testRemove() { TaskSeriesCollection c = new TaskSeriesCollection(); TaskSeries s1 = new TaskSeries("S1"); c.add(s1); assertEquals("S1", c.getSeries(0).getKey()); c.remove(0); assertEquals(0, c.getSeriesCount()); c.add(s1); try { c.remove(-1); fail("Should have thrown an IllegalArgumentException on index out of bounds"); } catch (IllegalArgumentException e) { assertEquals("TaskSeriesCollection.remove(): index outside valid range.", e.getMessage()); } try { c.remove(1); fail("Should have thrown an IllegalArgumentException on index out of bounds"); } catch (IllegalArgumentException e) { assertEquals("TaskSeriesCollection.remove(): index outside valid range.", e.getMessage()); } } }
23,526
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
SlidingGanttCategoryDatasetTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/gantt/SlidingGanttCategoryDatasetTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------------------- * SlidingGanttCategoryDatasetTests.java * ------------------------------------- * (C) Copyright 2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 08-May-2008 : Version 1 (DG); * */ package org.jfree.data.gantt; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.Date; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; /** * Tests for the {@link SlidingGanttCategoryDataset} class. */ public class SlidingGanttCategoryDatasetTest { /** * Some checks for the equals() method. */ @Test public void testEquals() { TaskSeries s1 = new TaskSeries("Series"); s1.add(new Task("Task 1", new Date(0L), new Date(1L))); s1.add(new Task("Task 2", new Date(10L), new Date(11L))); s1.add(new Task("Task 3", new Date(20L), new Date(21L))); TaskSeriesCollection u1 = new TaskSeriesCollection(); u1.add(s1); SlidingGanttCategoryDataset d1 = new SlidingGanttCategoryDataset( u1, 0, 5); TaskSeries s2 = new TaskSeries("Series"); s2.add(new Task("Task 1", new Date(0L), new Date(1L))); s2.add(new Task("Task 2", new Date(10L), new Date(11L))); s2.add(new Task("Task 3", new Date(20L), new Date(21L))); TaskSeriesCollection u2 = new TaskSeriesCollection(); u2.add(s2); SlidingGanttCategoryDataset d2 = new SlidingGanttCategoryDataset( u2, 0, 5); assertEquals(d1, d2); d1.setFirstCategoryIndex(1); assertFalse(d1.equals(d2)); d2.setFirstCategoryIndex(1); assertEquals(d1, d2); d1.setMaximumCategoryCount(99); assertFalse(d1.equals(d2)); d2.setMaximumCategoryCount(99); assertEquals(d1, d2); s1.add(new Task("Task 2", new Date(10L), new Date(11L))); assertFalse(d1.equals(d2)); s2.add(new Task("Task 2", new Date(10L), new Date(11L))); assertEquals(d1, d2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { TaskSeries s1 = new TaskSeries("Series"); s1.add(new Task("Task 1", new Date(0L), new Date(1L))); TaskSeriesCollection u1 = new TaskSeriesCollection(); u1.add(s1); SlidingGanttCategoryDataset d1 = new SlidingGanttCategoryDataset( u1, 0, 5); SlidingGanttCategoryDataset d2 = (SlidingGanttCategoryDataset) d1.clone(); assertNotSame(d1, d2); assertSame(d1.getClass(), d2.getClass()); assertEquals(d1, d2); // basic check for independence s1.add(new Task("Task 2", new Date(10L), new Date(11L))); assertFalse(d1.equals(d2)); TaskSeriesCollection u2 = (TaskSeriesCollection) d2.getUnderlyingDataset(); TaskSeries s2 = u2.getSeries("Series"); s2.add(new Task("Task 2", new Date(10L), new Date(11L))); assertEquals(d1, d2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws ClassNotFoundException, IOException { TaskSeries s1 = new TaskSeries("Series"); s1.add(new Task("Task 1", new Date(0L), new Date(1L))); TaskSeriesCollection u1 = new TaskSeriesCollection(); u1.add(s1); SlidingGanttCategoryDataset d1 = new SlidingGanttCategoryDataset( u1, 0, 5); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); SlidingGanttCategoryDataset d2 = (SlidingGanttCategoryDataset) in.readObject(); in.close(); assertEquals(d1, d2); // basic check for independence s1.add(new Task("Task 2", new Date(10L), new Date(11L))); assertFalse(d1.equals(d2)); TaskSeriesCollection u2 = (TaskSeriesCollection) d2.getUnderlyingDataset(); TaskSeries s2 = u2.getSeries("Series"); s2.add(new Task("Task 2", new Date(10L), new Date(11L))); assertEquals(d1, d2); } }
6,004
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYTaskDatasetTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/gantt/XYTaskDatasetTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------------- * XYTaskDatasetTests.java * ----------------------- * (C) Copyright 2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 16-Sep-2008 : Version 1 (DG); * */ package org.jfree.data.gantt; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.Date; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; /** * Tests for the {@link XYTaskDataset} class. */ public class XYTaskDatasetTest { /** * Some checks for the equals() method. */ @Test public void testEquals() { TaskSeries s1 = new TaskSeries("Series"); s1.add(new Task("Task 1", new Date(0L), new Date(1L))); s1.add(new Task("Task 2", new Date(10L), new Date(11L))); s1.add(new Task("Task 3", new Date(20L), new Date(21L))); TaskSeriesCollection u1 = new TaskSeriesCollection(); u1.add(s1); XYTaskDataset d1 = new XYTaskDataset(u1); TaskSeries s2 = new TaskSeries("Series"); s2.add(new Task("Task 1", new Date(0L), new Date(1L))); s2.add(new Task("Task 2", new Date(10L), new Date(11L))); s2.add(new Task("Task 3", new Date(20L), new Date(21L))); TaskSeriesCollection u2 = new TaskSeriesCollection(); u2.add(s2); XYTaskDataset d2 = new XYTaskDataset(u2); assertEquals(d1, d2); d1.setSeriesWidth(0.123); assertFalse(d1.equals(d2)); d2.setSeriesWidth(0.123); assertEquals(d1, d2); d1.setTransposed(true); assertFalse(d1.equals(d2)); d2.setTransposed(true); assertEquals(d1, d2); s1.add(new Task("Task 2", new Date(10L), new Date(11L))); assertFalse(d1.equals(d2)); s2.add(new Task("Task 2", new Date(10L), new Date(11L))); assertEquals(d1, d2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { TaskSeries s1 = new TaskSeries("Series"); s1.add(new Task("Task 1", new Date(0L), new Date(1L))); TaskSeriesCollection u1 = new TaskSeriesCollection(); u1.add(s1); XYTaskDataset d1 = new XYTaskDataset(u1); XYTaskDataset d2 = (XYTaskDataset) d1.clone(); assertNotSame(d1, d2); assertSame(d1.getClass(), d2.getClass()); assertEquals(d1, d2); // basic check for independence s1.add(new Task("Task 2", new Date(10L), new Date(11L))); assertFalse(d1.equals(d2)); TaskSeriesCollection u2 = d2.getTasks(); TaskSeries s2 = u2.getSeries("Series"); s2.add(new Task("Task 2", new Date(10L), new Date(11L))); assertEquals(d1, d2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { TaskSeries s1 = new TaskSeries("Series"); s1.add(new Task("Task 1", new Date(0L), new Date(1L))); TaskSeriesCollection u1 = new TaskSeriesCollection(); u1.add(s1); XYTaskDataset d1 = new XYTaskDataset(u1); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(d1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); XYTaskDataset d2 = (XYTaskDataset) in.readObject(); in.close(); assertEquals(d1, d2); // basic check for independence s1.add(new Task("Task 2", new Date(10L), new Date(11L))); assertFalse(d1.equals(d2)); TaskSeriesCollection u2 = d2.getTasks(); TaskSeries s2 = u2.getSeries("Series"); s2.add(new Task("Task 2", new Date(10L), new Date(11L))); assertEquals(d1, d2); } }
5,550
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TaskTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/gantt/TaskTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------- * TaskTests.java * -------------- * (C) Copyright 2004-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 30-Jul-2004 : Version 1 (DG); * */ package org.jfree.data.gantt; import org.jfree.data.time.SimpleTimePeriod; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.Date; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; /** * Tests for the {@link Task} class. */ public class TaskTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { Task t1 = new Task("T", new Date(1), new Date(2)); Task t2 = new Task("T", new Date(1), new Date(2)); assertEquals(t1, t2); assertEquals(t2, t1); t1.setDescription("X"); assertFalse(t1.equals(t2)); t2.setDescription("X"); assertEquals(t1, t2); t1.setDuration(new SimpleTimePeriod(new Date(2), new Date(3))); assertFalse(t1.equals(t2)); t2.setDuration(new SimpleTimePeriod(new Date(2), new Date(3))); assertEquals(t1, t2); t1.setPercentComplete(0.5); assertFalse(t1.equals(t2)); t2.setPercentComplete(0.5); assertEquals(t1, t2); t1.addSubtask(new Task("T", new Date(22), new Date(33))); assertFalse(t1.equals(t2)); t2.addSubtask(new Task("T", new Date(22), new Date(33))); assertEquals(t1, t2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { Task t1 = new Task("T", new Date(1), new Date(2)); Task t2 = (Task) t1.clone(); assertNotSame(t1, t2); assertSame(t1.getClass(), t2.getClass()); assertEquals(t1, t2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { Task t1 = new Task("T", new Date(1), new Date(2)); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(t1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); Task t2 = (Task) in.readObject(); in.close(); assertEquals(t1, t2); } /** * Check the getSubTaskCount() method. */ @Test public void testGetSubTaskCount() { Task t1 = new Task("T", new Date(100), new Date(200)); assertEquals(0, t1.getSubtaskCount()); t1.addSubtask(new Task("S1", new Date(100), new Date(110))); assertEquals(1, t1.getSubtaskCount()); Task s2 = new Task("S2", new Date(111), new Date(120)); t1.addSubtask(s2); assertEquals(2, t1.getSubtaskCount()); t1.addSubtask(new Task("S3", new Date(121), new Date(130))); assertEquals(3, t1.getSubtaskCount()); t1.removeSubtask(s2); assertEquals(2, t1.getSubtaskCount()); } }
4,783
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TaskSeriesTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/data/gantt/TaskSeriesTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * TaskSeriesTests.java * -------------------- * (C) Copyright 2004-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 30-Jul-2004 : Version 1 (DG); * 09-May-2008 : Added independence check in testCloning() (DG); * */ package org.jfree.data.gantt; import org.junit.Test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.Date; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; /** * Tests for the {@link TaskSeries} class. */ public class TaskSeriesTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { TaskSeries s1 = new TaskSeries("S"); s1.add(new Task("T1", new Date(1), new Date(2))); s1.add(new Task("T2", new Date(11), new Date(22))); TaskSeries s2 = new TaskSeries("S"); s2.add(new Task("T1", new Date(1), new Date(2))); s2.add(new Task("T2", new Date(11), new Date(22))); assertEquals(s1, s2); assertEquals(s2, s1); s1.add(new Task("T3", new Date(22), new Date(33))); assertFalse(s1.equals(s2)); s2.add(new Task("T3", new Date(22), new Date(33))); assertEquals(s1, s2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { TaskSeries s1 = new TaskSeries("S"); s1.add(new Task("T1", new Date(1), new Date(2))); s1.add(new Task("T2", new Date(11), new Date(22))); TaskSeries s2 = (TaskSeries) s1.clone(); assertNotSame(s1, s2); assertSame(s1.getClass(), s2.getClass()); assertEquals(s1, s2); // basic check for independence s1.add(new Task("T3", new Date(22), new Date(33))); assertFalse(s1.equals(s2)); s2.add(new Task("T3", new Date(22), new Date(33))); assertEquals(s1, s2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { TaskSeries s1 = new TaskSeries("S"); s1.add(new Task("T1", new Date(1), new Date(2))); s1.add(new Task("T2", new Date(11), new Date(22))); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(s1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray()) ); TaskSeries s2 = (TaskSeries) in.readObject(); in.close(); assertEquals(s1, s2); } /** * Some checks for the getTask() method. */ @Test public void testGetTask() { TaskSeries s1 = new TaskSeries("S"); s1.add(new Task("T1", new Date(1), new Date(2))); s1.add(new Task("T2", new Date(11), new Date(22))); Task t1 = s1.get("T1"); assertEquals(t1, new Task("T1", new Date(1), new Date(2))); Task t2 = s1.get("T2"); assertEquals(t2, new Task("T2", new Date(11), new Date(22))); Task t3 = s1.get("T3"); assertNull(t3); } }
4,878
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
PieChartTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/PieChartTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------ * PieChartTests.java * ------------------ * (C) Copyright 2002-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 11-Jun-2002 : Version 1 (DG); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * */ package org.jfree.chart; import org.jfree.chart.event.ChartChangeEvent; import org.jfree.chart.event.ChartChangeListener; import org.jfree.chart.plot.PiePlot; import org.jfree.data.general.DefaultPieDataset; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; /** * Tests for a pie chart. * */ public class PieChartTest { /** A chart. */ private JFreeChart pieChart; /** * Common test setup. */ @Before public void setUp() { this.pieChart = createPieChart(); } /** * Using a regular pie chart, we replace the dataset with null. Expect to * receive notification of a chart change event, and (of course) the * dataset should be null. */ @Test public void testReplaceDatasetOnPieChart() { LocalListener l = new LocalListener(); this.pieChart.addChangeListener(l); PiePlot plot = (PiePlot) this.pieChart.getPlot(); plot.setDataset(null); assertEquals(true, l.flag); assertNull(plot.getDataset()); } /** * Creates a pie chart. * * @return The pie chart. */ private static JFreeChart createPieChart() { DefaultPieDataset data = new DefaultPieDataset(); data.setValue("Java", new Double(43.2)); data.setValue("Visual Basic", new Double(0.0)); data.setValue("C/C++", new Double(17.5)); return ChartFactory.createPieChart("Pie Chart", data); } /** * A chart change listener. * */ static class LocalListener implements ChartChangeListener { /** A flag. */ private boolean flag; /** * Event handler. * * @param event the event. */ @Override public void chartChanged(ChartChangeEvent event) { this.flag = true; } } }
3,499
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
PieChart3DTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/PieChart3DTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * PieChart3DTests.java * -------------------- * (C) Copyright 2004-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 21-May-2004 : Version 1 (DG); * */ package org.jfree.chart; import org.jfree.chart.event.ChartChangeEvent; import org.jfree.chart.event.ChartChangeListener; import org.jfree.chart.plot.PiePlot; import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.general.PieDataset; import org.junit.Before; import org.junit.Test; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; /** * Tests for a pie chart with a 3D effect. */ public class PieChart3DTest { /** A chart. */ private JFreeChart pieChart; /** * Common test setup. */ @Before public void setUp() { // create a dataset... DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("Java", new Double(43.2)); dataset.setValue("Visual Basic", new Double(0.0)); dataset.setValue("C/C++", new Double(17.5)); this.pieChart = createPieChart3D(dataset); } /** * Using a regular pie chart, we replace the dataset with null. Expect to * receive notification of a chart change event, and (of course) the * dataset should be null. */ @Test public void testReplaceDatasetOnPieChart() { LocalListener l = new LocalListener(); this.pieChart.addChangeListener(l); PiePlot plot = (PiePlot) this.pieChart.getPlot(); plot.setDataset(null); assertEquals(true, l.flag); assertNull(plot.getDataset()); } /** * Tests that no exceptions are thrown when there is a <code>null</code> * value in the dataset. */ @Test public void testNullValueInDataset() { DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("Section 1", 10.0); dataset.setValue("Section 2", 11.0); dataset.setValue("Section 3", null); JFreeChart chart = createPieChart3D(dataset); BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); //FIXME we should really assert a value here } /** * Creates a pie chart. * * @param dataset the dataset. * * @return The pie chart. */ private static JFreeChart createPieChart3D(PieDataset dataset) { return ChartFactory.createPieChart3D("Pie Chart", dataset); } /** * A chart change listener. */ static class LocalListener implements ChartChangeListener { /** A flag. */ private boolean flag; /** * Event handler. * * @param event the event. */ @Override public void chartChanged(ChartChangeEvent event) { this.flag = true; } } }
4,450
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYLineChartTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/XYLineChartTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------- * XYLineChartTests.java * --------------------- * (C) Copyright 2005-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 12-Apr-2005 : Version 1 (DG); * */ package org.jfree.chart; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.event.ChartChangeEvent; import org.jfree.chart.event.ChartChangeListener; import org.jfree.chart.labels.StandardXYToolTipGenerator; import org.jfree.chart.labels.XYToolTipGenerator; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.XYItemRenderer; import org.jfree.data.Range; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.junit.Before; import org.junit.Test; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Some tests for an XY line chart. */ public class XYLineChartTest { /** A chart. */ private JFreeChart chart; /** * Common test setup. */ @Before public void setUp() { this.chart = createChart(); } /** * Draws the chart with a null info object to make sure that no exceptions * are thrown (a problem that was occurring at one point). */ @Test public void testDrawWithNullInfo() { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); //FIXME we should really assert a value here } /** * Replaces the dataset and checks that it has changed as expected. */ @Test public void testReplaceDataset() { // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(10.0, 10.0); series1.add(20.0, 20.0); series1.add(30.0, 30.0); XYDataset dataset = new XYSeriesCollection(series1); LocalListener l = new LocalListener(); this.chart.addChangeListener(l); XYPlot plot = (XYPlot) this.chart.getPlot(); plot.setDataset(dataset); assertEquals(true, l.flag); ValueAxis axis = plot.getRangeAxis(); Range range = axis.getRange(); assertTrue("Expecting the lower bound of the range to be around 10: " + range.getLowerBound(), range.getLowerBound() <= 10); assertTrue("Expecting the upper bound of the range to be around 30: " + range.getUpperBound(), range.getUpperBound() >= 30); } /** * Check that setting a tool tip generator for a series does override the * default generator. */ @Test public void testSetSeriesToolTipGenerator() { XYPlot plot = (XYPlot) this.chart.getPlot(); XYItemRenderer renderer = plot.getRenderer(); StandardXYToolTipGenerator tt = new StandardXYToolTipGenerator(); renderer.setSeriesToolTipGenerator(0, tt); XYToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); assertSame(tt2, tt); } /** * Create a test chart. * * @return The chart. */ private static JFreeChart createChart() { XYSeries series1 = new XYSeries("Series 1"); series1.add(1.0, 1.0); series1.add(2.0, 2.0); series1.add(3.0, 3.0); XYDataset dataset = new XYSeriesCollection(series1); // create the chart... return ChartFactory.createXYLineChart("XY Line Chart", "Domain", "Range", dataset); } /** * A chart change listener. * */ static class LocalListener implements ChartChangeListener { /** A flag. */ private boolean flag; /** * Event handler. * * @param event the event. */ @Override public void chartChanged(ChartChangeEvent event) { this.flag = true; } } }
5,480
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
BarChartTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/BarChartTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------ * BarChartTests.java * ------------------ * (C) Copyright 2002-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 11-Jun-2002 : Version 1 (DG); * 25-Jun-2002 : Removed redundant code (DG); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 14-Jul-2003 : Renamed BarChartTests.java (DG); * */ package org.jfree.chart; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.event.ChartChangeEvent; import org.jfree.chart.event.ChartChangeListener; import org.jfree.chart.labels.CategoryToolTipGenerator; import org.jfree.chart.labels.StandardCategoryToolTipGenerator; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.renderer.category.CategoryItemRenderer; import org.jfree.chart.urls.CategoryURLGenerator; import org.jfree.chart.urls.StandardCategoryURLGenerator; import org.jfree.data.Range; import org.jfree.data.category.CategoryDataset; import org.jfree.data.general.DatasetUtilities; import org.junit.Before; import org.junit.Test; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for a bar chart. */ public class BarChartTest { /** A chart. */ private JFreeChart chart; /** * Common test setup. */ @Before public void setUp() { this.chart = createBarChart(); } /** * Draws the chart with a null info object to make sure that no exceptions * are thrown (a problem that was occurring at one point). */ @Test public void testDrawWithNullInfo() { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); //FIXME this should really assert a value } /** * Replaces the chart's dataset and then checks that the new dataset is OK. */ @Test public void testReplaceDataset() { // create a dataset... Number[][] data = new Integer[][] {{-30, -20}, {-10, 10}, {20, 30}}; CategoryDataset newData = DatasetUtilities.createCategoryDataset("S", "C", data); LocalListener l = new LocalListener(); this.chart.addChangeListener(l); CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); plot.setDataset(newData); assertEquals(true, l.flag); ValueAxis axis = plot.getRangeAxis(); Range range = axis.getRange(); assertTrue("Expecting the lower bound of the range to be around -30: " + range.getLowerBound(), range.getLowerBound() <= -30); assertTrue("Expecting the upper bound of the range to be around 30: " + range.getUpperBound(), range.getUpperBound() >= 30); } /** * Check that setting a tool tip generator for a series does override the * default generator. */ @Test public void testSetSeriesToolTipGenerator() { CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); StandardCategoryToolTipGenerator tt = new StandardCategoryToolTipGenerator(); renderer.setSeriesToolTipGenerator(0, tt); CategoryToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); assertSame(tt2, tt); } /** * Check that setting a URL generator for a series does override the * default generator. */ @Test public void testSetSeriesURLGenerator() { CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); StandardCategoryURLGenerator url1 = new StandardCategoryURLGenerator(); renderer.setSeriesItemURLGenerator(0, url1); CategoryURLGenerator url2 = renderer.getItemURLGenerator(0, 0); assertSame(url2, url1); } /** * Create a bar chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createBarChart() { Number[][] data = new Integer[][] {{-3, -2}, {-1, 1}, {2, 3}}; CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data); return ChartFactory.createBarChart("Bar Chart", "Domain", "Range", dataset); } /** * A chart change listener. */ static class LocalListener implements ChartChangeListener { /** A flag. */ private boolean flag; /** * Event handler. * * @param event the event. */ @Override public void chartChanged(ChartChangeEvent event) { this.flag = true; } } }
6,369
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYAreaChartTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/XYAreaChartTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------- * XYAreaChartTests.java * --------------------- * (C) Copyright 2005-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 12-Apr-2005 : Version 1 (DG); * */ package org.jfree.chart; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.event.ChartChangeEvent; import org.jfree.chart.event.ChartChangeListener; import org.jfree.chart.labels.StandardXYToolTipGenerator; import org.jfree.chart.labels.XYToolTipGenerator; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.XYItemRenderer; import org.jfree.data.Range; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.junit.Before; import org.junit.Test; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Some tests for an XY area chart. */ public class XYAreaChartTest { /** A chart. */ private JFreeChart chart; /** * Common test setup. */ @Before public void setUp() { this.chart = createChart(); } /** * Draws the chart with a null info object to make sure that no exceptions * are thrown (a problem that was occurring at one point). */ @Test public void testDrawWithNullInfo() { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); //FIXME we should really assert a value here } /** * Replaces the dataset and checks that it has changed as expected. */ @Test public void testReplaceDataset() { // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(10.0, 10.0); series1.add(20.0, 20.0); series1.add(30.0, 30.0); XYDataset dataset = new XYSeriesCollection(series1); LocalListener l = new LocalListener(); this.chart.addChangeListener(l); XYPlot plot = (XYPlot) this.chart.getPlot(); plot.setDataset(dataset); assertEquals(true, l.flag); ValueAxis axis = plot.getRangeAxis(); Range range = axis.getRange(); assertTrue("Expecting the lower bound of the range to be around 10: " + range.getLowerBound(), range.getLowerBound() <= 10); assertTrue("Expecting the upper bound of the range to be around 30: " + range.getUpperBound(), range.getUpperBound() >= 30); } /** * Check that setting a tool tip generator for a series does override the * default generator. */ @Test public void testSetSeriesToolTipGenerator() { XYPlot plot = (XYPlot) this.chart.getPlot(); XYItemRenderer renderer = plot.getRenderer(); StandardXYToolTipGenerator tt = new StandardXYToolTipGenerator(); renderer.setSeriesToolTipGenerator(0, tt); XYToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); assertSame(tt2, tt); } /** * Create a test chart. * * @return The chart. */ private static JFreeChart createChart() { XYSeries series1 = new XYSeries("Series 1"); series1.add(1.0, 1.0); series1.add(2.0, 2.0); series1.add(3.0, 3.0); XYDataset dataset = new XYSeriesCollection(series1); return ChartFactory.createXYAreaChart("Area Chart", "Domain", "Range", dataset); } /** * A chart change listener. * */ static class LocalListener implements ChartChangeListener { /** A flag. */ private boolean flag; /** * Event handler. * * @param event the event. */ @Override public void chartChanged(ChartChangeEvent event) { this.flag = true; } } }
5,443
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
BarChart3DTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/BarChart3DTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * BarChart3DTests.java * -------------------- * (C) Copyright 2002-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 11-Jun-2002 : Version 1 (DG); * 25-Jun-2002 : Removed redundant code (DG); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 14-Jul-2003 : Renamed BarChart3DTests.java (DG); * */ package org.jfree.chart; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.event.ChartChangeEvent; import org.jfree.chart.event.ChartChangeListener; import org.jfree.chart.labels.CategoryToolTipGenerator; import org.jfree.chart.labels.StandardCategoryToolTipGenerator; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.renderer.category.CategoryItemRenderer; import org.jfree.chart.urls.CategoryURLGenerator; import org.jfree.chart.urls.StandardCategoryURLGenerator; import org.jfree.data.Range; import org.jfree.data.category.CategoryDataset; import org.jfree.data.general.DatasetUtilities; import org.junit.Before; import org.junit.Test; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for a 3D bar chart. */ public class BarChart3DTest { /** The chart. */ private JFreeChart chart; /** * Common test setup. */ @Before public void setUp() { this.chart = createBarChart3D(); } /** * Draws the chart with a null info object to make sure that no exceptions * are thrown (a problem that was occurring at one point). */ @Test public void testDrawWithNullInfo() { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); //FIXME this should really assert a value } /** * Replaces the dataset and checks that the data range is as expected. */ @Test public void testReplaceDataset() { // create a dataset... Number[][] data = new Integer[][] {{-30, -20}, {-10, 10}, {20, 30}}; CategoryDataset newData = DatasetUtilities.createCategoryDataset("S", "C", data); LocalListener l = new LocalListener(); this.chart.addChangeListener(l); CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); plot.setDataset(newData); assertEquals(true, l.flag); ValueAxis axis = plot.getRangeAxis(); Range range = axis.getRange(); assertTrue("Expecting the lower bound of the range to be around -30: " + range.getLowerBound(), range.getLowerBound() <= -30); assertTrue("Expecting the upper bound of the range to be around 30: " + range.getUpperBound(), range.getUpperBound() >= 30); } /** * Check that setting a tool tip generator for a series does override the * default generator. */ @Test public void testSetSeriesToolTipGenerator() { CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); StandardCategoryToolTipGenerator tt = new StandardCategoryToolTipGenerator(); renderer.setSeriesToolTipGenerator(0, tt); CategoryToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); assertSame(tt2, tt); } /** * Check that setting a URL generator for a series does override the * default generator. */ @Test public void testSetSeriesURLGenerator() { CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); StandardCategoryURLGenerator url1 = new StandardCategoryURLGenerator(); renderer.setSeriesItemURLGenerator(0, url1); CategoryURLGenerator url2 = renderer.getItemURLGenerator(0, 0); assertSame(url2, url1); } /** * Create a bar chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createBarChart3D() { Number[][] data = new Integer[][] {{-3, -2}, {-1, 1}, {2, 3}}; CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data); return ChartFactory.createBarChart3D("Bar Chart 3D", "Domain", "Range", dataset); } /** * A chart change listener. * */ static class LocalListener implements ChartChangeListener { /** A flag. */ private boolean flag; /** * Event handler. * * @param event the event. */ @Override public void chartChanged(ChartChangeEvent event) { this.flag = true; } } }
6,388
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
package-info.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/package-info.java
/** * Test cases for the JFreeChart class library, based on the JUnit framework. */ package org.jfree.chart;
111
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
AreaChartTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/AreaChartTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------- * AreaChartTests.java * ------------------- * (C) Copyright 2005-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 12-Apr-2005 : Version 1 (DG); * */ package org.jfree.chart; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.event.ChartChangeEvent; import org.jfree.chart.event.ChartChangeListener; import org.jfree.chart.labels.CategoryToolTipGenerator; import org.jfree.chart.labels.StandardCategoryToolTipGenerator; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.renderer.category.CategoryItemRenderer; import org.jfree.chart.urls.CategoryURLGenerator; import org.jfree.chart.urls.StandardCategoryURLGenerator; import org.jfree.data.Range; import org.jfree.data.category.CategoryDataset; import org.jfree.data.general.DatasetUtilities; import org.junit.Before; import org.junit.Test; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for an area chart. */ public class AreaChartTest { /** A chart. */ private JFreeChart chart; /** * Common test setup. */ @Before public void setUp() { this.chart = createAreaChart(); } /** * Check that setting a tool tip generator for a series does override the * default generator. */ @Test public void testSetSeriesToolTipGenerator() { CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); StandardCategoryToolTipGenerator tt = new StandardCategoryToolTipGenerator(); renderer.setSeriesToolTipGenerator(0, tt); CategoryToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); assertSame(tt2, tt); } /** * Check that setting a URL generator for a series does override the * default generator. */ @Test public void testSetSeriesURLGenerator() { CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); StandardCategoryURLGenerator url1 = new StandardCategoryURLGenerator(); renderer.setSeriesItemURLGenerator(0, url1); CategoryURLGenerator url2 = renderer.getItemURLGenerator(0, 0); assertSame(url2, url1); } /** * Draws the chart with a null info object to make sure that no exceptions * are thrown (a problem that was occurring at one point). */ @Test public void testDrawWithNullInfo() { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); //FIXME this should really assert a return value } /** * Replaces the chart's dataset and then checks that the new dataset is OK. */ @Test public void testReplaceDataset() { Number[][] data = new Integer[][] {{-30, -20}, {-10, 10}, {20, 30}}; CategoryDataset newData = DatasetUtilities.createCategoryDataset( "S", "C", data); LocalListener l = new LocalListener(); this.chart.addChangeListener(l); CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); plot.setDataset(newData); assertEquals(true, l.flag); ValueAxis axis = plot.getRangeAxis(); Range range = axis.getRange(); assertTrue("Expecting the lower bound of the range to be around -30: " + range.getLowerBound(), range.getLowerBound() <= -30); assertTrue("Expecting the upper bound of the range to be around 30: " + range.getUpperBound(), range.getUpperBound() >= 30); } /** * Create an area chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createAreaChart() { Number[][] data = new Integer[][] {{-3, -2}, {-1, 1}, {2, 3}}; CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data); return ChartFactory.createAreaChart("Area Chart", "Domain", "Range", dataset); } /** * A chart change listener. */ static class LocalListener implements ChartChangeListener { /** A flag. */ private boolean flag; /** * Event handler. * * @param event the event. */ @Override public void chartChanged(ChartChangeEvent event) { this.flag = true; } } }
6,226
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYStepChartTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/XYStepChartTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------- * XYStepChartTests.java * --------------------- * (C) Copyright 2005-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 12-Apr-2005 : Version 1 (DG); * */ package org.jfree.chart; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.event.ChartChangeEvent; import org.jfree.chart.event.ChartChangeListener; import org.jfree.chart.labels.StandardXYToolTipGenerator; import org.jfree.chart.labels.XYToolTipGenerator; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.XYItemRenderer; import org.jfree.data.Range; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.junit.Before; import org.junit.Test; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Some tests for an XY step plot. */ public class XYStepChartTest { /** A chart. */ private JFreeChart chart; /** * Common test setup. */ @Before public void setUp() { this.chart = createChart(); } /** * Draws the chart with a null info object to make sure that no exceptions * are thrown (a problem that was occurring at one point). */ @Test public void testDrawWithNullInfo() { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); //FIXME we should really assert a value here } /** * Replaces the dataset and checks that it has changed as expected. */ @Test public void testReplaceDataset() { // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(10.0, 10.0); series1.add(20.0, 20.0); series1.add(30.0, 30.0); XYDataset dataset = new XYSeriesCollection(series1); LocalListener l = new LocalListener(); this.chart.addChangeListener(l); XYPlot plot = (XYPlot) this.chart.getPlot(); plot.setDataset(dataset); assertEquals(true, l.flag); ValueAxis axis = plot.getRangeAxis(); Range range = axis.getRange(); assertTrue("Expecting the lower bound of the range to be around 10: " + range.getLowerBound(), range.getLowerBound() <= 10); assertTrue("Expecting the upper bound of the range to be around 30: " + range.getUpperBound(), range.getUpperBound() >= 30); } /** * Check that setting a tool tip generator for a series does override the * default generator. */ @Test public void testSetSeriesToolTipGenerator() { XYPlot plot = (XYPlot) this.chart.getPlot(); XYItemRenderer renderer = plot.getRenderer(); StandardXYToolTipGenerator tt = new StandardXYToolTipGenerator(); renderer.setSeriesToolTipGenerator(0, tt); XYToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); assertSame(tt2, tt); } /** * Create a test chart. * * @return The chart. */ private static JFreeChart createChart() { XYSeries series1 = new XYSeries("Series 1"); series1.add(1.0, 1.0); series1.add(2.0, 2.0); series1.add(3.0, 3.0); XYDataset dataset = new XYSeriesCollection(series1); return ChartFactory.createXYStepChart("Step Chart", "Domain", "Range", dataset); } /** * A chart change listener. * */ static class LocalListener implements ChartChangeListener { /** A flag. */ private boolean flag; /** * Event handler. * * @param event the event. */ @Override public void chartChanged(ChartChangeEvent event) { this.flag = true; } } }
5,444
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
LineChart3DTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/LineChart3DTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------- * LineChart3DTests.java * --------------------- * (C) Copyright 2005-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 12-Apr-2005 : Version 1 (DG); * */ package org.jfree.chart; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.event.ChartChangeEvent; import org.jfree.chart.event.ChartChangeListener; import org.jfree.chart.labels.CategoryToolTipGenerator; import org.jfree.chart.labels.StandardCategoryToolTipGenerator; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.renderer.category.CategoryItemRenderer; import org.jfree.chart.urls.CategoryURLGenerator; import org.jfree.chart.urls.StandardCategoryURLGenerator; import org.jfree.data.Range; import org.jfree.data.category.CategoryDataset; import org.jfree.data.general.DatasetUtilities; import org.junit.Before; import org.junit.Test; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Some tests for a line chart with a 3D effect. */ public class LineChart3DTest { /** A chart. */ private JFreeChart chart; /** * Common test setup. */ @Before public void setUp() { this.chart = createLineChart3D(); } /** * Draws the chart with a null info object to make sure that no exceptions * are thrown (a problem that was occurring at one point). */ @Test public void testDrawWithNullInfo() { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); //FIXME we should really assert a value here } /** * Replaces the chart's dataset and then checks that the new dataset is OK. */ @Test public void testReplaceDataset() { // create a dataset... Number[][] data = new Integer[][] {{-30, -20}, {-10, 10}, {20, 30}}; CategoryDataset newData = DatasetUtilities.createCategoryDataset("S", "C", data); LocalListener l = new LocalListener(); this.chart.addChangeListener(l); CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); plot.setDataset(newData); assertEquals(true, l.flag); ValueAxis axis = plot.getRangeAxis(); Range range = axis.getRange(); assertTrue("Expecting the lower bound of the range to be around -30: " + range.getLowerBound(), range.getLowerBound() <= -30); assertTrue("Expecting the upper bound of the range to be around 30: " + range.getUpperBound(), range.getUpperBound() >= 30); } /** * Check that setting a tool tip generator for a series does override the * default generator. */ @Test public void testSetSeriesToolTipGenerator() { CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); StandardCategoryToolTipGenerator tt = new StandardCategoryToolTipGenerator(); renderer.setSeriesToolTipGenerator(0, tt); CategoryToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); assertSame(tt2, tt); } /** * Check that setting a URL generator for a series does override the * default generator. */ @Test public void testSetSeriesURLGenerator() { CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); StandardCategoryURLGenerator url1 = new StandardCategoryURLGenerator(); renderer.setSeriesItemURLGenerator(0, url1); CategoryURLGenerator url2 = renderer.getItemURLGenerator(0, 0); assertSame(url2, url1); } /** * Create a line chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createLineChart3D() { Number[][] data = new Integer[][] {{-3, -2}, {-1, 1}, {2, 3}}; CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data); return ChartFactory.createLineChart3D("Line Chart", "Domain", "Range", dataset); } /** * A chart change listener. * */ static class LocalListener implements ChartChangeListener { /** A flag. */ private boolean flag; /** * Event handler. * * @param event the event. */ @Override public void chartChanged(ChartChangeEvent event) { this.flag = true; } } }
6,267
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
LineChartTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/LineChartTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------- * LineChartTests.java * ------------------- * (C) Copyright 2005-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 12-Apr-2005 : Version 1 (DG); * */ package org.jfree.chart; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.event.ChartChangeEvent; import org.jfree.chart.event.ChartChangeListener; import org.jfree.chart.labels.CategoryToolTipGenerator; import org.jfree.chart.labels.StandardCategoryToolTipGenerator; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.renderer.category.CategoryItemRenderer; import org.jfree.chart.urls.CategoryURLGenerator; import org.jfree.chart.urls.StandardCategoryURLGenerator; import org.jfree.data.Range; import org.jfree.data.category.CategoryDataset; import org.jfree.data.general.DatasetUtilities; import org.junit.Before; import org.junit.Test; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Some tests for a line chart. */ public class LineChartTest { /** A chart. */ private JFreeChart chart; /** * Common test setup. */ @Before public void setUp() { this.chart = createLineChart(); } /** * Draws the chart with a null info object to make sure that no exceptions * are thrown (a problem that was occurring at one point). */ @Test public void testDrawWithNullInfo() { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); //FIXME we should really assert a value here } /** * Replaces the chart's dataset and then checks that the new dataset is OK. */ @Test public void testReplaceDataset() { // create a dataset... Number[][] data = new Integer[][] {{-30, -20}, {-10, 10}, {20, 30}}; CategoryDataset newData = DatasetUtilities.createCategoryDataset("S", "C", data); LocalListener l = new LocalListener(); this.chart.addChangeListener(l); CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); plot.setDataset(newData); assertEquals(true, l.flag); ValueAxis axis = plot.getRangeAxis(); Range range = axis.getRange(); assertTrue("Expecting the lower bound of the range to be around -30: " + range.getLowerBound(), range.getLowerBound() <= -30); assertTrue("Expecting the upper bound of the range to be around 30: " + range.getUpperBound(), range.getUpperBound() >= 30); } /** * Check that setting a tool tip generator for a series does override the * default generator. */ @Test public void testSetSeriesToolTipGenerator() { CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); StandardCategoryToolTipGenerator tt = new StandardCategoryToolTipGenerator(); renderer.setSeriesToolTipGenerator(0, tt); CategoryToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); assertSame(tt2, tt); } /** * Check that setting a URL generator for a series does override the * default generator. */ @Test public void testSetSeriesURLGenerator() { CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); StandardCategoryURLGenerator url1 = new StandardCategoryURLGenerator(); renderer.setSeriesItemURLGenerator(0, url1); CategoryURLGenerator url2 = renderer.getItemURLGenerator(0, 0); assertSame(url2, url1); } /** * Create a line chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createLineChart() { Number[][] data = new Integer[][] {{-3, -2}, {-1, 1}, {2, 3}}; CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data); return ChartFactory.createLineChart("Line Chart", "Domain", "Range", dataset); } /** * A chart change listener. * */ static class LocalListener implements ChartChangeListener { /** A flag. */ private boolean flag; /** * Event handler. * * @param event the event. */ @Override public void chartChanged(ChartChangeEvent event) { this.flag = true; } } }
6,239
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TimeSeriesChartTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/TimeSeriesChartTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------- * TimeSeriesChartTests.java * ------------------------- * (C) Copyright 2005-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 12-Apr-2005 : Version 1 (DG); * */ package org.jfree.chart; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.event.ChartChangeEvent; import org.jfree.chart.event.ChartChangeListener; import org.jfree.chart.labels.StandardXYToolTipGenerator; import org.jfree.chart.labels.XYToolTipGenerator; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.XYItemRenderer; import org.jfree.data.Range; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.junit.Before; import org.junit.Test; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Some tests for a time series chart. */ public class TimeSeriesChartTest { /** A chart. */ private JFreeChart chart; /** * Common test setup. */ @Before public void setUp() { this.chart = createChart(); } /** * Draws the chart with a null info object to make sure that no exceptions * are thrown (a problem that was occurring at one point). */ @Test public void testDrawWithNullInfo() { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); //FIXME we should really assert a value here } /** * Replaces the dataset and checks that it has changed as expected. */ @Test public void testReplaceDataset() { // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(10.0, 10.0); series1.add(20.0, 20.0); series1.add(30.0, 30.0); XYDataset dataset = new XYSeriesCollection(series1); LocalListener l = new LocalListener(); this.chart.addChangeListener(l); XYPlot plot = (XYPlot) this.chart.getPlot(); plot.setDataset(dataset); assertEquals(true, l.flag); ValueAxis axis = plot.getRangeAxis(); Range range = axis.getRange(); assertTrue("Expecting the lower bound of the range to be around 10: " + range.getLowerBound(), range.getLowerBound() <= 10); assertTrue("Expecting the upper bound of the range to be around 30: " + range.getUpperBound(), range.getUpperBound() >= 30); } /** * Check that setting a tool tip generator for a series does override the * default generator. */ @Test public void testSetSeriesToolTipGenerator() { XYPlot plot = (XYPlot) this.chart.getPlot(); XYItemRenderer renderer = plot.getRenderer(); StandardXYToolTipGenerator tt = new StandardXYToolTipGenerator(); renderer.setSeriesToolTipGenerator(0, tt); XYToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); assertSame(tt2, tt); } /** * Create a test chart. * * @return The chart. */ private static JFreeChart createChart() { XYSeries series1 = new XYSeries("Series 1"); series1.add(1.0, 1.0); series1.add(2.0, 2.0); series1.add(3.0, 3.0); XYDataset dataset = new XYSeriesCollection(series1); return ChartFactory.createTimeSeriesChart("XY Line Chart", "Domain", "Range", dataset); } /** * A chart change listener. * */ static class LocalListener implements ChartChangeListener { /** A flag. */ private boolean flag; /** * Event handler. * * @param event the event. */ @Override public void chartChanged(ChartChangeEvent event) { this.flag = true; } } }
5,470
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
StackedBarChart3DTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/StackedBarChart3DTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------------- * StackedBarChart3DTests.java * --------------------------- * (C) Copyright 2005-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 12-Apr-2005 : Version 1 (DG); * */ package org.jfree.chart; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.event.ChartChangeEvent; import org.jfree.chart.event.ChartChangeListener; import org.jfree.chart.labels.CategoryToolTipGenerator; import org.jfree.chart.labels.StandardCategoryToolTipGenerator; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.renderer.category.CategoryItemRenderer; import org.jfree.chart.urls.CategoryURLGenerator; import org.jfree.chart.urls.StandardCategoryURLGenerator; import org.jfree.data.Range; import org.jfree.data.category.CategoryDataset; import org.jfree.data.general.DatasetUtilities; import org.junit.Before; import org.junit.Test; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Some tests for a stacked bar chart with 3D effect. */ public class StackedBarChart3DTest { /** A chart. */ private JFreeChart chart; /** * Common test setup. */ @Before public void setUp() { this.chart = createChart(); } /** * Draws the chart with a null info object to make sure that no exceptions * are thrown (a problem that was occurring at one point). */ @Test public void testDrawWithNullInfo() { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); //FIXME we should really assert a value here } /** * Replaces the dataset and checks that it has changed as expected. */ @Test public void testReplaceDataset() { // create a dataset... Number[][] data = new Integer[][] {{-30, -20}, {-10, 10}, {20, 30}}; CategoryDataset newData = DatasetUtilities.createCategoryDataset("S", "C", data); LocalListener l = new LocalListener(); this.chart.addChangeListener(l); CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); plot.setDataset(newData); assertEquals(true, l.flag); ValueAxis axis = plot.getRangeAxis(); Range range = axis.getRange(); assertTrue("Expecting the lower bound of the range to be around -30: " + range.getLowerBound(), range.getLowerBound() <= -30); assertTrue("Expecting the upper bound of the range to be around 30: " + range.getUpperBound(), range.getUpperBound() >= 30); } /** * Check that setting a tool tip generator for a series does override the * default generator. */ @Test public void testSetSeriesToolTipGenerator() { CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); StandardCategoryToolTipGenerator tt = new StandardCategoryToolTipGenerator(); renderer.setSeriesToolTipGenerator(0, tt); CategoryToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); assertSame(tt2, tt); } /** * Check that setting a URL generator for a series does override the * default generator. */ @Test public void testSetSeriesURLGenerator() { CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); StandardCategoryURLGenerator url1 = new StandardCategoryURLGenerator(); renderer.setSeriesItemURLGenerator(0, url1); CategoryURLGenerator url2 = renderer.getItemURLGenerator(0, 0); assertSame(url2, url1); } /** * Create a stacked bar chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createChart() { Number[][] data = new Integer[][] {{-3, -2}, {-1, 1}, {2, 3}}; CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data); return ChartFactory.createStackedBarChart3D("Stacked Bar Chart 3D", "Domain", "Range", dataset); } /** * A chart change listener. */ static class LocalListener implements ChartChangeListener { /** A flag. */ private boolean flag; /** * Event handler. * * @param event the event. */ @Override public void chartChanged(ChartChangeEvent event) { this.flag = true; } } }
6,298
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
TestUtilities.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/TestUtilities.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2013, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------ * TestUtilities.java * ------------------ * (C) Copyright 2007-2013, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 08-Jun-2007 : Version 1 (DG); * */ package org.jfree.chart; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.util.Collection; import java.util.Iterator; /** * Some utility methods for use by the testing code. */ public class TestUtilities { /** * Returns <code>true</code> if the collections contains any object that * is an instance of the specified class, and <code>false</code> otherwise. * * @param collection the collection. * @param c the class. * * @return A boolean. */ public static boolean containsInstanceOf(Collection collection, Class c) { Iterator iterator = collection.iterator(); while (iterator.hasNext()) { Object obj = iterator.next(); if (obj != null && obj.getClass().equals(c)) { return true; } } return false; } /** * Returns an object that is the deserialised form of the supplied object. * The original object is serialised to a byte array then deserialised * and returned. * * @param original the original object (<code>null</code> not permitted). * * @return A serialised and deserialised object. */ public static Object serialised(Object original) { Object result = null; ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out; try { out = new ObjectOutputStream(buffer); out.writeObject(original); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); result = in.readObject(); in.close(); } catch (IOException e) { throw new RuntimeException(e); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } return result; } }
3,579
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
ChartRenderingInfoTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/ChartRenderingInfoTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------------- * ChartRenderingInfoTests.java * ---------------------------- * (C) Copyright 2004-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 19-Mar-2004 : Version 1 (DG); * 30-Nov-2005 : Updated for removed field in ChartRenderingInfo (DG); * */ package org.jfree.chart; import org.jfree.chart.entity.ChartEntity; import org.jfree.chart.entity.StandardEntityCollection; import org.junit.Test; import java.awt.Rectangle; import java.awt.geom.Rectangle2D; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; /** * Tests for the {@link ChartRenderingInfo} class. */ public class ChartRenderingInfoTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { ChartRenderingInfo i1 = new ChartRenderingInfo(); ChartRenderingInfo i2 = new ChartRenderingInfo(); assertEquals(i1, i2); i1.setChartArea(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0)); assertFalse(i1.equals(i2)); i2.setChartArea(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0)); assertEquals(i1, i2); i1.getPlotInfo().setDataArea(new Rectangle(1, 2, 3, 4)); assertFalse(i1.equals(i2)); i2.getPlotInfo().setDataArea(new Rectangle(1, 2, 3, 4)); assertEquals(i1, i2); StandardEntityCollection e1 = new StandardEntityCollection(); e1.add(new ChartEntity(new Rectangle(1, 2, 3, 4))); i1.setEntityCollection(e1); assertFalse(i1.equals(i2)); StandardEntityCollection e2 = new StandardEntityCollection(); e2.add(new ChartEntity(new Rectangle(1, 2, 3, 4))); i2.setEntityCollection(e2); } /** * Confirm that cloning works. */ @Test public void testCloning() throws CloneNotSupportedException { ChartRenderingInfo i1 = new ChartRenderingInfo(); ChartRenderingInfo i2 = (ChartRenderingInfo) i1.clone(); assertNotSame(i1, i2); assertSame(i1.getClass(), i2.getClass()); assertEquals(i1, i2); // check independence i1.getChartArea().setRect(4.0, 3.0, 2.0, 1.0); assertFalse(i1.equals(i2)); i2.getChartArea().setRect(4.0, 3.0, 2.0, 1.0); assertEquals(i1, i2); i1.getEntityCollection().add(new ChartEntity(new Rectangle(1, 2, 2, 1))); assertFalse(i1.equals(i2)); i2.getEntityCollection().add(new ChartEntity(new Rectangle(1, 2, 2, 1))); assertEquals(i1, i2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { ChartRenderingInfo i1 = new ChartRenderingInfo(); i1.setChartArea(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0)); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(i1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); ChartRenderingInfo i2 = (ChartRenderingInfo) in.readObject(); in.close(); assertEquals(i1, i2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization2() throws IOException, ClassNotFoundException { ChartRenderingInfo i1 = new ChartRenderingInfo(); i1.getPlotInfo().setDataArea(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0)); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(i1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); ChartRenderingInfo i2 = (ChartRenderingInfo) in.readObject(); in.close(); assertEquals(i1, i2); assertEquals(i2, i2.getPlotInfo().getOwner()); } }
5,773
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
StandardChartThemeTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/StandardChartThemeTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ---------------------------- * StandardChartThemeTests.java * ---------------------------- * (C) Copyright 2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 14-Aug-2008 : Version 1 (DG); * */ package org.jfree.chart; import org.jfree.chart.plot.DefaultDrawingSupplier; import org.jfree.chart.plot.PieLabelLinkStyle; import org.jfree.chart.renderer.category.StandardBarPainter; import org.jfree.chart.renderer.xy.StandardXYBarPainter; import org.jfree.chart.ui.RectangleInsets; import org.junit.Test; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.GradientPaint; import java.awt.Paint; import java.awt.Shape; import java.awt.Stroke; import java.awt.geom.Rectangle2D; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; /** * Tests for the {@link StandardChartTheme} class. */ public class StandardChartThemeTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { StandardChartTheme t1 = new StandardChartTheme("Name"); StandardChartTheme t2 = new StandardChartTheme("Name"); assertEquals(t1, t2); // name t1 = new StandardChartTheme("t1"); assertFalse(t1.equals(t2)); t2 = new StandardChartTheme("t1"); assertEquals(t1, t2); //extraLargeFont t1.setExtraLargeFont(new Font("Dialog", Font.PLAIN, 21)); assertFalse(t1.equals(t2)); t2.setExtraLargeFont(new Font("Dialog", Font.PLAIN, 21)); assertEquals(t1, t2); //largeFont t1.setLargeFont(new Font("Dialog", Font.PLAIN, 19)); assertFalse(t1.equals(t2)); t2.setLargeFont(new Font("Dialog", Font.PLAIN, 19)); assertEquals(t1, t2); //regularFont; t1.setRegularFont(new Font("Dialog", Font.PLAIN, 17)); assertFalse(t1.equals(t2)); t2.setRegularFont(new Font("Dialog", Font.PLAIN, 17)); assertEquals(t1, t2); //titlePaint; t1.setTitlePaint(new GradientPaint(0f, 1f, Color.RED, 2f, 3f, Color.BLUE)); assertFalse(t1.equals(t2)); t2.setTitlePaint(new GradientPaint(0f, 1f, Color.RED, 2f, 3f, Color.BLUE)); assertEquals(t1, t2); //subtitlePaint; t1.setSubtitlePaint(new GradientPaint(1f, 2f, Color.RED, 3f, 4f, Color.BLUE)); assertFalse(t1.equals(t2)); t2.setSubtitlePaint(new GradientPaint(1f, 2f, Color.RED, 3f, 4f, Color.BLUE)); assertEquals(t1, t2); //chartBackgroundPaint; t1.setChartBackgroundPaint(new GradientPaint(2f, 3f, Color.BLUE, 4f, 5f, Color.RED)); assertFalse(t1.equals(t2)); t2.setChartBackgroundPaint(new GradientPaint(2f, 3f, Color.BLUE, 4f, 5f, Color.RED)); assertEquals(t1, t2); //legendBackgroundPaint; t1.setLegendBackgroundPaint(new GradientPaint(3f, 4f, Color.gray, 1f, 2f, Color.RED)); assertFalse(t1.equals(t2)); t2.setLegendBackgroundPaint(new GradientPaint(3f, 4f, Color.gray, 1f, 2f, Color.RED)); assertEquals(t1, t2); //legendItemPaint; t1.setLegendItemPaint(new GradientPaint(9f, 8f, Color.RED, 7f, 6f, Color.BLUE)); assertFalse(t1.equals(t2)); t2.setLegendItemPaint(new GradientPaint(9f, 8f, Color.RED, 7f, 6f, Color.BLUE)); assertEquals(t1, t2); //drawingSupplier; t1.setDrawingSupplier(new DefaultDrawingSupplier( new Paint[] {Color.RED}, new Paint[] {Color.BLUE}, new Stroke[] {new BasicStroke(1.0f)}, new Stroke[] {new BasicStroke(1.0f)}, new Shape[] {new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0)})); assertFalse(t1.equals(t2)); t2.setDrawingSupplier(new DefaultDrawingSupplier( new Paint[] {Color.RED}, new Paint[] {Color.BLUE}, new Stroke[] {new BasicStroke(1.0f)}, new Stroke[] {new BasicStroke(1.0f)}, new Shape[] {new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0)})); assertEquals(t1, t2); //plotBackgroundPaint; t1.setPlotBackgroundPaint(new GradientPaint(4f, 3f, Color.RED, 6f, 7f, Color.BLUE)); assertFalse(t1.equals(t2)); t2.setPlotBackgroundPaint(new GradientPaint(4f, 3f, Color.RED, 6f, 7f, Color.BLUE)); assertEquals(t1, t2); //plotOutlinePaint; t1.setPlotOutlinePaint(new GradientPaint(5f, 2f, Color.BLUE, 6f, 7f, Color.RED)); assertFalse(t1.equals(t2)); t2.setPlotOutlinePaint(new GradientPaint(5f, 2f, Color.BLUE, 6f, 7f, Color.RED)); assertEquals(t1, t2); //labelLinkStyle; t1.setLabelLinkStyle(PieLabelLinkStyle.STANDARD); assertFalse(t1.equals(t2)); t2.setLabelLinkStyle(PieLabelLinkStyle.STANDARD); assertEquals(t1, t2); //labelLinkPaint; t1.setLabelLinkPaint(new GradientPaint(4f, 3f, Color.RED, 2f, 9f, Color.BLUE)); assertFalse(t1.equals(t2)); t2.setLabelLinkPaint(new GradientPaint(4f, 3f, Color.RED, 2f, 9f, Color.BLUE)); assertEquals(t1, t2); //domainGridlinePaint; t1.setDomainGridlinePaint(Color.BLUE); assertFalse(t1.equals(t2)); t2.setDomainGridlinePaint(Color.BLUE); assertEquals(t1, t2); //rangeGridlinePaint; t1.setRangeGridlinePaint(Color.RED); assertFalse(t1.equals(t2)); t2.setRangeGridlinePaint(Color.RED); assertEquals(t1, t2); //axisOffset; t1.setAxisOffset(new RectangleInsets(1, 2, 3, 4)); assertFalse(t1.equals(t2)); t2.setAxisOffset(new RectangleInsets(1, 2, 3, 4)); assertEquals(t1, t2); //axisLabelPaint; t1.setAxisLabelPaint(new GradientPaint(8f, 4f, Color.gray, 2f, 9f, Color.BLUE)); assertFalse(t1.equals(t2)); t2.setAxisLabelPaint(new GradientPaint(8f, 4f, Color.gray, 2f, 9f, Color.BLUE)); assertEquals(t1, t2); //tickLabelPaint; t1.setTickLabelPaint(new GradientPaint(3f, 4f, Color.RED, 5f, 6f, Color.yellow)); assertFalse(t1.equals(t2)); t2.setTickLabelPaint(new GradientPaint(3f, 4f, Color.RED, 5f, 6f, Color.yellow)); assertEquals(t1, t2); //itemLabelPaint; t1.setItemLabelPaint(new GradientPaint(2f, 5f, Color.gray, 1f, 2f, Color.BLUE)); assertFalse(t1.equals(t2)); t2.setItemLabelPaint(new GradientPaint(2f, 5f, Color.gray, 1f, 2f, Color.BLUE)); assertEquals(t1, t2); //shadowVisible; t1.setShadowVisible(!t1.isShadowVisible()); assertFalse(t1.equals(t2)); t2.setShadowVisible(t1.isShadowVisible()); assertEquals(t1, t2); //shadowPaint; t1.setShadowPaint(new GradientPaint(7f, 1f, Color.BLUE, 4f, 6f, Color.RED)); assertFalse(t1.equals(t2)); t2.setShadowPaint(new GradientPaint(7f, 1f, Color.BLUE, 4f, 6f, Color.RED)); assertEquals(t1, t2); //barPainter; t1.setBarPainter(new StandardBarPainter()); assertFalse(t1.equals(t2)); t2.setBarPainter(new StandardBarPainter()); assertEquals(t1, t2); //xyBarPainter; t1.setXYBarPainter(new StandardXYBarPainter()); assertFalse(t1.equals(t2)); t2.setXYBarPainter(new StandardXYBarPainter()); assertEquals(t1, t2); //thermometerPaint; t1.setThermometerPaint(new GradientPaint(9f, 7f, Color.RED, 5f, 1f, Color.BLUE)); assertFalse(t1.equals(t2)); t2.setThermometerPaint(new GradientPaint(9f, 7f, Color.RED, 5f, 1f, Color.BLUE)); assertEquals(t1, t2); //wallPaint; t1.setWallPaint(new GradientPaint(4f, 5f, Color.RED, 1f, 0f, Color.gray)); assertFalse(t1.equals(t2)); t2.setWallPaint(new GradientPaint(4f, 5f, Color.RED, 1f, 0f, Color.gray)); assertEquals(t1, t2); //errorIndicatorPaint; t1.setErrorIndicatorPaint(new GradientPaint(0f, 1f, Color.WHITE, 2f, 3f, Color.BLUE)); assertFalse(t1.equals(t2)); t2.setErrorIndicatorPaint(new GradientPaint(0f, 1f, Color.WHITE, 2f, 3f, Color.BLUE)); assertEquals(t1, t2); //gridBandPaint t1.setGridBandPaint(new GradientPaint(1f, 2f, Color.WHITE, 4f, 8f, Color.RED)); assertFalse(t1.equals(t2)); t2.setGridBandPaint(new GradientPaint(1f, 2f, Color.WHITE, 4f, 8f, Color.RED)); assertEquals(t1, t2); //gridBandAlternatePaint t1.setGridBandAlternatePaint(new GradientPaint(1f, 4f, Color.green, 1f, 2f, Color.RED)); assertFalse(t1.equals(t2)); t2.setGridBandAlternatePaint(new GradientPaint(1f, 4f, Color.green, 1f, 2f, Color.RED)); assertEquals(t1, t2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { StandardChartTheme t1 = new StandardChartTheme("Name"); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(t1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); StandardChartTheme t2 = (StandardChartTheme) in.readObject(); in.close(); assertEquals(t1, t2); } /** * Basic checks for cloning. */ @Test public void testCloning() throws CloneNotSupportedException { StandardChartTheme t1 = new StandardChartTheme("Name"); StandardChartTheme t2 = (StandardChartTheme) t1.clone(); assertNotSame(t1, t2); assertSame(t1.getClass(), t2.getClass()); assertEquals(t1, t2); } }
11,497
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYBarChartTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/XYBarChartTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * XYBarChartTests.java * -------------------- * (C) Copyright 2005-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 12-Apr-2005 : Version 1 (DG); * */ package org.jfree.chart; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.event.ChartChangeEvent; import org.jfree.chart.event.ChartChangeListener; import org.jfree.chart.labels.StandardXYToolTipGenerator; import org.jfree.chart.labels.XYToolTipGenerator; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.XYItemRenderer; import org.jfree.data.Range; import org.jfree.data.xy.IntervalXYDataset; import org.jfree.data.xy.XYBarDataset; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.junit.Before; import org.junit.Test; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Some tests for an XY bar chart. */ public class XYBarChartTest { /** A chart. */ private JFreeChart chart; /** * Common test setup. */ @Before public void setUp() { this.chart = createChart(); } /** * Draws the chart with a null info object to make sure that no exceptions * are thrown (a problem that was occurring at one point). */ @Test public void testDrawWithNullInfo() { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); //FIXME we should really assert a value here } /** * Replaces the dataset and checks that it has changed as expected. */ @Test public void testReplaceDataset() { // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(10.0, 10.0); series1.add(20.0, 20.0); series1.add(30.0, 30.0); XYDataset dataset = new XYSeriesCollection(series1); LocalListener l = new LocalListener(); this.chart.addChangeListener(l); XYPlot plot = (XYPlot) this.chart.getPlot(); plot.setDataset(dataset); assertEquals(true, l.flag); ValueAxis axis = plot.getRangeAxis(); Range range = axis.getRange(); assertTrue("Expecting the lower bound of the range to be around 10: " + range.getLowerBound(), range.getLowerBound() <= 10); assertTrue("Expecting the upper bound of the range to be around 30: " + range.getUpperBound(), range.getUpperBound() >= 30); } /** * Check that setting a tool tip generator for a series does override the * default generator. */ @Test public void testSetSeriesToolTipGenerator() { XYPlot plot = (XYPlot) this.chart.getPlot(); XYItemRenderer renderer = plot.getRenderer(); StandardXYToolTipGenerator tt = new StandardXYToolTipGenerator(); renderer.setSeriesToolTipGenerator(0, tt); XYToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); assertSame(tt2, tt); } /** * Create a test chart. * * @return The chart. */ private static JFreeChart createChart() { XYSeries series1 = new XYSeries("Series 1"); series1.add(1.0, 1.0); series1.add(2.0, 2.0); series1.add(3.0, 3.0); IntervalXYDataset dataset = new XYBarDataset(new XYSeriesCollection( series1), 1.0); return ChartFactory.createXYBarChart("XY Bar Chart", "Domain", false, "Range", dataset); } /** * A chart change listener. * */ static class LocalListener implements ChartChangeListener { /** A flag. */ private boolean flag; /** * Event handler. * * @param event the event. */ @Override public void chartChanged(ChartChangeEvent event) { this.flag = true; } } }
5,581
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
JFreeChartTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/JFreeChartTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2013, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * JFreeChartTests.java * -------------------- * (C) Copyright 2002-2013, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 11-Jun-2002 : Version 1 (DG); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 23-Sep-2003 : Removed null title test, since TM has added code to ensure * null titles cannot be created (DG); * 24-Nov-2005 : Removed OldLegend (DG); * 16-May-2007 : Added some new tests (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart; import org.jfree.chart.event.ChartChangeEvent; import org.jfree.chart.event.ChartChangeListener; import org.jfree.chart.plot.PiePlot; import org.jfree.chart.plot.RingPlot; import org.jfree.chart.title.LegendTitle; import org.jfree.chart.title.TextTitle; import org.jfree.chart.title.Title; import org.jfree.chart.ui.Align; import org.jfree.chart.ui.RectangleEdge; import org.jfree.chart.ui.RectangleInsets; import org.jfree.data.category.DefaultCategoryDataset; import org.jfree.data.general.DefaultPieDataset; import org.jfree.data.time.Day; import org.jfree.data.time.RegularTimePeriod; import org.jfree.data.time.TimeSeries; import org.jfree.data.time.TimeSeriesCollection; import org.junit.Before; import org.junit.Test; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.GradientPaint; import java.awt.Image; import java.awt.RenderingHints; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.net.URL; import java.util.List; import javax.swing.ImageIcon; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; /** * Tests for the {@link JFreeChart} class. */ public class JFreeChartTest implements ChartChangeListener { /** A pie chart. */ private JFreeChart pieChart; private Image testImage; private Image getTestImage() { if (testImage == null) { URL imageURL = getClass().getClassLoader().getResource( "org/jfree/chart/gorilla.jpg"); if (imageURL != null) { ImageIcon temp = new ImageIcon(imageURL); // use ImageIcon because it waits for the image to load... testImage = temp.getImage(); } } return testImage; } /** * Common test setup. */ @Before public void setUp() { DefaultPieDataset data = new DefaultPieDataset(); data.setValue("Java", new Double(43.2)); data.setValue("Visual Basic", new Double(0.0)); data.setValue("C/C++", new Double(17.5)); this.pieChart = ChartFactory.createPieChart("Pie Chart", data); } /** * Check that the equals() method can distinguish all fields. */ @Test public void testEquals() { JFreeChart chart1 = new JFreeChart("Title", new Font("SansSerif", Font.PLAIN, 12), new PiePlot(), true); JFreeChart chart2 = new JFreeChart("Title", new Font("SansSerif", Font.PLAIN, 12), new PiePlot(), true); assertEquals(chart1, chart2); assertEquals(chart2, chart1); // renderingHints chart1.setRenderingHints(new RenderingHints( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON)); assertFalse(chart1.equals(chart2)); chart2.setRenderingHints(new RenderingHints( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON)); assertEquals(chart1, chart2); // borderVisible chart1.setBorderVisible(true); assertFalse(chart1.equals(chart2)); chart2.setBorderVisible(true); assertEquals(chart1, chart2); // borderStroke BasicStroke s = new BasicStroke(2.0f); chart1.setBorderStroke(s); assertFalse(chart1.equals(chart2)); chart2.setBorderStroke(s); assertEquals(chart1, chart2); // borderPaint chart1.setBorderPaint(Color.RED); assertFalse(chart1.equals(chart2)); chart2.setBorderPaint(Color.RED); assertEquals(chart1, chart2); // padding chart1.setPadding(new RectangleInsets(1, 2, 3, 4)); assertFalse(chart1.equals(chart2)); chart2.setPadding(new RectangleInsets(1, 2, 3, 4)); assertEquals(chart1, chart2); // title chart1.setTitle("XYZ"); assertFalse(chart1.equals(chart2)); chart2.setTitle("XYZ"); assertEquals(chart1, chart2); // subtitles chart1.addSubtitle(new TextTitle("Subtitle")); assertFalse(chart1.equals(chart2)); chart2.addSubtitle(new TextTitle("Subtitle")); assertEquals(chart1, chart2); // plot chart1 = new JFreeChart("Title", new Font("SansSerif", Font.PLAIN, 12), new RingPlot(), false); chart2 = new JFreeChart("Title", new Font("SansSerif", Font.PLAIN, 12), new PiePlot(), false); assertFalse(chart1.equals(chart2)); chart2 = new JFreeChart("Title", new Font("SansSerif", Font.PLAIN, 12), new RingPlot(), false); assertEquals(chart1, chart2); // backgroundPaint chart1.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE)); assertFalse(chart1.equals(chart2)); chart2.setBackgroundPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.BLUE)); assertEquals(chart1, chart2); // backgroundImage chart1.setBackgroundImage(getTestImage()); assertFalse(chart1.equals(chart2)); chart2.setBackgroundImage(getTestImage()); assertEquals(chart1, chart2); // backgroundImageAlignment chart1.setBackgroundImageAlignment(Align.BOTTOM_LEFT); assertFalse(chart1.equals(chart2)); chart2.setBackgroundImageAlignment(Align.BOTTOM_LEFT); assertEquals(chart1, chart2); // backgroundImageAlpha chart1.setBackgroundImageAlpha(0.1f); assertFalse(chart1.equals(chart2)); chart2.setBackgroundImageAlpha(0.1f); assertEquals(chart1, chart2); } /** * A test to make sure that the legend is being picked up in the * equals() testing. */ @Test public void testEquals2() { JFreeChart chart1 = new JFreeChart("Title", new Font("SansSerif", Font.PLAIN, 12), new PiePlot(), true); JFreeChart chart2 = new JFreeChart("Title", new Font("SansSerif", Font.PLAIN, 12), new PiePlot(), false); assertFalse(chart1.equals(chart2)); assertFalse(chart2.equals(chart1)); } /** * Checks the subtitle count - should be 1 (the legend). */ @Test public void testSubtitleCount() { int count = this.pieChart.getSubtitleCount(); assertEquals(1, count); } /** * Some checks for the getSubtitle() method. */ @Test public void testGetSubtitle() { DefaultPieDataset dataset = new DefaultPieDataset(); JFreeChart chart = ChartFactory.createPieChart("title", dataset); Title t = chart.getSubtitle(0); assertTrue(t instanceof LegendTitle); try { chart.getSubtitle(-1); fail("Should have thrown an IllegalArgumentException on negative number"); } catch (IllegalArgumentException e) { assertEquals("Index out of range.", e.getMessage()); } try { chart.getSubtitle(1); fail("Should have thrown an IllegalArgumentException on excesive number"); } catch (IllegalArgumentException e) { assertEquals("Index out of range.", e.getMessage()); } try { chart.getSubtitle(2); fail("Should have thrown an IllegalArgumentException on number being out of range"); } catch (IllegalArgumentException e) { assertEquals("Index out of range.", e.getMessage()); } } /** * Serialize a pie chart, restore it, and check for equality. */ @Test public void testSerialization1() throws IOException, ClassNotFoundException { DefaultPieDataset data = new DefaultPieDataset(); data.setValue("Type 1", 54.5); data.setValue("Type 2", 23.9); data.setValue("Type 3", 45.8); JFreeChart c1 = ChartFactory.createPieChart("Test", data); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(c1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); JFreeChart c2 = (JFreeChart) in.readObject(); in.close(); assertEquals(c1, c2); LegendTitle lt2 = c2.getLegend(); assertSame(lt2.getSources()[0], c2.getPlot()); } /** * Serialize a 3D pie chart, restore it, and check for equality. */ @Test public void testSerialization2() throws IOException, ClassNotFoundException { DefaultPieDataset data = new DefaultPieDataset(); data.setValue("Type 1", 54.5); data.setValue("Type 2", 23.9); data.setValue("Type 3", 45.8); JFreeChart c1 = ChartFactory.createPieChart3D("Test", data); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(c1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); JFreeChart c2 = (JFreeChart) in.readObject(); in.close(); assertEquals(c1, c2); } /** * Serialize a bar chart, restore it, and check for equality. */ @Test public void testSerialization3() throws IOException, ClassNotFoundException { // row keys... String series1 = "First"; String series2 = "Second"; String series3 = "Third"; // column keys... String category1 = "Category 1"; String category2 = "Category 2"; String category3 = "Category 3"; String category4 = "Category 4"; String category5 = "Category 5"; String category6 = "Category 6"; String category7 = "Category 7"; String category8 = "Category 8"; // create the dataset... DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(1.0, series1, category1); dataset.addValue(4.0, series1, category2); dataset.addValue(3.0, series1, category3); dataset.addValue(5.0, series1, category4); dataset.addValue(5.0, series1, category5); dataset.addValue(7.0, series1, category6); dataset.addValue(7.0, series1, category7); dataset.addValue(8.0, series1, category8); dataset.addValue(5.0, series2, category1); dataset.addValue(7.0, series2, category2); dataset.addValue(6.0, series2, category3); dataset.addValue(8.0, series2, category4); dataset.addValue(4.0, series2, category5); dataset.addValue(4.0, series2, category6); dataset.addValue(2.0, series2, category7); dataset.addValue(1.0, series2, category8); dataset.addValue(4.0, series3, category1); dataset.addValue(3.0, series3, category2); dataset.addValue(2.0, series3, category3); dataset.addValue(3.0, series3, category4); dataset.addValue(6.0, series3, category5); dataset.addValue(3.0, series3, category6); dataset.addValue(4.0, series3, category7); dataset.addValue(3.0, series3, category8); // create the chart... JFreeChart c1 = ChartFactory.createBarChart("Vertical Bar Chart", "Category", "Value", dataset); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(c1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); JFreeChart c2 = (JFreeChart) in.readObject(); in.close(); assertEquals(c1, c2); } /** * Serialize a time seroes chart, restore it, and check for equality. */ @Test public void testSerialization4() throws IOException, ClassNotFoundException { RegularTimePeriod t = new Day(); TimeSeries series = new TimeSeries("Series 1"); series.add(t, 36.4); t = t.next(); series.add(t, 63.5); TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(series); JFreeChart c1 = ChartFactory.createTimeSeriesChart("Test", "Date", "Value", dataset); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(c1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); JFreeChart c2 = (JFreeChart) in.readObject(); in.close(); assertEquals(c1, c2); } /** * Some checks for the addSubtitle() methods. */ @Test public void testAddSubtitle() { DefaultPieDataset dataset = new DefaultPieDataset(); JFreeChart chart = ChartFactory.createPieChart("title", dataset); TextTitle t0 = new TextTitle("T0"); chart.addSubtitle(0, t0); assertEquals(t0, chart.getSubtitle(0)); TextTitle t1 = new TextTitle("T1"); chart.addSubtitle(t1); assertEquals(t1, chart.getSubtitle(2)); // subtitle 1 is the legend try { chart.addSubtitle(null); fail("Should have thrown an IllegalArgumentException on index out of range"); } catch (IllegalArgumentException e) { assertEquals("Null 'subtitle' argument.", e.getMessage()); } try { chart.addSubtitle(-1, t0); fail("Should have thrown an IllegalArgumentException on index out of range"); } catch (IllegalArgumentException e) { assertEquals("The 'index' argument is out of range.", e.getMessage()); } try { chart.addSubtitle(4, t0); fail("Should have thrown an IllegalArgumentException on index out of range"); } catch (IllegalArgumentException e) { assertEquals("The 'index' argument is out of range.", e.getMessage()); } } /** * Some checks for the getSubtitles() method. */ @Test public void testGetSubtitles() { DefaultPieDataset dataset = new DefaultPieDataset(); JFreeChart chart = ChartFactory.createPieChart("title", dataset); List<Title> subtitles = chart.getSubtitles(); assertEquals(1, chart.getSubtitleCount()); // adding something to the returned list should NOT change the chart subtitles.add(new TextTitle("T")); assertEquals(1, chart.getSubtitleCount()); } /** * Some checks for the default legend firing change events. */ @Test public void testLegendEvents() { DefaultPieDataset dataset = new DefaultPieDataset(); JFreeChart chart = ChartFactory.createPieChart("title", dataset); chart.addChangeListener(this); this.lastChartChangeEvent = null; LegendTitle legend = chart.getLegend(); legend.setPosition(RectangleEdge.TOP); assertNotNull(this.lastChartChangeEvent); } /** * Some checks for title changes and event notification. */ @Test public void testTitleChangeEvent() { DefaultPieDataset dataset = new DefaultPieDataset(); JFreeChart chart = ChartFactory.createPieChart("title", dataset); chart.addChangeListener(this); this.lastChartChangeEvent = null; TextTitle t = chart.getTitle(); t.setFont(new Font("Dialog", Font.BOLD, 9)); assertNotNull(this.lastChartChangeEvent); this.lastChartChangeEvent = null; // now create a new title and replace the existing title, several // things should happen: // (1) Adding the new title should trigger an immediate // ChartChangeEvent; // (2) Modifying the new title should trigger a ChartChangeEvent; // (3) Modifying the old title should NOT trigger a ChartChangeEvent TextTitle t2 = new TextTitle("T2"); chart.setTitle(t2); assertNotNull(this.lastChartChangeEvent); this.lastChartChangeEvent = null; t2.setFont(new Font("Dialog", Font.BOLD, 9)); assertNotNull(this.lastChartChangeEvent); this.lastChartChangeEvent = null; t.setFont(new Font("Dialog", Font.BOLD, 9)); assertNull(this.lastChartChangeEvent); this.lastChartChangeEvent = null; } /** The last ChartChangeEvent received. */ private ChartChangeEvent lastChartChangeEvent; /** * Records the last chart change event. * * @param event the event. */ @Override public void chartChanged(ChartChangeEvent event) { this.lastChartChangeEvent = event; } }
19,223
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
ScatterPlotTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/ScatterPlotTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * --------------------- * ScatterPlotTests.java * --------------------- * (C) Copyright 2002-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 11-Jun-2002 : Version 1 (DG); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * */ package org.jfree.chart; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.event.ChartChangeEvent; import org.jfree.chart.event.ChartChangeListener; import org.jfree.chart.labels.StandardXYToolTipGenerator; import org.jfree.chart.labels.XYToolTipGenerator; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.XYItemRenderer; import org.jfree.data.Range; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.junit.Before; import org.junit.Test; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for a scatter plot. */ public class ScatterPlotTest { /** A chart. */ private JFreeChart chart; /** * Common test setup. */ @Before public void setUp() { this.chart = createChart(); } /** * Draws the chart with a null info object to make sure that no exceptions * are thrown (a problem that was occurring at one point). */ @Test public void testDrawWithNullInfo() { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); //FIXME we should really assert a value here } /** * Replaces the dataset and checks that it has changed as expected. */ @Test public void testReplaceDataset() { // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(10.0, 10.0); series1.add(20.0, 20.0); series1.add(30.0, 30.0); XYDataset dataset = new XYSeriesCollection(series1); LocalListener l = new LocalListener(); this.chart.addChangeListener(l); XYPlot plot = (XYPlot) this.chart.getPlot(); plot.setDataset(dataset); assertEquals(true, l.flag); ValueAxis axis = plot.getRangeAxis(); Range range = axis.getRange(); assertTrue("Expecting the lower bound of the range to be around 10: " + range.getLowerBound(), range.getLowerBound() <= 10); assertTrue("Expecting the upper bound of the range to be around 30: " + range.getUpperBound(), range.getUpperBound() >= 30); } /** * Check that setting a tool tip generator for a series does override the * default generator. */ @Test public void testSetSeriesToolTipGenerator() { XYPlot plot = (XYPlot) this.chart.getPlot(); XYItemRenderer renderer = plot.getRenderer(); StandardXYToolTipGenerator tt = new StandardXYToolTipGenerator(); renderer.setSeriesToolTipGenerator(0, tt); XYToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); assertSame(tt2, tt); } /** * Create a test chart. * * @return The chart. */ private static JFreeChart createChart() { XYSeries series1 = new XYSeries("Series 1"); series1.add(1.0, 1.0); series1.add(2.0, 2.0); series1.add(3.0, 3.0); XYDataset dataset = new XYSeriesCollection(series1); return ChartFactory.createScatterPlot("Scatter Plot", "Domain", "Range", dataset); } /** * A chart change listener. */ static class LocalListener implements ChartChangeListener { /** A flag. */ private boolean flag; /** * Event handler. * * @param event the event. */ @Override public void chartChanged(ChartChangeEvent event) { this.flag = true; } } }
5,488
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
WaterfallChartTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/WaterfallChartTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------ * WaterfallChartTests.java * ------------------------ * (C) Copyright 2002-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 12-Apr-2005 : Version 1 (DG); * */ package org.jfree.chart; import org.jfree.chart.labels.CategoryToolTipGenerator; import org.jfree.chart.labels.StandardCategoryToolTipGenerator; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.renderer.category.CategoryItemRenderer; import org.jfree.chart.urls.CategoryURLGenerator; import org.jfree.chart.urls.StandardCategoryURLGenerator; import org.jfree.data.category.CategoryDataset; import org.jfree.data.general.DatasetUtilities; import org.junit.Before; import org.junit.Test; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import static org.junit.Assert.assertSame; /** * Some tests for a waterfall chart. */ public class WaterfallChartTest { /** A chart. */ private JFreeChart chart; /** * Common test setup. */ @Before public void setUp() { this.chart = createWaterfallChart(); } /** * Draws the chart with a null info object to make sure that no exceptions * are thrown (a problem that was occurring at one point). */ @Test public void testDrawWithNullInfo() { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); //FIXME we should really assert a value here } /** * Check that setting a tool tip generator for a series does override the * default generator. */ @Test public void testSetSeriesToolTipGenerator() { CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); StandardCategoryToolTipGenerator tt = new StandardCategoryToolTipGenerator(); renderer.setSeriesToolTipGenerator(0, tt); CategoryToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); assertSame(tt2, tt); } /** * Check that setting a URL generator for a series does override the * default generator. */ @Test public void testSetSeriesURLGenerator() { CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); StandardCategoryURLGenerator url1 = new StandardCategoryURLGenerator(); renderer.setSeriesItemURLGenerator(0, url1); CategoryURLGenerator url2 = renderer.getItemURLGenerator(0, 0); assertSame(url2, url1); } /** * Create a bar chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createWaterfallChart() { Number[][] data = new Integer[][] {{-3, -2}, {-1, 1}, {2, 3}}; CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data); return ChartFactory.createWaterfallChart("Waterfall Chart", "Domain", "Range", dataset); } }
4,616
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
StackedAreaChartTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/StackedAreaChartTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------------- * StackedAreaChartTests.java * -------------------------- * (C) Copyright 2005-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 12-Apr-2005 : Version 1 (DG); * */ package org.jfree.chart; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.event.ChartChangeEvent; import org.jfree.chart.event.ChartChangeListener; import org.jfree.chart.labels.CategoryToolTipGenerator; import org.jfree.chart.labels.StandardCategoryToolTipGenerator; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.renderer.category.CategoryItemRenderer; import org.jfree.chart.urls.CategoryURLGenerator; import org.jfree.chart.urls.StandardCategoryURLGenerator; import org.jfree.data.Range; import org.jfree.data.category.CategoryDataset; import org.jfree.data.general.DatasetUtilities; import org.junit.Before; import org.junit.Test; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Some tests for a stacked area chart. */ public class StackedAreaChartTest { /** A chart. */ private JFreeChart chart; /** * Common test setup. */ @Before public void setUp() { this.chart = createChart(); } /** * Draws the chart with a null info object to make sure that no exceptions * are thrown (a problem that was occurring at one point). */ @Test public void testDrawWithNullInfo() { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); //FIXME we should really assert a value here } /** * Replaces the dataset and checks that it has changed as expected. */ @Test public void testReplaceDataset() { // create a dataset... Number[][] data = new Integer[][] {{-30, -20}, {-10, 10}, {20, 30}}; CategoryDataset newData = DatasetUtilities.createCategoryDataset("S", "C", data); LocalListener l = new LocalListener(); this.chart.addChangeListener(l); CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); plot.setDataset(newData); assertEquals(true, l.flag); ValueAxis axis = plot.getRangeAxis(); Range range = axis.getRange(); assertTrue("Expecting the lower bound of the range to be around -30: " + range.getLowerBound(), range.getLowerBound() <= -30); assertTrue("Expecting the upper bound of the range to be around 30: " + range.getUpperBound(), range.getUpperBound() >= 30); } /** * Check that setting a tool tip generator for a series does override the * default generator. */ @Test public void testSetSeriesToolTipGenerator() { CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); StandardCategoryToolTipGenerator tt = new StandardCategoryToolTipGenerator(); renderer.setSeriesToolTipGenerator(0, tt); CategoryToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); assertSame(tt2, tt); } /** * Check that setting a URL generator for a series does override the * default generator. */ @Test public void testSetSeriesURLGenerator() { CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); StandardCategoryURLGenerator url1 = new StandardCategoryURLGenerator(); renderer.setSeriesItemURLGenerator(0, url1); CategoryURLGenerator url2 = renderer.getItemURLGenerator(0, 0); assertSame(url2, url1); } /** * Create a stacked bar chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createChart() { Number[][] data = new Integer[][] {{-3, -2}, {-1, 1}, {2, 3}}; CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data); return ChartFactory.createStackedAreaChart("Stacked Area Chart", "Domain", "Range", dataset); } /** * A chart change listener. */ static class LocalListener implements ChartChangeListener { /** A flag. */ private boolean flag; /** * Event handler. * * @param event the event. */ @Override public void chartChanged(ChartChangeEvent event) { this.flag = true; } } }
6,276
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
PaintMapTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/PaintMapTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------ * PaintMapTests.java * ------------------ * (C) Copyright 2006, 2007, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 27-Sep-2006 : Version 1 (DG); * 17-Jan-2007 : Added testKeysOfDifferentClasses() (DG); * */ package org.jfree.chart; import org.junit.Test; import java.awt.Color; import java.awt.GradientPaint; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.fail; /** * Some tests for the {@link PaintMap} class. */ public class PaintMapTest { /** * Some checks for the getPaint() method. */ @Test public void testGetPaint() { PaintMap m1 = new PaintMap(); assertEquals(null, m1.getPaint("A")); m1.put("A", Color.RED); assertEquals(Color.RED, m1.getPaint("A")); m1.put("A", null); assertEquals(null, m1.getPaint("A")); // a null key should throw an IllegalArgumentException try { m1.getPaint(null); fail("IllegalArgumentException should have been thrown on passing null value"); } catch (IllegalArgumentException e) { assertEquals("Null 'key' argument.", e.getMessage()); } } /** * Some checks for the put() method. */ @Test public void testPut() { PaintMap m1 = new PaintMap(); m1.put("A", Color.RED); assertEquals(Color.RED, m1.getPaint("A")); // a null key should throw an IllegalArgumentException try { m1.put(null, Color.BLUE); fail("IllegalArgumentException should have been thrown on null key"); } catch (IllegalArgumentException e) { assertEquals("Null 'key' argument.", e.getMessage()); } } /** * Some checks for the equals() method. */ @Test public void testEquals() { PaintMap m1 = new PaintMap(); PaintMap m2 = new PaintMap(); assertEquals(m1, m1); assertEquals(m1, m2); assertFalse(m1.equals(null)); assertFalse(m1.equals("ABC")); m1.put("K1", Color.RED); assertFalse(m1.equals(m2)); m2.put("K1", Color.RED); assertEquals(m1, m2); m1.put("K2", new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.yellow)); assertFalse(m1.equals(m2)); m2.put("K2", new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.yellow)); assertEquals(m1, m2); m1.put("K2", null); assertFalse(m1.equals(m2)); m2.put("K2", null); assertEquals(m1, m2); } /** * Some checks for cloning. */ @Test public void testCloning() throws CloneNotSupportedException { PaintMap m1 = new PaintMap(); PaintMap m2 = (PaintMap) m1.clone(); assertEquals(m1, m2); m1.put("K1", Color.RED); m1.put("K2", new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.yellow)); m2 = (PaintMap) m1.clone(); assertEquals(m1, m2); } /** * A check for serialization. */ @Test public void testSerialization1() throws IOException, ClassNotFoundException { PaintMap m1 = new PaintMap(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(m1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); PaintMap m2 = (PaintMap) in.readObject(); in.close(); assertEquals(m1, m2); } /** * A check for serialization. */ @Test public void testSerialization2() throws IOException, ClassNotFoundException { PaintMap m1 = new PaintMap(); m1.put("K1", Color.RED); m1.put("K2", new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.yellow)); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(m1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); PaintMap m2 = (PaintMap) in.readObject(); in.close(); assertEquals(m1, m2); } /** * This test covers a bug reported in the forum: * * http://www.jfree.org/phpBB2/viewtopic.php?t=19980 */ @Test public void testKeysOfDifferentClasses() { PaintMap m = new PaintMap(); m.put("ABC", Color.RED); m.put(99, Color.BLUE); assertEquals(Color.BLUE, m.getPaint(99)); } }
6,313
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
HashUtilitiesTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/HashUtilitiesTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ----------------------- * HashUtilitiesTests.java * ----------------------- * (C) Copyright 2004-2008, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 06-Mar-2007 : Version 1 (DG); * */ package org.jfree.chart; import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; /** * Tests for the {@link HashUtilities} class. */ public class HashUtilitiesTest { /** * Some sanity checks for the hashCodeForDoubleArray() method. */ @Test public void testHashCodeForDoubleArray() { double[] a1 = new double[] {1.0}; double[] a2 = new double[] {1.0}; int h1 = HashUtilities.hashCodeForDoubleArray(a1); int h2 = HashUtilities.hashCodeForDoubleArray(a2); assertEquals(h1, h2); double[] a3 = new double[] {0.5, 1.0}; int h3 = HashUtilities.hashCodeForDoubleArray(a3); assertFalse(h1 == h3); } }
2,288
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
ChartPanelTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/ChartPanelTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * ChartPanelTests.java * -------------------- * (C) Copyright 2004-2009, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 13-Jul-2004 : Version 1 (DG); * 12-Jan-2009 : Added test2502355() (DG); * 08-Jun-2009 : Added testSetMouseWheelEnabled() (DG); */ package org.jfree.chart; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.awt.geom.Rectangle2D; import java.util.EventListener; import java.util.List; import javax.swing.event.CaretListener; import org.jfree.chart.axis.NumberAxis; import org.jfree.chart.event.ChartChangeEvent; import org.jfree.chart.event.ChartChangeListener; import org.jfree.chart.plot.XYPlot; import org.jfree.data.xy.DefaultXYDataset; import org.junit.Test; /** * Tests for the {@link ChartPanel} class. */ public class ChartPanelTest implements ChartChangeListener, ChartMouseListener { private List<ChartChangeEvent> chartChangeEvents = new java.util.ArrayList<ChartChangeEvent>(); /** * Receives a chart change event and stores it in a list for later * inspection. * * @param event the event. */ @Override public void chartChanged(ChartChangeEvent event) { this.chartChangeEvents.add(event); } /** * Test that the constructor will accept a null chart. */ @Test public void testConstructor1() { ChartPanel panel = new ChartPanel(null); assertEquals(null, panel.getChart()); } /** * Test that it is possible to set the panel's chart to null. */ @Test public void testSetChart() { JFreeChart chart = new JFreeChart(new XYPlot()); ChartPanel panel = new ChartPanel(chart); panel.setChart(null); assertEquals(null, panel.getChart()); } /** * Check the behaviour of the getListeners() method. */ @Test public void testGetListeners() { ChartPanel p = new ChartPanel(null); p.addChartMouseListener(this); EventListener[] listeners = p.getListeners(ChartMouseListener.class); assertEquals(1, listeners.length); assertEquals(this, listeners[0]); // try a listener type that isn't registered listeners = p.getListeners(CaretListener.class); assertEquals(0, listeners.length); p.removeChartMouseListener(this); listeners = p.getListeners(ChartMouseListener.class); assertEquals(0, listeners.length); // try a null argument try { p.getListeners(null); fail("A null pointer exception should have been thrown"); } catch (NullPointerException e) { // we expect to go in here } } /** * Ignores a mouse click event. * * @param event the event. */ @Override public void chartMouseClicked(ChartMouseEvent event) { // ignore } /** * Ignores a mouse move event. * * @param event the event. */ @Override public void chartMouseMoved(ChartMouseEvent event) { // ignore } /** * Checks that a call to the zoom() method generates just one * ChartChangeEvent. */ @Test public void test2502355_zoom() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", "Y", dataset); ChartPanel panel = new ChartPanel(chart); chart.addChangeListener(this); this.chartChangeEvents.clear(); panel.zoom(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0)); assertEquals(1, this.chartChangeEvents.size()); } /** * Checks that a call to the zoomInBoth() method generates just one * ChartChangeEvent. */ @Test public void test2502355_zoomInBoth() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", "Y", dataset); ChartPanel panel = new ChartPanel(chart); chart.addChangeListener(this); this.chartChangeEvents.clear(); panel.zoomInBoth(1.0, 2.0); assertEquals(1, this.chartChangeEvents.size()); } /** * Checks that a call to the zoomOutBoth() method generates just one * ChartChangeEvent. */ @Test public void test2502355_zoomOutBoth() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", "Y", dataset); ChartPanel panel = new ChartPanel(chart); chart.addChangeListener(this); this.chartChangeEvents.clear(); panel.zoomOutBoth(1.0, 2.0); assertEquals(1, this.chartChangeEvents.size()); } /** * Checks that a call to the restoreAutoBounds() method generates just one * ChartChangeEvent. */ @Test public void test2502355_restoreAutoBounds() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", "Y", dataset); ChartPanel panel = new ChartPanel(chart); chart.addChangeListener(this); this.chartChangeEvents.clear(); panel.restoreAutoBounds(); assertEquals(1, this.chartChangeEvents.size()); } /** * Checks that a call to the zoomInDomain() method, for a plot with more * than one domain axis, generates just one ChartChangeEvent. */ @Test public void test2502355_zoomInDomain() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", "Y", dataset); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainAxis(1, new NumberAxis("X2")); ChartPanel panel = new ChartPanel(chart); chart.addChangeListener(this); this.chartChangeEvents.clear(); panel.zoomInDomain(1.0, 2.0); assertEquals(1, this.chartChangeEvents.size()); } /** * Checks that a call to the zoomInRange() method, for a plot with more * than one range axis, generates just one ChartChangeEvent. */ @Test public void test2502355_zoomInRange() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", "Y", dataset); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRangeAxis(1, new NumberAxis("X2")); ChartPanel panel = new ChartPanel(chart); chart.addChangeListener(this); this.chartChangeEvents.clear(); panel.zoomInRange(1.0, 2.0); assertEquals(1, this.chartChangeEvents.size()); } /** * Checks that a call to the zoomOutDomain() method, for a plot with more * than one domain axis, generates just one ChartChangeEvent. */ @Test public void test2502355_zoomOutDomain() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", "Y", dataset); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainAxis(1, new NumberAxis("X2")); ChartPanel panel = new ChartPanel(chart); chart.addChangeListener(this); this.chartChangeEvents.clear(); panel.zoomOutDomain(1.0, 2.0); assertEquals(1, this.chartChangeEvents.size()); } /** * Checks that a call to the zoomOutRange() method, for a plot with more * than one range axis, generates just one ChartChangeEvent. */ @Test public void test2502355_zoomOutRange() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", "Y", dataset); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRangeAxis(1, new NumberAxis("X2")); ChartPanel panel = new ChartPanel(chart); chart.addChangeListener(this); this.chartChangeEvents.clear(); panel.zoomOutRange(1.0, 2.0); assertEquals(1, this.chartChangeEvents.size()); } /** * Checks that a call to the restoreAutoDomainBounds() method, for a plot * with more than one range axis, generates just one ChartChangeEvent. */ @Test public void test2502355_restoreAutoDomainBounds() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", "Y", dataset); XYPlot plot = (XYPlot) chart.getPlot(); plot.setDomainAxis(1, new NumberAxis("X2")); ChartPanel panel = new ChartPanel(chart); chart.addChangeListener(this); this.chartChangeEvents.clear(); panel.restoreAutoDomainBounds(); assertEquals(1, this.chartChangeEvents.size()); } /** * Checks that a call to the restoreAutoRangeBounds() method, for a plot * with more than one range axis, generates just one ChartChangeEvent. */ @Test public void test2502355_restoreAutoRangeBounds() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", "Y", dataset); XYPlot plot = (XYPlot) chart.getPlot(); plot.setRangeAxis(1, new NumberAxis("X2")); ChartPanel panel = new ChartPanel(chart); chart.addChangeListener(this); this.chartChangeEvents.clear(); panel.restoreAutoRangeBounds(); assertEquals(1, this.chartChangeEvents.size()); } /** * In version 1.0.13 there is a bug where enabling the mouse wheel handler * twice would in fact disable it. */ @Test public void testSetMouseWheelEnabled() { DefaultXYDataset dataset = new DefaultXYDataset(); JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X", "Y", dataset); ChartPanel panel = new ChartPanel(chart); panel.setMouseWheelEnabled(true); assertTrue(panel.isMouseWheelEnabled()); panel.setMouseWheelEnabled(true); assertTrue(panel.isMouseWheelEnabled()); panel.setMouseWheelEnabled(false); assertFalse(panel.isMouseWheelEnabled()); } }
11,804
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
GanttChartTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/GanttChartTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * GanttChartTests.java * -------------------- * (C) Copyright 2005-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 12-Apr-2005 : Version 1 (DG); * */ package org.jfree.chart; import org.jfree.chart.event.ChartChangeEvent; import org.jfree.chart.event.ChartChangeListener; import org.jfree.chart.labels.CategoryToolTipGenerator; import org.jfree.chart.labels.StandardCategoryToolTipGenerator; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.renderer.category.CategoryItemRenderer; import org.jfree.chart.urls.CategoryURLGenerator; import org.jfree.chart.urls.StandardCategoryURLGenerator; import org.jfree.data.category.IntervalCategoryDataset; import org.jfree.data.gantt.Task; import org.jfree.data.gantt.TaskSeries; import org.jfree.data.gantt.TaskSeriesCollection; import org.jfree.data.time.SimpleTimePeriod; import org.junit.Before; import org.junit.Test; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.util.Calendar; import java.util.Date; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; /** * Some tests for a Gantt chart. */ public class GanttChartTest { /** A chart. */ private JFreeChart chart; /** * Common test setup. */ @Before public void setUp() { this.chart = createGanttChart(); } /** * Draws the chart with a <code>null</code> info object to make sure that * no exceptions are thrown (a problem that was occurring at one point). */ @Test public void testDrawWithNullInfo() { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); //FIXME we should really assert a value } /** * Draws the chart with a <code>null</code> info object to make sure that * no exceptions are thrown (a problem that was occurring at one point). */ @Test public void testDrawWithNullInfo2() { JFreeChart chart = createGanttChart(); CategoryPlot plot = (CategoryPlot) chart.getPlot(); plot.setDataset(createDataset()); /* BufferedImage img =*/ chart.createBufferedImage(300, 200, null); //FIXME we should really assert a value } /** * Replaces the chart's dataset and then checks that the new dataset is OK. */ @Test public void testReplaceDataset() { LocalListener l = new LocalListener(); this.chart.addChangeListener(l); CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); plot.setDataset(null); assertEquals(true, l.flag); } /** * Check that setting a tool tip generator for a series does override the * default generator. */ @Test public void testSetSeriesToolTipGenerator() { CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); StandardCategoryToolTipGenerator tt = new StandardCategoryToolTipGenerator(); renderer.setSeriesToolTipGenerator(0, tt); CategoryToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); assertSame(tt2, tt); } /** * Check that setting a URL generator for a series does override the * default generator. */ @Test public void testSetSeriesURLGenerator() { CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); StandardCategoryURLGenerator url1 = new StandardCategoryURLGenerator(); renderer.setSeriesItemURLGenerator(0, url1); CategoryURLGenerator url2 = renderer.getItemURLGenerator(0, 0); assertSame(url2, url1); } /** * Create a Gantt chart. * * @return The chart. */ private static JFreeChart createGanttChart() { return ChartFactory.createGanttChart("Gantt Chart", "Domain", "Range", null); } /** * Creates a sample dataset for a Gantt chart. * * @return The dataset. */ public static IntervalCategoryDataset createDataset() { TaskSeries s1 = new TaskSeries("Scheduled"); s1.add(new Task("Write Proposal", new SimpleTimePeriod(date(1, Calendar.APRIL, 2001), date(5, Calendar.APRIL, 2001)))); s1.add(new Task("Obtain Approval", new SimpleTimePeriod(date(9, Calendar.APRIL, 2001), date(9, Calendar.APRIL, 2001)))); s1.add(new Task("Requirements Analysis", new SimpleTimePeriod(date(10, Calendar.APRIL, 2001), date(5, Calendar.MAY, 2001)))); s1.add(new Task("Design Phase", new SimpleTimePeriod(date(6, Calendar.MAY, 2001), date(30, Calendar.MAY, 2001)))); s1.add(new Task("Design Signoff", new SimpleTimePeriod(date(2, Calendar.JUNE, 2001), date(2, Calendar.JUNE, 2001)))); s1.add(new Task("Alpha Implementation", new SimpleTimePeriod(date(3, Calendar.JUNE, 2001), date(31, Calendar.JULY, 2001)))); s1.add(new Task("Design Review", new SimpleTimePeriod(date(1, Calendar.AUGUST, 2001), date(8, Calendar.AUGUST, 2001)))); s1.add(new Task("Revised Design Signoff", new SimpleTimePeriod(date(10, Calendar.AUGUST, 2001), date(10, Calendar.AUGUST, 2001)))); s1.add(new Task("Beta Implementation", new SimpleTimePeriod(date(12, Calendar.AUGUST, 2001), date(12, Calendar.SEPTEMBER, 2001)))); s1.add(new Task("Testing", new SimpleTimePeriod(date(13, Calendar.SEPTEMBER, 2001), date(31, Calendar.OCTOBER, 2001)))); s1.add(new Task("Final Implementation", new SimpleTimePeriod(date(1, Calendar.NOVEMBER, 2001), date(15, Calendar.NOVEMBER, 2001)))); s1.add(new Task("Signoff", new SimpleTimePeriod(date(28, Calendar.NOVEMBER, 2001), date(30, Calendar.NOVEMBER, 2001)))); TaskSeries s2 = new TaskSeries("Actual"); s2.add(new Task("Write Proposal", new SimpleTimePeriod(date(1, Calendar.APRIL, 2001), date(5, Calendar.APRIL, 2001)))); s2.add(new Task("Obtain Approval", new SimpleTimePeriod(date(9, Calendar.APRIL, 2001), date(9, Calendar.APRIL, 2001)))); s2.add(new Task("Requirements Analysis", new SimpleTimePeriod(date(10, Calendar.APRIL, 2001), date(15, Calendar.MAY, 2001)))); s2.add(new Task("Design Phase", new SimpleTimePeriod(date(15, Calendar.MAY, 2001), date(17, Calendar.JUNE, 2001)))); s2.add(new Task("Design Signoff", new SimpleTimePeriod(date(30, Calendar.JUNE, 2001), date(30, Calendar.JUNE, 2001)))); s2.add(new Task("Alpha Implementation", new SimpleTimePeriod(date(1, Calendar.JULY, 2001), date(12, Calendar.SEPTEMBER, 2001)))); s2.add(new Task("Design Review", new SimpleTimePeriod(date(12, Calendar.SEPTEMBER, 2001), date(22, Calendar.SEPTEMBER, 2001)))); s2.add(new Task("Revised Design Signoff", new SimpleTimePeriod(date(25, Calendar.SEPTEMBER, 2001), date(27, Calendar.SEPTEMBER, 2001)))); s2.add(new Task("Beta Implementation", new SimpleTimePeriod(date(27, Calendar.SEPTEMBER, 2001), date(30, Calendar.OCTOBER, 2001)))); s2.add(new Task("Testing", new SimpleTimePeriod(date(31, Calendar.OCTOBER, 2001), date(17, Calendar.NOVEMBER, 2001)))); s2.add(new Task("Final Implementation", new SimpleTimePeriod(date(18, Calendar.NOVEMBER, 2001), date(5, Calendar.DECEMBER, 2001)))); s2.add(new Task("Signoff", new SimpleTimePeriod(date(10, Calendar.DECEMBER, 2001), date(11, Calendar.DECEMBER, 2001)))); TaskSeriesCollection collection = new TaskSeriesCollection(); collection.add(s1); collection.add(s2); return collection; } /** * Utility method for creating <code>Date</code> objects. * * @param day the date. * @param month the month. * @param year the year. * * @return a date. */ private static Date date(int day, int month, int year) { Calendar calendar = Calendar.getInstance(); calendar.set(year, month, day); Date result = calendar.getTime(); return result; } /** * A chart change listener. * */ static class LocalListener implements ChartChangeListener { /** A flag. */ private boolean flag; /** * Event handler. * * @param event the event. */ @Override public void chartChanged(ChartChangeEvent event) { this.flag = true; } } }
11,192
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
StackedBarChartTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/StackedBarChartTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------- * StackedBarChartTests.java * ------------------------- * (C) Copyright 2002-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 11-Jun-2002 : Version 1 (DG); * 25-Jun-2002 : Removed unnecessary import (DG); * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG); * 29-Jan-2004 : Renamed StackedHorizontalBarChartTests * --> StackedBarChartTests (DG); * */ package org.jfree.chart; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.event.ChartChangeEvent; import org.jfree.chart.event.ChartChangeListener; import org.jfree.chart.labels.CategoryToolTipGenerator; import org.jfree.chart.labels.StandardCategoryToolTipGenerator; import org.jfree.chart.plot.CategoryPlot; import org.jfree.chart.renderer.category.CategoryItemRenderer; import org.jfree.chart.urls.CategoryURLGenerator; import org.jfree.chart.urls.StandardCategoryURLGenerator; import org.jfree.data.Range; import org.jfree.data.category.CategoryDataset; import org.jfree.data.general.DatasetUtilities; import org.junit.Before; import org.junit.Test; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Tests for a stacked bar chart. */ public class StackedBarChartTest { /** A chart. */ private JFreeChart chart; /** * Common test setup. */ @Before public void setUp() { this.chart = createChart(); } /** * Draws the chart with a null info object to make sure that no exceptions * are thrown (a problem that was occurring at one point). */ @Test public void testDrawWithNullInfo() { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); //FIXME we should really assert a value here } /** * Replaces the dataset and checks that it has changed as expected. */ @Test public void testReplaceDataset() { // create a dataset... Number[][] data = new Integer[][] {{-30, -20}, {-10, 10}, {20, 30}}; CategoryDataset newData = DatasetUtilities.createCategoryDataset("S", "C", data); LocalListener l = new LocalListener(); this.chart.addChangeListener(l); CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); plot.setDataset(newData); assertEquals(true, l.flag); ValueAxis axis = plot.getRangeAxis(); Range range = axis.getRange(); assertTrue("Expecting the lower bound of the range to be around -30: " + range.getLowerBound(), range.getLowerBound() <= -30); assertTrue("Expecting the upper bound of the range to be around 30: " + range.getUpperBound(), range.getUpperBound() >= 30); } /** * Check that setting a tool tip generator for a series does override the * default generator. */ @Test public void testSetSeriesToolTipGenerator() { CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); StandardCategoryToolTipGenerator tt = new StandardCategoryToolTipGenerator(); renderer.setSeriesToolTipGenerator(0, tt); CategoryToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); assertSame(tt2, tt); } /** * Check that setting a URL generator for a series does override the * default generator. */ @Test public void testSetSeriesURLGenerator() { CategoryPlot plot = (CategoryPlot) this.chart.getPlot(); CategoryItemRenderer renderer = plot.getRenderer(); StandardCategoryURLGenerator url1 = new StandardCategoryURLGenerator(); renderer.setSeriesItemURLGenerator(0, url1); CategoryURLGenerator url2 = renderer.getItemURLGenerator(0, 0); assertSame(url2, url1); } /** * Create a stacked bar chart with sample data in the range -3 to +3. * * @return The chart. */ private static JFreeChart createChart() { Number[][] data = new Integer[][] {{-3, -2}, {-1, 1}, {2, 3}}; CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", "C", data); return ChartFactory.createStackedBarChart("Stacked Bar Chart", "Domain", "Range", dataset); } /** * A chart change listener. */ static class LocalListener implements ChartChangeListener { /** A flag. */ private boolean flag; /** * Event handler. * * @param event the event. */ @Override public void chartChanged(ChartChangeEvent event) { this.flag = true; } } }
6,478
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
MeterChartTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/MeterChartTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * MeterChartTests.java * -------------------- * (C) Copyright 2005-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 29-Mar-2005 : Version 1 (DG); * */ package org.jfree.chart; import org.jfree.chart.plot.MeterInterval; import org.jfree.chart.plot.MeterPlot; import org.jfree.data.Range; import org.jfree.data.general.DefaultValueDataset; import org.junit.Test; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; /** * Miscellaneous checks for meter charts. */ public class MeterChartTest { /** * Draws the chart with a single range. At one point, this caused a null * pointer exception (fixed now). */ @Test public void testDrawWithNullInfo() { MeterPlot plot = new MeterPlot(new DefaultValueDataset(60.0)); plot.addInterval(new MeterInterval("Normal", new Range(0.0, 80.0))); JFreeChart chart = new JFreeChart(plot); BufferedImage image = new BufferedImage(200, 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); //FIXME we should really assert a value here } }
2,603
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
StrokeMapTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/StrokeMapTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------- * StrokeMapTests.java * ------------------- * (C) Copyright 2006-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 27-Sep-2006 : Version 1 (DG); * */ package org.jfree.chart; import org.junit.Test; import java.awt.BasicStroke; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.fail; /** * Some tests for the {@link StrokeMap} class. */ public class StrokeMapTest { /** * Some checks for the getStroke() method. */ @Test public void testGetStroke() { StrokeMap m1 = new StrokeMap(); assertEquals(null, m1.getStroke("A")); m1.put("A", new BasicStroke(1.1f)); assertEquals(new BasicStroke(1.1f), m1.getStroke("A")); m1.put("A", null); assertEquals(null, m1.getStroke("A")); // a null key should throw an IllegalArgumentException try { m1.getStroke(null); fail("IllegalArgumentException should have been thrown on null argument"); } catch (IllegalArgumentException e) { assertEquals("Null 'key' argument.", e.getMessage()); } } /** * Some checks for the put() method. */ @Test public void testPut() { StrokeMap m1 = new StrokeMap(); m1.put("A", new BasicStroke(1.1f)); assertEquals(new BasicStroke(1.1f), m1.getStroke("A")); // a null key should throw an IllegalArgumentException try { m1.put(null, new BasicStroke(1.1f)); fail("IllegalArgumentException should have been thrown on null parameter"); } catch (IllegalArgumentException e) { assertEquals("Null 'key' argument.", e.getMessage()); } } /** * Some checks for the equals() method. */ @Test public void testEquals() { StrokeMap m1 = new StrokeMap(); StrokeMap m2 = new StrokeMap(); assertEquals(m1, m1); assertEquals(m1, m2); assertFalse(m1.equals(null)); assertFalse(m1.equals("ABC")); m1.put("K1", new BasicStroke(1.1f)); assertFalse(m1.equals(m2)); m2.put("K1", new BasicStroke(1.1f)); assertEquals(m1, m2); m1.put("K2", new BasicStroke(2.2f)); assertFalse(m1.equals(m2)); m2.put("K2", new BasicStroke(2.2f)); assertEquals(m1, m2); m1.put("K2", null); assertFalse(m1.equals(m2)); m2.put("K2", null); assertEquals(m1, m2); } /** * Some checks for cloning. */ @Test public void testCloning() throws CloneNotSupportedException { StrokeMap m1 = new StrokeMap(); StrokeMap m2 = (StrokeMap) m1.clone(); assertEquals(m1, m2); m1.put("K1", new BasicStroke(1.1f)); m1.put("K2", new BasicStroke(2.2f)); m2 = (StrokeMap) m1.clone(); assertEquals(m1, m2); } /** * A check for serialization. */ @Test public void testSerialization1() throws IOException, ClassNotFoundException { StrokeMap m1 = new StrokeMap(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(m1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); StrokeMap m2 = (StrokeMap) in.readObject(); in.close(); assertEquals(m1, m2); } /** * A check for serialization. */ @Test public void testSerialization2() throws IOException, ClassNotFoundException { StrokeMap m1 = new StrokeMap(); m1.put("K1", new BasicStroke(1.1f)); m1.put("K2", new BasicStroke(2.2f)); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(m1); out.close(); ObjectInput in = new ObjectInputStream(new ByteArrayInputStream( buffer.toByteArray())); StrokeMap m2 = (StrokeMap) in.readObject(); in.close(); assertEquals(m1, m2); } }
5,770
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
LegendItemTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/LegendItemTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * -------------------- * LegendItemTests.java * -------------------- * (C) Copyright 2004-2012, by Object Refinery Limited and Contributors. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes * ------- * 04-Jun-2004 : Version 1 (DG); * 10-Dec-2005 : Addded new test to cover bug report 1374328 (DG); * 13-Dec-2006 : Extended testEquals() for new fillPaintTransformer * attribute (DG); * 23-Apr-2008 : Implemented Cloneable (DG); * 17-Jun-2008 : Included new fields in existing tests (DG); * 17-Jun-2012 : Removed JCommon dependencies (DG); * */ package org.jfree.chart; import org.jfree.chart.ui.GradientPaintTransformType; import org.jfree.chart.ui.StandardGradientPaintTransformer; import org.junit.Test; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.GradientPaint; import java.awt.font.TextAttribute; import java.awt.geom.Line2D; import java.awt.geom.Rectangle2D; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInput; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.text.AttributedString; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotSame; import static org.junit.Assert.assertSame; /** * Tests for the {@link LegendItem} class. */ public class LegendItemTest { /** * Confirm that the equals method can distinguish all the required fields. */ @Test public void testEquals() { LegendItem item1 = new LegendItem("Label", "Description", "ToolTip", "URL", true, new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.RED, true, Color.BLUE, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.green); LegendItem item2 = new LegendItem("Label", "Description", "ToolTip", "URL", true, new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.RED, true, Color.BLUE, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.green); assertEquals(item1, item2); assertEquals(item2, item1); item1 = new LegendItem("Label2", "Description", "ToolTip", "URL", true, new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.RED, true, Color.BLUE, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.green); assertFalse(item1.equals(item2)); item2 = new LegendItem("Label2", "Description", "ToolTip", "URL", true, new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.RED, true, Color.BLUE, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.green); assertEquals(item1, item2); item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL", true, new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.RED, true, Color.BLUE, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.green); assertFalse(item1.equals(item2)); item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL", true, new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.RED, true, Color.BLUE, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.green); assertEquals(item1, item2); item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.RED, true, Color.BLUE, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.green); assertFalse(item1.equals(item2)); item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.RED, true, Color.BLUE, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.green); assertEquals(item1, item2); item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), true, Color.RED, true, Color.BLUE, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.green); assertFalse(item1.equals(item2)); item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), true, Color.RED, true, Color.BLUE, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.green); assertEquals(item1, item2); item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.RED, true, Color.BLUE, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.green); assertFalse(item1.equals(item2)); item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.RED, true, Color.BLUE, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.green); assertEquals(item1, item2); item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, true, Color.BLUE, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.green); assertFalse(item1.equals(item2)); item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, true, Color.BLUE, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.green); assertEquals(item1, item2); item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.BLUE, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.green); assertFalse(item1.equals(item2)); item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.BLUE, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.green); assertEquals(item1, item2); item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.yellow, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.green); assertFalse(item1.equals(item2)); item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.yellow, new BasicStroke(1.2f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.green); assertEquals(item1, item2); item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.yellow, new BasicStroke(2.1f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.green); assertFalse(item1.equals(item2)); item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.yellow, new BasicStroke(2.1f), true, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.green); assertEquals(item1, item2); item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.yellow, new BasicStroke(2.1f), false, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.green); assertFalse(item1.equals(item2)); item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.yellow, new BasicStroke(2.1f), false, new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f), Color.green); assertEquals(item1, item2); item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.yellow, new BasicStroke(2.1f), false, new Line2D.Double(4.0, 3.0, 2.0, 1.0), new BasicStroke(2.1f), Color.green); assertFalse(item1.equals(item2)); item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.yellow, new BasicStroke(2.1f), false, new Line2D.Double(4.0, 3.0, 2.0, 1.0), new BasicStroke(2.1f), Color.green); assertEquals(item1, item2); item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.yellow, new BasicStroke(2.1f), false, new Line2D.Double(4.0, 3.0, 2.0, 1.0), new BasicStroke(3.3f), Color.green); assertFalse(item1.equals(item2)); item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.yellow, new BasicStroke(2.1f), false, new Line2D.Double(4.0, 3.0, 2.0, 1.0), new BasicStroke(3.3f), Color.green); assertEquals(item1, item2); item1 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.yellow, new BasicStroke(2.1f), false, new Line2D.Double(4.0, 3.0, 2.0, 1.0), new BasicStroke(3.3f), Color.WHITE ); assertFalse(item1.equals(item2)); item2 = new LegendItem("Label2", "Description2", "ToolTip", "URL", false, new Rectangle2D.Double(4.0, 3.0, 2.0, 1.0), false, Color.BLACK, false, Color.yellow, new BasicStroke(2.1f), false, new Line2D.Double(4.0, 3.0, 2.0, 1.0), new BasicStroke(3.3f), Color.WHITE); assertEquals(item1, item2); // fillPaintTransformer item1.setFillPaintTransformer(new StandardGradientPaintTransformer( GradientPaintTransformType.CENTER_VERTICAL)); assertFalse(item1.equals(item2)); item2.setFillPaintTransformer(new StandardGradientPaintTransformer( GradientPaintTransformType.CENTER_VERTICAL)); assertEquals(item1, item2); // labelFont item1.setLabelFont(new Font("Dialog", Font.PLAIN, 13)); assertFalse(item1.equals(item2)); item2.setLabelFont(new Font("Dialog", Font.PLAIN, 13)); assertEquals(item1, item2); // labelPaint item1.setLabelPaint(Color.RED); assertFalse(item1.equals(item2)); item2.setLabelPaint(Color.RED); assertEquals(item1, item2); // fillPaint item1.setFillPaint(new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.BLUE)); assertFalse(item1.equals(item2)); item2.setFillPaint(new GradientPaint(1.0f, 2.0f, Color.green, 3.0f, 4.0f, Color.BLUE)); assertEquals(item1, item2); // outlinePaint item1.setOutlinePaint(new GradientPaint(1.1f, 2.2f, Color.green, 3.3f, 4.4f, Color.BLUE)); assertFalse(item1.equals(item2)); item2.setOutlinePaint(new GradientPaint(1.1f, 2.2f, Color.green, 3.3f, 4.4f, Color.BLUE)); assertEquals(item1, item2); // linePaint item1.setLinePaint(new GradientPaint(0.1f, 0.2f, Color.green, 0.3f, 0.4f, Color.BLUE)); assertFalse(item1.equals(item2)); item2.setLinePaint(new GradientPaint(0.1f, 0.2f, Color.green, 0.3f, 0.4f, Color.BLUE)); assertEquals(item1, item2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization() throws IOException, ClassNotFoundException { LegendItem item1 = new LegendItem("Item", "Description", "ToolTip", "URL", new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), new GradientPaint( 5.0f, 6.0f, Color.BLUE, 7.0f, 8.0f, Color.gray)); item1.setLabelPaint(new GradientPaint(1.0f, 2.0f, Color.RED, 3.0f, 4.0f, Color.yellow)); item1.setOutlinePaint(new GradientPaint(4.0f, 3.0f, Color.green, 2.0f, 1.0f, Color.RED)); item1.setLinePaint(new GradientPaint(1.0f, 2.0f, Color.WHITE, 3.0f, 4.0f, Color.RED)); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(item1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); LegendItem item2 = (LegendItem) in.readObject(); in.close(); assertEquals(item1, item2); } /** * Serialize an instance, restore it, and check for equality. */ @Test public void testSerialization2() throws IOException, ClassNotFoundException { AttributedString as = new AttributedString("Test String"); as.addAttribute(TextAttribute.FONT, new Font("Dialog", Font.PLAIN, 12)); LegendItem item1 = new LegendItem(as, "Description", "ToolTip", "URL", new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), Color.RED); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); ObjectOutput out = new ObjectOutputStream(buffer); out.writeObject(item1); out.close(); ObjectInput in = new ObjectInputStream( new ByteArrayInputStream(buffer.toByteArray())); LegendItem item2 = (LegendItem) in.readObject(); in.close(); assertEquals(item1, item2); } /** * Basic checks for cloning. */ @Test public void testCloning() throws CloneNotSupportedException { LegendItem item1 = new LegendItem("Item"); LegendItem item2 = (LegendItem) item1.clone(); assertNotSame(item1, item2); assertSame(item1.getClass(), item2.getClass()); assertEquals(item1, item2); // the clone references the same dataset as the original assertSame(item1.getDataset(), item2.getDataset()); } }
17,736
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z
XYStepAreaChartTest.java
/FileExtraction/Java_unseen/akardapolov_ASH-Viewer/jfreechart-fse/src/test/java/org/jfree/chart/XYStepAreaChartTest.java
/* =========================================================== * JFreeChart : a free chart library for the Java(tm) platform * =========================================================== * * (C) Copyright 2000-2012, by Object Refinery Limited and Contributors. * * Project Info: http://www.jfree.org/jfreechart/index.html * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. * Other names may be trademarks of their respective owners.] * * ------------------------- * XYStepAreaChartTests.java * ------------------------- * (C) Copyright 2005-2008, by Object Refinery Limited. * * Original Author: David Gilbert (for Object Refinery Limited); * Contributor(s): -; * * Changes: * -------- * 12-Apr-2005 : Version 1 (DG); * */ package org.jfree.chart; import org.jfree.chart.axis.ValueAxis; import org.jfree.chart.event.ChartChangeEvent; import org.jfree.chart.event.ChartChangeListener; import org.jfree.chart.labels.StandardXYToolTipGenerator; import org.jfree.chart.labels.XYToolTipGenerator; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.XYItemRenderer; import org.jfree.data.Range; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy.XYSeriesCollection; import org.junit.Before; import org.junit.Test; import java.awt.Graphics2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; /** * Some tests for an XY step area chart. */ public class XYStepAreaChartTest { /** A chart. */ private JFreeChart chart; /** * Common test setup. */ @Before public void setUp() { this.chart = createChart(); } /** * Draws the chart with a null info object to make sure that no exceptions * are thrown (a problem that was occurring at one point). */ @Test public void testDrawWithNullInfo() { BufferedImage image = new BufferedImage(200 , 100, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); this.chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null); g2.dispose(); //FIXME we should really assert a value here } /** * Replaces the dataset and checks that it has changed as expected. */ @Test public void testReplaceDataset() { // create a dataset... XYSeries series1 = new XYSeries("Series 1"); series1.add(10.0, 10.0); series1.add(20.0, 20.0); series1.add(30.0, 30.0); XYDataset dataset = new XYSeriesCollection(series1); LocalListener l = new LocalListener(); this.chart.addChangeListener(l); XYPlot plot = (XYPlot) this.chart.getPlot(); plot.setDataset(dataset); assertEquals(true, l.flag); ValueAxis axis = plot.getRangeAxis(); Range range = axis.getRange(); assertTrue("Expecting the lower bound of the range to be around 10: " + range.getLowerBound(), range.getLowerBound() <= 10); assertTrue("Expecting the upper bound of the range to be around 30: " + range.getUpperBound(), range.getUpperBound() >= 30); } /** * Check that setting a tool tip generator for a series does override the * default generator. */ @Test public void testSetSeriesToolTipGenerator() { XYPlot plot = (XYPlot) this.chart.getPlot(); XYItemRenderer renderer = plot.getRenderer(); StandardXYToolTipGenerator tt = new StandardXYToolTipGenerator(); renderer.setSeriesToolTipGenerator(0, tt); XYToolTipGenerator tt2 = renderer.getToolTipGenerator(0, 0); assertSame(tt2, tt); } /** * Create a test chart. * * @return The chart. */ private static JFreeChart createChart() { XYSeries series1 = new XYSeries("Series 1"); series1.add(1.0, 1.0); series1.add(2.0, 2.0); series1.add(3.0, 3.0); XYDataset dataset = new XYSeriesCollection(series1); return ChartFactory.createXYStepAreaChart("Step Chart", "Domain", "Range", dataset); } /** * A chart change listener. */ static class LocalListener implements ChartChangeListener { /** Tracks whether the change event is received. */ private boolean flag; /** * Event handler. * * @param event the event. */ @Override public void chartChanged(ChartChangeEvent event) { this.flag = true; } } }
5,499
Java
.java
akardapolov/ASH-Viewer
156
72
35
2011-05-25T05:22:11Z
2023-12-04T11:03:40Z