org.jfree.data.time.Year Java Examples

The following examples show how to use org.jfree.data.time.Year. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OHLCSeriesCollectionTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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);
    assertTrue(c1.equals(c2));
    int h1 = c1.hashCode();
    int h2 = c2.hashCode();
    assertEquals(h1, h2);
}
 
Example #2
Source File: PeriodAxisTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Confirm that the equals() method can distinguish the locale field (which
 * is new in version 1.0.13).
 */
@Test
public void testEqualsWithLocale() {
    PeriodAxis a1 = new PeriodAxis("Test", new Year(2000), new Year(2009),
            TimeZone.getDefault(), Locale.JAPAN);
    PeriodAxis a2 = new PeriodAxis("Test", new Year(2000), new Year(2009),
            TimeZone.getDefault(), Locale.JAPAN);
    assertTrue(a1.equals(a2));
    assertTrue(a2.equals(a1));

    a1 = new PeriodAxis("Test", new Year(2000), new Year(2009),
            TimeZone.getDefault(), Locale.UK);
    assertFalse(a1.equals(a2));
    a2 = new PeriodAxis("Test", new Year(2000), new Year(2009),
            TimeZone.getDefault(), Locale.UK);
    assertTrue(a1.equals(a2));
}
 
Example #3
Source File: OHLCSeriesCollectionTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    assertTrue(c1.equals(c2));
    int h1 = c1.hashCode();
    int h2 = c2.hashCode();
    assertEquals(h1, h2);
}
 
Example #4
Source File: PeriodAxisTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Confirm that the equals() method can distinguish the locale field (which
 * is new in version 1.0.13).
 */
@Test
public void testEqualsWithLocale() {
    PeriodAxis a1 = new PeriodAxis("Test", new Year(2000), new Year(2009),
            TimeZone.getDefault(), Locale.JAPAN);
    PeriodAxis a2 = new PeriodAxis("Test", new Year(2000), new Year(2009),
            TimeZone.getDefault(), Locale.JAPAN);
    assertTrue(a1.equals(a2));
    assertTrue(a2.equals(a1));

    a1 = new PeriodAxis("Test", new Year(2000), new Year(2009),
            TimeZone.getDefault(), Locale.UK);
    assertFalse(a1.equals(a2));
    a2 = new PeriodAxis("Test", new Year(2000), new Year(2009),
            TimeZone.getDefault(), Locale.UK);
    assertTrue(a1.equals(a2));
}
 
Example #5
Source File: TimeSeriesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test the setMaximumItemCount() method to ensure that it removes items 
 * from the series if necessary.
 */
public void testSetMaximumItemCount() {

    TimeSeries s1 = new TimeSeries("S1", Year.class);
    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);

    assertTrue(s1.getItemCount() == 5);
    s1.setMaximumItemCount(3);
    assertTrue(s1.getItemCount() == 3);
    TimeSeriesDataItem item = s1.getDataItem(0);
    assertTrue(item.getPeriod().equals(new Year(2002)));

}
 
Example #6
Source File: PeriodAxisTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Confirm that the equals() method can distinguish the locale field (which
 * is new in version 1.0.13).
 */
@Test
public void testEqualsWithLocale() {
    PeriodAxis a1 = new PeriodAxis("Test", new Year(2000), new Year(2009),
            TimeZone.getDefault(), Locale.JAPAN);
    PeriodAxis a2 = new PeriodAxis("Test", new Year(2000), new Year(2009),
            TimeZone.getDefault(), Locale.JAPAN);
    assertTrue(a1.equals(a2));
    assertTrue(a2.equals(a1));

    a1 = new PeriodAxis("Test", new Year(2000), new Year(2009),
            TimeZone.getDefault(), Locale.UK);
    assertFalse(a1.equals(a2));
    a2 = new PeriodAxis("Test", new Year(2000), new Year(2009),
            TimeZone.getDefault(), Locale.UK);
    assertTrue(a1.equals(a2));
}
 
Example #7
Source File: OHLCSeriesCollectionTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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();
    assertTrue(c1 != c2);
    assertTrue(c1.getClass() == c2.getClass());
    assertTrue(c1.equals(c2));

    // check independence
    s1.setDescription("XYZ");
    assertFalse(c1.equals(c2));
}
 
Example #8
Source File: ChartConstants.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static Class getTimePeriodClass( final String timePeriodStr ) {
  Class retClass = Millisecond.class;
  if ( timePeriodStr.equalsIgnoreCase( SECOND_PERIOD_TYPE_STR ) ) {
    retClass = Second.class;
  } else if ( timePeriodStr.equalsIgnoreCase( MINUTE_PERIOD_TYPE_STR ) ) {
    retClass = Minute.class;
  } else if ( timePeriodStr.equalsIgnoreCase( HOUR_PERIOD_TYPE_STR ) ) {
    retClass = Hour.class;
  } else if ( timePeriodStr.equalsIgnoreCase( DAY_PERIOD_TYPE_STR ) ) {
    retClass = Day.class;
  } else if ( timePeriodStr.equalsIgnoreCase( WEEK_PERIOD_TYPE_STR ) ) {
    retClass = Week.class;
  } else if ( timePeriodStr.equalsIgnoreCase( MONTH_PERIOD_TYPE_STR ) ) {
    retClass = Month.class;
  } else if ( timePeriodStr.equalsIgnoreCase( QUARTER_PERIOD_TYPE_STR ) ) {
    retClass = Quarter.class;
  } else if ( timePeriodStr.equalsIgnoreCase( YEAR_PERIOD_TYPE_STR ) ) {
    retClass = Year.class;
  }
  return retClass;
}
 
Example #9
Source File: TimeSeriesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getMaxY() method.
 */
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);
}
 
Example #10
Source File: TimeSeriesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some more checks for the addOrUpdate() method.
 */
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(new Double(20.09), overwritten.getValue());
    assertEquals(new Double(1.0), ts.getValue(new Year(2009)));

    // changing the overwritten record shouldn't affect the series
    overwritten.setValue(null);
    assertEquals(new Double(1.0), ts.getValue(new Year(2009)));

    TimeSeriesDataItem item = new TimeSeriesDataItem(new Year(2010), 20.10);
    overwritten = ts.addOrUpdate(item);
    assertNull(overwritten);
    assertEquals(new Double(20.10), ts.getValue(new Year(2010)));
    // changing the item that was added should not change the series
    item.setValue(null);
    assertEquals(new Double(20.10), ts.getValue(new Year(2010)));
}
 
Example #11
Source File: OHLCItemTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
public void testSerialization() {
    OHLCItem item1 = new OHLCItem(new Year(2006), 2.0, 4.0, 1.0, 3.0);
    OHLCItem item2 = null;
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(item1);
        out.close();

        ObjectInput in = new ObjectInputStream(
                new ByteArrayInputStream(buffer.toByteArray()));
        item2 = (OHLCItem) in.readObject();
        in.close();
    }
    catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(item1, item2);
}
 
Example #12
Source File: WeekTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A test case for bug 1498805.
 */
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.getDefault());
        assertEquals(53, w.getWeek());
        assertEquals(new Year(2004), w.getYear());
    }
    finally {
        Locale.setDefault(saved);
    }
}
 
Example #13
Source File: TimeSeriesTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
  * Some checks for the getMinY() method.
  */
 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);
}
 
Example #14
Source File: OHLCSeriesCollectionTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    assertTrue(c1.equals(c2));

    // add an empty series
    c1.addSeries(new OHLCSeries("Empty Series"));
    assertFalse(c1.equals(c2));
    c2.addSeries(new OHLCSeries("Empty Series"));
    assertTrue(c1.equals(c2));

    c1.setXPosition(TimePeriodAnchor.END);
    assertFalse(c1.equals(c2));
    c2.setXPosition(TimePeriodAnchor.END);
    assertTrue(c1.equals(c2));

}
 
