⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 segmentedtimelinetests.java

📁 jfreechart-1.0.12 开发包和文档等
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     * inside one segment as well as adjacent segments are verified.     * @param timeline the timeline to use for verifications.     */    public void verifyOneSegment(SegmentedTimeline timeline) {        for (long testCycle = TEST_CYCLE_START; testCycle < TEST_CYCLE_END;             testCycle += TEST_CYCLE_INC) {            // get two consecutive segments for various tests            SegmentedTimeline.Segment segment1 = timeline.getSegment(                    this.monday.getTime().getTime() + testCycle);            SegmentedTimeline.Segment segment2 = timeline.getSegment(                    segment1.getSegmentEnd() + 1);            // verify segments are consecutive and correct            assertEquals(segment1.getSegmentNumber() + 1,                    segment2.getSegmentNumber());            assertEquals(segment1.getSegmentEnd() + 1,                    segment2.getSegmentStart());            assertEquals(segment1.getSegmentStart()                    + timeline.getSegmentSize() - 1, segment1.getSegmentEnd());            assertEquals(segment1.getSegmentStart() + timeline.getSegmentSize(),                    segment2.getSegmentStart());            assertEquals(segment1.getSegmentEnd() + timeline.getSegmentSize(),                    segment2.getSegmentEnd());            // verify various indices inside a segment are the same segment            long delta;            if (timeline.getSegmentSize() > 1000000) {                delta = timeline.getSegmentSize() / 10000;            }            else if (timeline.getSegmentSize() > 100000) {                delta = timeline.getSegmentSize() / 1000;            }            else if (timeline.getSegmentSize() > 10000) {                delta = timeline.getSegmentSize() / 100;            }            else if (timeline.getSegmentSize() > 1000) {                delta = timeline.getSegmentSize() / 10;            }            else if (timeline.getSegmentSize() > 100) {                delta = timeline.getSegmentSize() / 5;            }            else {                delta = 1;            }            long start = segment1.getSegmentStart() + delta;            long end = segment1.getSegmentStart()                       + timeline.getSegmentSize() - 1;            SegmentedTimeline.Segment lastSeg = timeline.getSegment(                    segment1.getSegmentStart());            SegmentedTimeline.Segment seg;            for (long i = start; i < end; i += delta) {                seg = timeline.getSegment(i);                assertEquals(lastSeg.getSegmentNumber(),                        seg.getSegmentNumber());                assertEquals(lastSeg.getSegmentStart(), seg.getSegmentStart());                assertEquals(lastSeg.getSegmentEnd(), seg.getSegmentEnd());                assertTrue(lastSeg.getMillisecond() < seg.getMillisecond());                lastSeg = seg;            }            // try next segment            seg = timeline.getSegment(end + 1);            assertEquals(segment2.getSegmentNumber(), seg.getSegmentNumber());            assertEquals(segment2.getSegmentStart(), seg.getSegmentStart());            assertEquals(segment2.getSegmentEnd(), seg.getSegmentEnd());        }    }    //////////////////////////////////////////////////////////////////////////    // test inc methods    //////////////////////////////////////////////////////////////////////////    /**     * Tests the inc methods on the msTimeline.     */    public void testMsInc() {        verifyInc(this.msTimeline);    }    /**     * Tests the inc methods on the msTimeline.     */    public void testMs2Inc() {        verifyInc(this.ms2Timeline);    }    /**     * Tests the inc methods on the Monday through Friday timeline.     */    public void testMondayThroughFridayInc() {        verifyInc(this.mondayFridayTimeline);    }    /**     * Tests the inc methods on the Fifteen minute timeline.     */    public void testFifteenMinInc() {        verifyInc(this.fifteenMinTimeline);    }    /**     * Tests the inc methods.     * @param timeline the timeline to use for verifications.     */    public void verifyInc(SegmentedTimeline timeline) {        for (long testCycle = TEST_CYCLE_START; testCycle < TEST_CYCLE_END;             testCycle += TEST_CYCLE_INC) {            long m = timeline.getSegmentSize();            SegmentedTimeline.Segment segment = timeline.getSegment(testCycle);            SegmentedTimeline.Segment seg1 = segment.copy();            for (int i = 0; i < 1000; i++) {                // test inc() method                SegmentedTimeline.Segment seg2 = seg1.copy();                seg2.inc();                if ((seg1.getSegmentEnd() + 1) != seg2.getSegmentStart()) {                    // logically consecutive segments non-physically consecutive                    // (with non-contained time in between)                    assertTrue(!timeline.containsDomainRange(                            seg1.getSegmentEnd() + 1,                            seg2.getSegmentStart() - 1));                    assertEquals(0, (seg2.getSegmentStart()                            - seg1.getSegmentStart()) % m);                    assertEquals(0, (seg2.getSegmentEnd()                            - seg1.getSegmentEnd()) % m);                    assertEquals(0, (seg2.getMillisecond()                            - seg1.getMillisecond()) % m);                }                else {                    // physically consecutive                    assertEquals(seg1.getSegmentStart() + m,                            seg2.getSegmentStart());                    assertEquals(seg1.getSegmentEnd() + m,                            seg2.getSegmentEnd());                    assertEquals(seg1.getMillisecond() + m,                            seg2.getMillisecond());                }                // test inc(n) method                SegmentedTimeline.Segment seg3 = seg1.copy();                SegmentedTimeline.Segment seg4 = seg1.copy();                for (int j = 0; j < i; j++) {                    seg3.inc();                }                seg4.inc(i);                assertEquals(seg3.getSegmentStart(), seg4.getSegmentStart());                assertEquals(seg3.getSegmentEnd(), seg4.getSegmentEnd());                assertEquals(seg3.getMillisecond(), seg4.getMillisecond());                // go to another segment to continue test                seg1.inc();            }        }    }    //////////////////////////////////////////////////////////////////////////    // main include and excluded segments    //////////////////////////////////////////////////////////////////////////    /**     * Tests that the msTimeline's included and excluded     * segments are being calculated correctly.     */    public void testMsIncludedAndExcludedSegments() {        verifyIncludedAndExcludedSegments(this.msTimeline, 0);    }    /**     * Tests that the ms2Timeline's included and excluded     * segments are being calculated correctly.     */    public void testMs2IncludedAndExcludedSegments() {        verifyIncludedAndExcludedSegments(this.ms2Timeline, 1);    }    /**     * Tests that the Monday through Friday timeline's included and excluded     * segments are being calculated correctly. The test is performed starting     * on the first monday after 1/1/2000 and for five years.     */    public void testMondayThroughFridayIncludedAndExcludedSegments() {        verifyIncludedAndExcludedSegments(this.mondayFridayTimeline,                this.monday.getTime().getTime());    }    /**     * Tests that the Fifteen-Min timeline's included and excluded     * segments are being calculated correctly. The test is performed starting     * on the first monday after 1/1/2000 and for five years.     */    public void testFifteenMinIncludedAndExcludedSegments() {        verifyIncludedAndExcludedSegments(this.fifteenMinTimeline,                this.monday9am.getTime().getTime());    }    /**     * Tests that a timeline's included and excluded segments are being     * calculated correctly.     *     * @param timeline the timeline to verify     * @param n the first segment number to start verifying     */    public void verifyIncludedAndExcludedSegments(SegmentedTimeline timeline,                                                  long n) {        // clear any exceptions in this timeline        timeline.setExceptionSegments(new java.util.ArrayList());        // test some included and excluded segments        SegmentedTimeline.Segment segment = timeline.getSegment(n);        for (int i = 0; i < 1000; i++) {            int d = (i % timeline.getGroupSegmentCount());            if (d < timeline.getSegmentsIncluded()) {                // should be an included segment                assertTrue(segment.inIncludeSegments());                assertTrue(!segment.inExcludeSegments());                assertTrue(!segment.inExceptionSegments());            }            else {                // should be an excluded segment                assertTrue(!segment.inIncludeSegments());                assertTrue(segment.inExcludeSegments());                assertTrue(!segment.inExceptionSegments());            }            segment.inc();        }    }    //////////////////////////////////////////////////////////////////////////    // test exception segments    //////////////////////////////////////////////////////////////////////////    /**     * Tests methods related to exceptions methods in the msTimeline.     *     * @throws ParseException if there is a parsing error.     */    public void testMsExceptionSegments() throws ParseException {        verifyExceptionSegments(this.msTimeline, MS_EXCEPTIONS, NUMBER_FORMAT);    }    /**     * Tests methods related to exceptions methods in the ms2BaseTimeline.     *     * @throws ParseException if there is a parsing error.     */    public void testMs2BaseTimelineExceptionSegments() throws ParseException {        verifyExceptionSegments(this.ms2BaseTimeline,                MS2_BASE_TIMELINE_EXCEPTIONS, NUMBER_FORMAT);    }    /**     * Tests methods related to exceptions methods in the mondayFridayTimeline.     *     * @throws ParseException if there is a parsing error.     */    public void testMondayThoughFridayExceptionSegments()        throws ParseException {        verifyExceptionSegments(this.mondayFridayTimeline,                US_HOLIDAYS, DATE_FORMAT);    }    /**     * Tests methods related to exceptions methods in the fifteenMinTimeline.     *     * @throws ParseException if there is a parsing error.     */    public void testFifteenMinExceptionSegments() throws ParseException {        verifyExceptionSegments(this.fifteenMinTimeline,                FIFTEEN_MIN_EXCEPTIONS, DATE_TIME_FORMAT);    }    /**     * Tests methods related to adding exceptions.     *     * @param timeline the timeline to verify     * @param exceptionString array of Strings that represent the exceptions     * @param fmt Format object that can parse the exceptionString strings     *     * @throws ParseException if there is a parsing error.     */    public void verifyExceptionSegments(SegmentedTimeline timeline,                                        String[] exceptionString,                                        Format fmt)        throws ParseException {        // fill in the exceptions        long[] exception = verifyFillInExceptions(timeline, exceptionString,                fmt);        int m = exception.length;        // verify list of exceptions        assertEquals(exception.length, timeline.getExceptionSegments().size());        SegmentedTimeline.Segment lastSegment = timeline.getSegment(                exception[m - 1]);        for (int i = 0; i < m; i++) {            SegmentedTimeline.Segment segment = timeline.getSegment(                    exception[i]);            assertTrue(segment.inExceptionSegments());            // include current exception and last one            assertEquals(m - i, timeline.getExceptionSegmentCount(                    segment.getSegmentStart(), lastSegment.getSegmentEnd()));            // exclude current exception and last one            assertEquals(Math.max(0, m - i - 2),                    timeline.getExceptionSegmentCount(exception[i] + 1,                    exception[m - 1] - 1));        }    }    //////////////////////////////////////////////////////////////////////////    // test timeline translations    //////////////////////////////////////////////////////////////////////////    /**     * Tests translations for 1-ms timeline     *     * @throws ParseException if there is a parsing error.     */    public void testMsTranslations() throws ParseException {        verifyFillInExceptions(this.msTimeline, MS_EXCEPTIONS, NUMBER_FORMAT);        verifyTranslations(this.msTimeline, 0);    }    /**     * Tests translations for the base timeline used for the ms2Timeline     *     * @throws ParseException if there is a parsing error.     */    public void testMs2BaseTimelineTranslations() throws ParseException {        verifyFillInExceptions(this.ms2BaseTimeline,                MS2_BASE_TIMELINE_EXCEPTIONS, NUMBER_FORMAT);        verifyTranslations(this.ms2BaseTimeline, 0);    }    /**     * Tests translations for the Monday through Friday timeline     *     * @throws ParseException if there is a parsing error.     */    public void testMs2Translations() throws ParseException {        fillInBaseTimelineExceptions(this.ms2Timeline,                MS2_BASE_TIMELINE_EXCEPTIONS, NUMBER_FORMAT);        fillInBaseTimelineExclusionsAsExceptions(this.ms2Timeline, 0, 5000);        verifyTranslations(this.ms2Timeline, 1);    }    /**     * Tests translations for the Monday through Friday timeline     *     * @throws ParseException if there is a parsing error.     */    public void textMondayThroughFridayTranslations() throws ParseException {        verifyFillInExceptions(this.mondayFridayTimeline, US_HOLIDAYS,                DATE_FORMAT);        verifyTranslations(this.mondayFridayTimeline,                this.monday.getTime().getTime());    }    /**     * Tests translations for the Fifteen Min timeline     *     * @throws ParseException if there is a parsing error.     */    public void testFifteenMinTranslations() throws ParseException {        verifyFillInExceptions(this.fifteenMinTimeline,                FIFTEEN_MIN_EXCEPTIONS, DATE_TIME_FORMAT);        fillInBaseTimelineExceptions(this.fifteenMinTimeline,                US_HOLIDAYS, DATE_FORMAT);        fillInBaseTimelineExclusionsAsExceptions(this.fifteenMinTimeline,                this.monday9am.getTime().getTime(),                this.monday9am.getTime().getTime() + FIVE_YEARS);        verifyTranslations(this.fifteenMinTimeline,                this.monday9am.getTime().getTime());    }    /**     * Tests translations between timelines.     *     * @param timeline the timeline to use for verifications.     * @param startTest  ??.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -