?? segmentedtimelinetests.java
字號:
/* ======================================
* JFreeChart : a free Java chart library
* ======================================
*
* Project Info: http://www.jfree.org/jfreechart/index.html
* Project Lead: David Gilbert (david.gilbert@object-refinery.com);
*
* (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
*
* 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., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* ----------------------------
* SegmentedTimelineTests.java
* ----------------------------
* (C) Copyright 2003 by Bill Kelemen and Contributors.
*
* Original Author: Bill Kelemen;
* Contributor(s): ;
*
* $Id: SegmentedTimelineTests.java,v 1.8 2003/09/11 07:42:12 mungady Exp $
*
* Changes
* -------
* 24-May-2003 : Version 1 (BK);
*
*/
package org.jfree.chart.axis.junit;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.text.Format;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Iterator;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.jfree.chart.axis.SegmentedTimeline;
/**
* JUnit Tests for the {@link SegmentedTimeline} class.
*
* @author Bill Kelemen
*/
public class SegmentedTimelineTests extends TestCase {
/** These constants control test cycles in the validateXXXX methods. */
private static final int TEST_CYCLE_START = 0;
/** These constants control test cycles in the validateXXXX methods. */
private static final int TEST_CYCLE_END = 1000;
/** These constants control test cycles in the validateXXXX methods. */
private static final int TEST_CYCLE_INC = 55;
/** Number of ms in five years */
private static final long FIVE_YEARS = 5 * 365 * SegmentedTimeline.DAY_SEGMENT_SIZE;
/** Number format object for ms tests. */
private static final NumberFormat NUMBER_FORMAT = NumberFormat.getNumberInstance();
/** Date format object for Monday through Friday tests. */
private static final SimpleDateFormat DATE_FORMAT;
/** Date format object 9:00 AM to 4:00 PM tests. */
private static final SimpleDateFormat DATE_TIME_FORMAT;
/** Some ms exceptions for ms testing. */
private static final String[] MS_EXCEPTIONS =
{"0", "2", "4", "10", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24",
"47", "58", "100", "101"};
/** Some ms4 exceptions for ms testing. */
private static final String[] MS2_BASE_TIMELINE_EXCEPTIONS =
{"0", "8", "16", "24", "32", "40", "48", "56", "64", "72", "80", "88", "96", "104",
"112", "120", "128", "136"};
/** US non-trading dates in 2000 through 2002 to test exceptions. */
private static final String[] US_HOLIDAYS =
{"2000-01-17", "2000-02-21", "2000-04-21", "2000-05-29", "2000-07-04",
"2000-09-04", "2000-11-23", "2000-12-25", "2001-01-01", "2001-01-15",
"2001-02-19", "2001-04-13", "2001-05-28", "2001-07-04", "2001-09-03",
"2001-09-11", "2001-09-12", "2001-09-13", "2001-09-14", "2001-11-22",
"2001-12-25", "2002-01-01", "2002-01-21", "2002-02-18", "2002-03-29",
"2002-05-27", "2002-07-04", "2002-09-02", "2002-11-28", "2002-12-25"};
/** Some test exceptions for the fifteen min timeline. */
private static final String[] FIFTEEN_MIN_EXCEPTIONS =
{"2000-01-10 09:00:00", "2000-01-10 09:15:00", "2000-01-10 09:30:00",
"2000-01-10 09:45:00", "2000-01-10 10:00:00", "2000-01-10 10:15:00",
"2000-02-15 09:00:00", "2000-02-15 09:15:00", "2000-02-15 09:30:00",
"2000-02-15 09:45:00", "2000-02-15 10:00:00", "2000-02-15 10:15:00",
"2000-02-16 11:00:00", "2000-02-16 11:15:00", "2000-02-16 11:30:00",
"2000-02-16 11:45:00", "2000-02-16 12:00:00", "2000-02-16 12:15:00",
"2000-02-16 12:30:00", "2000-02-16 12:45:00", "2000-02-16 01:00:00",
"2000-02-16 01:15:00", "2000-02-16 01:30:00", "2000-02-16 01:45:00",
"2000-05-17 11:45:00", "2000-05-17 12:00:00", "2000-05-17 12:15:00",
"2000-05-17 12:30:00", "2000-05-17 12:45:00", "2000-05-17 01:00:00",
"2000-05-17 01:15:00", "2000-05-17 01:30:00", "2000-05-17 01:45:00",
"2000-05-17 02:00:00", "2000-05-17 02:15:00", "2000-05-17 02:30:00",
"2000-05-17 02:45:00", "2000-05-17 03:00:00", "2000-05-17 03:15:00",
"2000-05-17 03:30:00", "2000-05-17 03:45:00", "2000-05-17 04:00:00"};
/** Our 1-ms test timeline using 5 included and 2 excluded segments. */
private SegmentedTimeline msTimeline;
/** Our 1-ms test timeline (with baseTimeline) using 2 included and 2 excluded segments. */
private SegmentedTimeline ms2Timeline;
/** Our 4-ms test base timeline for ms2Timeline using 1 included and 1 excluded segments */
private SegmentedTimeline ms2BaseTimeline;
/** Our test Monday through Friday test timeline. */
private SegmentedTimeline mondayFridayTimeline;
/** Our 9:00 AM to 4:00 PM fifteen minute timeline. */
private SegmentedTimeline fifteenMinTimeline;
/** ms from 1970-01-01 to first monday after 2001-01-01. */
private Calendar monday;
/** ms from 1970-01-01 to 9 am first monday after 2001-01-01. */
private Calendar monday9am;
/** Static initialization block. */
static {
DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
DATE_FORMAT.setTimeZone(SegmentedTimeline.NO_DST_TIME_ZONE);
DATE_TIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
DATE_TIME_FORMAT.setTimeZone(SegmentedTimeline.NO_DST_TIME_ZONE);
}
/**
* Returns the tests as a test suite.
*
* @return the test suite.
*/
public static Test suite() {
return new TestSuite(SegmentedTimelineTests.class);
}
/**
* Constructs a new set of tests.
*
* @param name the name of the tests.
*/
public SegmentedTimelineTests(String name) {
super(name);
}
/**
* Sets up the fixture, for example, open a network connection.
* This method is called before a test is executed.
*
* @throws Exception if there is a problem.
*/
protected void setUp() throws Exception {
// setup our test timelines
//
// Legend for comments below:
// <spaces> = Segments included in the final timeline
// EE = Excluded segments via timeline rules
// xx = Exception segments inherited from base timeline exclusions
// 1-ms test timeline using 5 included and 2 excluded segments.
//
// timeline start time = 0
// |
// v
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 ...
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+...
// | | | | | |EE|EE| | | | | |EE|EE| | | | | | |EE|EE| <-- msTimeline
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+...
// \_________ ________/ \_/
// \/ |
// segment group segment size = 1 ms
//
msTimeline = new SegmentedTimeline(1, 5, 2);
msTimeline.setStartTime(0);
// 4-ms test base timeline for ms2Timeline using 1 included and 1 excluded segments
//
// timeline start time = 0
// |
// v
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ...
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+...
// | | | | |EE|EE|EE|EE| | | | |EE|EE|EE|EE| | | | | <-- ms2BaseTimeline
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+...
// \__________ _________/ \____ _____/
// \/ \/
// segment group segment size = 4 ms
//
ms2BaseTimeline = new SegmentedTimeline(4, 1, 1);
ms2BaseTimeline.setStartTime(0);
// 1-ms test timeline (with a baseTimeline) using 2 included and 2 excluded segments
// centered inside each base segment
//
// The ms2Timeline without a base would look like this:
//
// timeline start time = 1
// |
// v
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ...
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+...
// |EE| | |EE|EE| | |EE|EE| | |EE|EE| | |EE|EE| | |EE| <-- ms2Timeline
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+...
// \____ _____/ \_/
// \/ |
// segment group segment size = 1 ms
//
// With the base timeline some originally included segments are now removed (see "xx"
// below):
//
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ...
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+...
// |EE| | |EE|EE|xx|xx|EE|EE| | |EE|EE|xx|xx|EE|EE| | |EE| <-- ms2Timeline
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+...
// | | | | |EE|EE|EE|EE| | | | |EE|EE|EE|EE| | | | | <-- ms2BaseTimeline
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+...
//
ms2Timeline = new SegmentedTimeline(1, 2, 2);
ms2Timeline.setStartTime(1);
ms2Timeline.setBaseTimeline(ms2BaseTimeline);
// test monday though friday timeline
mondayFridayTimeline = SegmentedTimeline.newMondayThroughFridayTimeline();
// test 9am-4pm Monday through Friday timeline
fifteenMinTimeline = SegmentedTimeline.newFifteenMinuteTimeline();
// find first Monday after 2001-01-01
Calendar cal = new GregorianCalendar(SegmentedTimeline.NO_DST_TIME_ZONE);
cal.set(2001, 0, 1, 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
while (cal.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
cal.add(Calendar.DATE, 1);
}
monday = (Calendar) cal.clone();
// calculate 9am on the first Monday after 2001-01-01
cal.add(Calendar.HOUR, 9);
monday9am = (Calendar) cal.clone();
}
/**
* Tears down the fixture, for example, close a network connection.
* This method is called after a test is executed.
*
* @throws Exception if there is a problem.
*/
protected void tearDown() throws Exception {
}
//////////////////////////////////////////////////////////////////////////
// test construction process
//////////////////////////////////////////////////////////////////////////
/**
* Tests that the new method that created the msTimeline segmented
* timeline did so correctly.
*/
public void testMsSegmentedTimeline() {
// verify attributes set during object construction
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -