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.impl; 41 42 import org.chronicj.BaseTestCase; 43 import org.chronicj.DatePrecision; 44 import org.chronicj.DateRange; 45 import org.chronicj.PrecisionTestRequired; 46 import org.chronicj.TemporalExpression; 47 import org.chronicj.TimePoint; 48 49 import java.util.GregorianCalendar; 50 51 52 /*** 53 * JUnit Test for <code>ArbitraryDateRangeTE</code>. 54 * 55 * @author <a href="mlipper@US-ABP.com">Matthew Lipper</a> 56 * 57 * @see <a href="http://junit.org">JUnit</a> 58 */ 59 public class ArbitraryDateRangeTETest extends BaseTestCase 60 implements PrecisionTestRequired { 61 public boolean supports(DatePrecision precision) { 62 if (DatePrecision.SECOND.equals(precision) || 63 DatePrecision.MILLISECOND.equals(precision)) { 64 return false; 65 } 66 67 return true; 68 } 69 70 public void testDatePrecision() throws Exception { 71 //December 15th, 2003 to January 15th, 2004 72 DateRange aRange = new DateRange(new TimePoint(2003, 12, 31), 73 new TimePoint(2004, 1, 15)); 74 75 TemporalExpression anExpression = new ArbitraryDateRangeTE(aRange); 76 77 //January 1st, 2004 78 assertTrue(anExpression.includes(new TimePoint(2004, 1, 1))); 79 80 //January 16th, 2004 81 assertTrue(!anExpression.includes(new TimePoint(2004, 1, 16))); 82 83 //MixPrecision 84 //3:15am, December 31st, 2003 85 assertTrue(anExpression.includes(new TimePoint(2003, 12, 31, 3, 15))); 86 87 //Composite expression 88 TemporalExpression anotherExpression = new ArbitraryTimePointTE(new TimePoint( 89 2004, 1, 1)); 90 91 IntersectionTE compositeExpression = new IntersectionTE(); 92 93 //January 1st, 2004 94 compositeExpression.add(anExpression).add(anotherExpression); 95 96 //Includes January 1st, 2004 97 assertTrue(compositeExpression.includes(new TimePoint(2004, 1, 1))); 98 99 //Does not includes January 5th, 2004 100 assertTrue(!compositeExpression.includes(new TimePoint(2004, 1, 5))); 101 } 102 103 public void testHourOfDayPrecision() throws Exception { 104 //11(:59)pm February 28th, 2000 to 12:(00)am February 29th, 2000 105 DateRange aRange = new DateRange(new TimePoint( 106 new GregorianCalendar(2000, 1, 28, 23, 59), 107 DatePrecision.HOUR_OF_DAY), 108 new TimePoint(new GregorianCalendar(2000, 1, 29, 0, 0), 109 DatePrecision.HOUR_OF_DAY)); 110 111 TemporalExpression anExpression = new ArbitraryDateRangeTE(aRange); 112 113 //11(:55)pm February 28th, 2000 114 assertTrue(anExpression.includes(new TimePoint(2000, 2, 28, 23))); 115 116 //12(:00)am February 29th, 2000 117 assertTrue(anExpression.includes(new TimePoint(2000, 2, 29, 00))); 118 119 //1(:00)am February 29th, 2000 120 assertTrue(!anExpression.includes(new TimePoint(2000, 2, 29, 1, 00))); 121 } 122 123 public void testMillisecondPrecision() throws Exception { 124 // //11:59:59:997pm December 31st, 1999 to 11:59:999pm December 31st, 125 // 1999 126 // GregorianCalendar partyLike = 127 // new GregorianCalendar(1999, 11, 31, 23, 59, 59); 128 // 129 // partyLike.set(Calendar.MILLISECOND, 997); 130 // 131 // GregorianCalendar its1999 = 132 // new GregorianCalendar(1999, 11, 31, 23, 59, 59); 133 // 134 // its1999.set(Calendar.MILLISECOND, 999); 135 // 136 // DateRange aRange = 137 // new DateRange( 138 // new TimePoint(partyLike, DatePrecision.MILLISECOND), 139 // new TimePoint(its1999, DatePrecision.MILLISECOND)); 140 // 141 // TemporalExpression anExpression = new ArbitraryDateRangeTE(aRange); 142 // 143 // partyLike.add(Calendar.MILLISECOND,1); 144 // 145 // //11:59:59:998pm December 31st, 1999 146 // assertTrue(anExpression.includes(new 147 // TimePoint(partyLike.getTime()))); 148 // 149 // its1999.add(Calendar.MILLISECOND, 1); 150 // 151 // //12:00:00:00pm January 1st, 2000 152 // assertTrue(!anExpression.includes(new 153 // TimePoint(its1999.getTime()))); 154 // 155 } 156 157 public void testMinutePrecision() throws Exception { 158 //11:58pm December 31st, 1999 to 12:01am January 1st,2000 159 DateRange aRange = new DateRange(new TimePoint(1999, 12, 31, 23, 58), 160 new TimePoint(2000, 1, 1, 00, 01)); 161 162 TemporalExpression anExpression = new ArbitraryDateRangeTE(aRange); 163 164 //11:59 December 31st, 1999 165 assertTrue(anExpression.includes(new TimePoint(1999, 12, 31, 23, 59))); 166 167 //12:00am January 1st, 2000 168 assertTrue(anExpression.includes(new TimePoint(2000, 1, 1, 00, 00))); 169 170 //11:58 December 31st, 1999 171 assertTrue(anExpression.includes(new TimePoint(1999, 12, 31, 23, 58))); 172 173 //12:01am January 1st, 2000 174 assertTrue(anExpression.includes(new TimePoint(2000, 1, 1, 00, 01))); 175 176 //12:02pm January 1st, 2000 177 assertTrue(!anExpression.includes(new TimePoint(2000, 1, 1, 00, 02))); 178 179 //12:00am January 1st, 2001 180 assertTrue(!anExpression.includes(new TimePoint(2001, 1, 1, 00, 00))); 181 } 182 183 public void testMonthPrecision() throws Exception { 184 //November 2003 - March, 2004 185 TemporalExpression anExpression = new ArbitraryDateRangeTE(new DateRange( 186 new TimePoint(2003, 11), new TimePoint(2004, 3))); 187 188 //January, 2004 189 assertTrue(anExpression.includes(new TimePoint(2004, 1))); 190 191 //January (1st 12:00am), 2004 192 assertTrue(anExpression.includes(new TimePoint(2004, 1, 1, 00, 01))); 193 194 //March (31st), 2004 195 assertTrue(anExpression.includes(new TimePoint(2004, 3, 31))); 196 197 //March, 2005 198 assertTrue(!anExpression.includes(new TimePoint(2005, 3))); 199 } 200 201 public void testSecondPrecision() throws Exception { 202 // TODO Not implemented 203 } 204 205 public void testYearPrecision() throws Exception { 206 // TODO Auto-generated method stub 207 } 208 }

This page was automatically generated by Maven