예제 #1
0
  /** 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);
    assertTrue(item1.equals(item2));
    assertTrue(item2.equals(item1));

    item1.setValue(new Integer(5));
    assertFalse(item1.equals(item2));
    item2.setValue(new Integer(5));
    assertTrue(item1.equals(item2));
  }
 /**
  * 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);
   assertTrue(item.equals(series.getDataItem(0)));
   item.setValue(new Double(99.9));
   assertFalse(item.equals(series.getDataItem(0)));
 }
  /** 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(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)));
  }