Example #15
Source File: OHLCItemTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
    assertTrue(item1.equals(item2));
    assertTrue(item2.equals(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);
    assertTrue(item1.equals(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);
    assertTrue(item1.equals(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);
    assertTrue(item1.equals(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);
    assertTrue(item1.equals(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);
    assertTrue(item1.equals(item2));
}
 
Example #16
Source File: OHLCItemTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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();
    assertTrue(item1 != item2);
    assertTrue(item1.getClass() == item2.getClass());
    assertTrue(item1.equals(item2));
}
 
Example #17
Source File: OHLCSeriesTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    boolean pass = false;
    try {
        s1.add(new Year(2006), 1.0, 1.0, 1.0, 1.0);
    }
    catch (SeriesException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #18
Source File: TimeTableXYDatasetTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test clearing data.
 */
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());
}
 
Example #19
Source File: TimeSeriesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check that the item bounds are determined correctly when there is a
 * maximum item count and a new value is added.
 */
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);
}
 
Example #20
Source File: OHLCSeriesCollectionTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    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) 
            TestUtilities.serialised(c1);
    assertEquals(c1, c2);
}
 
Example #21
Source File: OHLCSeriesTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #22
Source File: OHLCSeriesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check that the maximum item count can be applied retrospectively.
 */
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));
}
 
Example #23
Source File: TimePeriodValuesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add a value to series A for 1999.  It should be added at index 0.
 */
public void testAddValue() {

    TimePeriodValues tpvs = new TimePeriodValues("Test");
    try {
        tpvs.add(new Year(1999), new Integer(1));
    }
    catch (SeriesException e) {
        System.err.println("Problem adding to series.");
    }

    int value = tpvs.getValue(0).intValue();
    assertEquals(1, value);

}
 
Example #24
Source File: PeriodAxis.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new axis.
 *
 * @param label  the axis label (<code>null</code> permitted).
 * @param first  the first time period in the axis range
 *               (<code>null</code> not permitted).
 * @param last  the last time period in the axis range
 *              (<code>null</code> not permitted).
 * @param timeZone  the time zone (<code>null</code> not permitted).
 * @param locale  the locale (<code>null</code> not permitted).
 *
 * @since 1.0.13
 */
public PeriodAxis(String label, RegularTimePeriod first,
        RegularTimePeriod last, TimeZone timeZone, Locale locale) {
    super(label, null);
    ParamChecks.nullNotPermitted(timeZone, "timeZone");
    ParamChecks.nullNotPermitted(locale, "locale");
    this.first = first;
    this.last = last;
    this.timeZone = timeZone;
    this.locale = locale;
    this.calendar = Calendar.getInstance(timeZone, locale);
    this.first.peg(this.calendar);
    this.last.peg(this.calendar);
    this.autoRangeTimePeriodClass = first.getClass();
    this.majorTickTimePeriodClass = first.getClass();
    this.minorTickMarksVisible = false;
    this.minorTickTimePeriodClass = RegularTimePeriod.downsize(
            this.majorTickTimePeriodClass);
    setAutoRange(true);
    this.labelInfo = new PeriodAxisLabelInfo[2];
    SimpleDateFormat df0 = new SimpleDateFormat("MMM", locale);
    df0.setTimeZone(timeZone);
    this.labelInfo[0] = new PeriodAxisLabelInfo(Month.class, df0);
    SimpleDateFormat df1 = new SimpleDateFormat("yyyy", locale);
    df1.setTimeZone(timeZone);
    this.labelInfo[1] = new PeriodAxisLabelInfo(Year.class, df1);
}
 
Example #25
Source File: OHLCItemTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the constructor.
 */
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);
}
 
Example #26
Source File: OHLCSeriesTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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());
}
 
Example #27
Source File: OHLCSeriesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the clear() method.
 */
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());
}
 
Example #28
Source File: OHLCSeriesTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #29
Source File: OHLCSeriesTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #30
Source File: TimeSeriesTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add a value to series A for 1999.  It should be added at index 0.
 */
public void testAddValue() {

    try {
        this.seriesA.add(new Year(1999), new Integer(1));
    }
    catch (SeriesException e) {
        System.err.println("Problem adding to series.");
    }

    int value = this.seriesA.getValue(0).intValue();
    assertEquals(1, value);

}