1 /*
2 * ==================================================================== The
3 * Apache Software License, Version 1.1
4 *
5 * Copyright (c) 2003 Digital Clash LLC. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met: 1.
9 * Redistributions of source code must retain the above copyright notice, this
10 * list of conditions and the following disclaimer. 2. Redistributions in
11 * binary form must reproduce the above copyright notice, this list of
12 * conditions and the following disclaimer in the documentation and/or other
13 * materials provided with the distribution. 3. The end-user documentation
14 * included with the redistribution, if any, must include the following
15 * acknowledgment: "This product includes software developed by the ChronicJ
16 * team (http://www.chronicj.org/)." Alternately, this acknowledgment may
17 * appear in the software itself, if and wherever such third-party
18 * acknowledgments normally appear. 4. The names "ChronicJ" and "Digital Clash"
19 * not be used to endorse or promote products derived from this software
20 * without prior written permission. For written permission, please contact
21 * info@digitalclash.com. 5. Products derived from this software may not be
22 * called "ChronicJ", "Digital Clash", nor may "ChronicJ" or "Digital Clash"
23 * appear in their name, without prior written permission of Digital Clash LLC.
24 *
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
26 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
27 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 * ==================================================================== This
36 * product includes software developed by the by the Apache Software Foundation
37 * (http://www.apache.org/).
38 * ====================================================================
39 */
40 package org.chronicj;
41
42 import java.util.GregorianCalendar;
43
44
45 /***
46 * RangeIterator unit tests.
47 *
48 * @author <a href="mlipper@US-ABP.com">Matthew Lipper</a>
49 *
50 * @see <a href="http://junit.org">JUnit</a>
51 */
52 public class RangeIteratorTest extends BaseTestCase {
53 public void testHasNext() {
54 /* ### Minute precision ### */
55
56 //3:00am to 3:02am, December 12th, 2003
57 DateRange aRange = new DateRange(new TimePoint(2003, 12, 12, 3, 0),
58 new TimePoint(2003, 12, 12, 3, 2));
59 print(aRange);
60
61 RangeIterator iter = new RangeIterator(aRange);
62 assertTrue(iter.hasNext());
63
64 //index-> 3:00am to 3:01am
65 print((DateRange) iter.next());
66
67 //index-> 3:01am to 3:02am
68 print((DateRange) iter.next());
69 assertTrue(!iter.hasNext());
70 }
71
72 public void testNext() {
73 /* ### Hour precision ### */
74
75 //12:00am February 1st to 12:00am, February 2nd, 2004
76 DateRange aRange = new DateRange(new TimePoint(
77 new GregorianCalendar(2004, 2, 1, 12, 0),
78 DatePrecision.HOUR_OF_DAY),
79 new TimePoint(new GregorianCalendar(2004, 2, 2, 12, 0),
80 DatePrecision.HOUR_OF_DAY));
81 int count = 0;
82
83 for (RangeIterator iter = new RangeIterator(aRange); iter.hasNext();
84 count++) {
85 DateRange aSubRange = (DateRange) iter.next();
86
87 print("index: " + count + " ", aSubRange);
88 }
89
90 assertTrue(24 == count);
91 }
92
93 public void testRemove() {
94 //May to July, 1812
95 DateRange aRange = new DateRange(new TimePoint(1812, 5),
96 new TimePoint(1812, 7));
97
98 for (RangeIterator iter = new RangeIterator(aRange); iter.hasNext();) {
99 DateRange aSubRange = (DateRange) iter.next();
100 print(aSubRange);
101
102 try {
103 iter.remove();
104 fail("Call to RangeIterator#remove() should not succeed.");
105 } catch (UnsupportedOperationException expected) {
106 continue;
107 }
108 }
109 }
110
111 public void testMonthPrecision() {
112 //October 2003 to February 2004
113 DateRange aRange = new DateRange(new TimePoint(
114 new GregorianCalendar(2003, 9, 28), DatePrecision.DATE),
115 new TimePoint(new GregorianCalendar(2004, 1, 14),
116 DatePrecision.DATE));
117 int count = 0;
118
119 for (RangeIterator iter = new RangeIterator(aRange); iter.hasNext();
120 count++) {
121 DateRange aSubRange = (DateRange) iter.next();
122 print("index: " + count + " ", aSubRange);
123 }
124 }
125 }
This page was automatically generated by Maven