/** Set up a quarter equal to Q1 1900. Request the previous quarter, it should be null. */
  public void testClone() {

    TimePeriodValues series = new TimePeriodValues("Test Series");

    RegularTimePeriod jan1st2002 = new Day(1, MonthConstants.JANUARY, 2002);
    try {
      series.add(jan1st2002, new Integer(42));
    } catch (SeriesException e) {
      System.err.println("Problem adding to collection.");
    }

    TimePeriodValues clone = null;
    try {
      clone = (TimePeriodValues) series.clone();
      clone.setKey("Clone Series");
      try {
        clone.update(0, new Integer(10));
      } catch (SeriesException e) {
        System.err.println("Problem updating series.");
      }
    } catch (CloneNotSupportedException e) {
      assertTrue(false);
    }

    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. */
  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);
  }
  /** Some checks for the add() methods. */
  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
    boolean pass = false;
    try {
      tpv.add((TimePeriodValue) null);
    } catch (IllegalArgumentException e) {
      pass = true;
    }
    assertTrue(pass);
  }