Subversion Repository Public Repository

litesoft

Diff Revisions 869 vs 897 for /trunk/Java/core/Anywhere/tests/org/litesoft/core/simpletypes/temporal/UtilDateAdaptorTest.java

Diff revisions: vs.
  @@ -24,8 +24,29 @@
24 24 junit.textui.TestRunner.run( suite() );
25 25 }
26 26
27 + public void test_DST()
28 + {
29 + // UtilDateAdaptor zOrigAdaptor = UtilDateAdaptor.wall( 2013, 3, 17, 20 ); // DST!
30 + // Date zOrigDate = zOrigAdaptor.getWallDate();
31 + // UtilDateAdaptor zRT_Adaptor = new UtilDateAdaptor( zOrigDate, TemporalResolution.ToHour );
32 + // Date zRT_Date = zRT_Adaptor.getWallDate();
33 + // System.out.println( "UtilDateAdaptorTest.test_DST\nCW: " + zOrigDate + " | " + zOrigAdaptor + "\nRT: " + zRT_Date + " | " + zRT_Adaptor );
34 + //
35 + // zOrigAdaptor = UtilDateAdaptor.wall( 2013, 2, 14, 10 ); // !DST
36 + // zOrigDate = zOrigAdaptor.getWallDate();
37 + // zRT_Adaptor = new UtilDateAdaptor( zOrigDate, TemporalResolution.ToHour );
38 + // zRT_Date = zRT_Adaptor.getWallDate();
39 + // System.out.println( "UtilDateAdaptorTest.test_DST\nCW: " + zOrigDate + " | " + zOrigAdaptor + "\nRT: " + zRT_Date + " | " + zRT_Adaptor );
40 +
41 + chkRT( 2013, 3, 17, 20 ); // DST!
42 + chkRT( 2013, 2, 14, 10 ); // !DST
43 + }
44 +
27 45 public void test_RoundTrip()
28 46 {
47 + chkRT( 2013, 2, 15, 12 ); // !DST
48 + chkRT( 2013, 3, 15, 12 ); // DST!
49 +
29 50 chkRT( 1957 );
30 51 chkRT( 1957, 1 );
31 52 chkRT( 1957, 1, 4 );
  @@ -67,58 +88,76 @@
67 88
68 89 public void test_RT_Years()
69 90 {
70 - for ( int i = 1800; i < 2100; i++ )
91 + for ( int zYear = 1800; zYear < 2100; zYear++ )
71 92 {
72 - chkRT( i );
93 + chkRT( zYear );
73 94 }
74 95 }
75 96
76 97 public void test_RT_Months()
77 98 {
78 - for ( int i = 1; i < 12; i++ )
99 + for ( int zMonth = 1; zMonth < 12; zMonth++ )
79 100 {
80 - chkRT( 1957, i );
101 + chkRT( 1957, zMonth );
102 + chkRT( 2000, zMonth );
81 103 }
82 104 }
83 105
84 106 public void test_RT_Days()
85 107 {
86 - for ( int i = 1; i < 12; i++ )
108 + for ( int zMonth = 1; zMonth <= 12; zMonth++ )
87 109 {
88 - chkDays( 1957, i );
89 - chkDays( 2000, i );
110 + chkDays( 1957, zMonth );
111 + chkDays( 2000, zMonth );
90 112 }
91 113 }
92 114
93 115 public void test_RT_Hours()
94 116 {
95 - for ( int i = 0; i < 23; i++ )
117 + for ( int zMonth = 1; zMonth <= 12; zMonth++ )
96 118 {
97 - chkRT( 1957, 1, 4, i );
119 + for ( int zDay = 1; zDay <= 28; zDay++ )
120 + {
121 + for ( int zHour = 0; zHour < 23; zHour++ )
122 + {
123 + chkRT( 1957, zMonth, zDay, zHour );
124 + chkRT( 2000, zMonth, zDay, zHour );
125 + }
126 + }
98 127 }
99 128 }
100 129
101 130 public void test_RT_Mins()
102 131 {
103 - for ( int i = 0; i < 59; i++ )
132 + for ( int zMonth = 1; zMonth <= 12; zMonth++ )
104 133 {
105 - chkRT( 1957, 1, 4, 9, i );
134 + for ( int zDay = 1; zDay <= 28; zDay++ )
135 + {
136 + for ( int zHour = 0; zHour < 23; zHour++ )
137 + {
138 + for ( int zMin = 0; zMin < 59; zMin++ )
139 + {
140 + chkRT( 1957, zMonth, zDay, zHour, zMin );
141 + chkRT( 2000, zMonth, zDay, zHour, zMin );
142 + }
143 + }
144 + }
106 145 }
107 146 }
108 147
109 148 public void test_RT_Secs()
110 149 {
111 - for ( int i = 0; i < 59; i++ )
150 + for ( int zSec = 0; zSec < 59; zSec++ )
112 151 {
113 - chkRT( 1957, 1, 4, 9, 8, i );
152 + chkRT( 1957, 1, 4, 9, 8, zSec );
114 153 }
115 154 }
116 155
117 156 public void test_RT_MilliSecs()
118 157 {
119 - for ( int i = 0; i < 999; i++ )
158 + for ( int zMilli = 0; zMilli < 999; zMilli++ )
120 159 {
121 - chkRT( 1957, 1, 4, 9, 8, 7, i );
160 + chkRT( 1957, 1, 4, 9, 8, 7, zMilli );
122 161 }
123 162 }
124 163
  @@ -133,43 +172,43 @@
133 172 private void chkRT( int pYear )
134 173 {
135 174 chkRT( TemporalResolution.ToYear, //
136 - UtilDateAdaptor.currentWall( pYear ) );
175 + UtilDateAdaptor.wall( pYear ) );
137 176 }
138 177
139 178 private void chkRT( int pYear, int pMonth )
140 179 {
141 180 chkRT( TemporalResolution.ToMonth, //
142 - UtilDateAdaptor.currentWall( pYear, pMonth ) );
181 + UtilDateAdaptor.wall( pYear, pMonth ) );
143 182 }
144 183
145 184 private void chkRT( int pYear, int pMonth, int pDay )
146 185 {
147 186 chkRT( TemporalResolution.ToDay, //
148 - UtilDateAdaptor.currentWall( pYear, pMonth, pDay ) );
187 + UtilDateAdaptor.wall( pYear, pMonth, pDay ) );
149 188 }
150 189
151 190 private void chkRT( int pYear, int pMonth, int pDay, int pHour )
152 191 {
153 192 chkRT( TimeRes.ToHOUR, TemporalResolution.ToHour, //
154 - UtilDateAdaptor.currentWall( pYear, pMonth, pDay, pHour ) );
193 + UtilDateAdaptor.wall( pYear, pMonth, pDay, pHour ) );
155 194 }
156 195
157 196 private void chkRT( int pYear, int pMonth, int pDay, int pHour, int pMin )
158 197 {
159 198 chkRT( TimeRes.ToMIN, TemporalResolution.ToMin, //
160 - UtilDateAdaptor.currentWall( pYear, pMonth, pDay, pHour, pMin ) );
199 + UtilDateAdaptor.wall( pYear, pMonth, pDay, pHour, pMin ) );
161 200 }
162 201
163 202 private void chkRT( int pYear, int pMonth, int pDay, int pHour, int pMin, int pSec )
164 203 {
165 204 chkRT( TimeRes.ToSEC, TemporalResolution.ToSec, //
166 - UtilDateAdaptor.currentWall( pYear, pMonth, pDay, pHour, pMin, pSec ) );
205 + UtilDateAdaptor.wall( pYear, pMonth, pDay, pHour, pMin, pSec ) );
167 206 }
168 207
169 208 private void chkRT( int pYear, int pMonth, int pDay, int pHour, int pMin, int pSec, int pMilliSec )
170 209 {
171 210 chkRT( TimeRes.ToMSEC, TemporalResolution.ToMilliSec, //
172 - UtilDateAdaptor.currentWall( pYear, pMonth, pDay, pHour, pMin, pSec, pMilliSec ) );
211 + UtilDateAdaptor.wall( pYear, pMonth, pDay, pHour, pMin, pSec, pMilliSec ) );
173 212 }
174 213
175 214 private void chkRT( TimeRes pTimeRes, TemporalResolution pTemporalResolution, UtilDateAdaptor pOrigAdaptor )
  @@ -191,17 +230,89 @@
191 230 chkRT( pTemporalResolution, pOrigAdaptor, zRT_Adaptor );
192 231 }
193 232
233 + private interface IntAccessor
234 + {
235 + int get( UtilDateAdaptor pAdaptor );
236 + }
237 +
194 238 private void chkRT( TemporalResolution pTemporalResolution, UtilDateAdaptor pOrigAdaptor, UtilDateAdaptor pRT_Adaptor )
195 239 {
196 - assertEquals( "TemporalResolution", pTemporalResolution, pOrigAdaptor.getTemporalResolution() );
197 - assertEquals( "TemporalResolution", pOrigAdaptor.getTemporalResolution(), pRT_Adaptor.getTemporalResolution() );
240 + assertEquals( "TemporalResolution: " + pOrigAdaptor, pTemporalResolution, pOrigAdaptor.getTemporalResolution() );
241 + assertEquals( "TemporalResolution: " + pOrigAdaptor + " | " + pRT_Adaptor, pOrigAdaptor.getTemporalResolution(), pRT_Adaptor.getTemporalResolution() );
242 +
243 + chkRT( pOrigAdaptor, pRT_Adaptor, "Year", new IntAccessor()
244 + {
245 + @Override
246 + public int get( UtilDateAdaptor pAdaptor )
247 + {
248 + return pAdaptor.getYear();
249 + }
250 + } );
251 + chkRT( pOrigAdaptor, pRT_Adaptor, "Month", new IntAccessor()
252 + {
253 + @Override
254 + public int get( UtilDateAdaptor pAdaptor )
255 + {
256 + return pAdaptor.getMonth();
257 + }
258 + } );
259 + chkRT( pOrigAdaptor, pRT_Adaptor, "Day", new IntAccessor()
260 + {
261 + @Override
262 + public int get( UtilDateAdaptor pAdaptor )
263 + {
264 + return pAdaptor.getDay();
265 + }
266 + } );
267 + chkRT( pOrigAdaptor, pRT_Adaptor, "Hour", new IntAccessor()
268 + {
269 + @Override
270 + public int get( UtilDateAdaptor pAdaptor )
271 + {
272 + return pAdaptor.getHour();
273 + }
274 + } );
275 + chkRT( pOrigAdaptor, pRT_Adaptor, "Min", new IntAccessor()
276 + {
277 + @Override
278 + public int get( UtilDateAdaptor pAdaptor )
279 + {
280 + return pAdaptor.getMin();
281 + }
282 + } );
283 + chkRT( pOrigAdaptor, pRT_Adaptor, "Sec", new IntAccessor()
284 + {
285 + @Override
286 + public int get( UtilDateAdaptor pAdaptor )
287 + {
288 + return pAdaptor.getSec();
289 + }
290 + } );
291 + chkRT( pOrigAdaptor, pRT_Adaptor, "MilliSec", new IntAccessor()
292 + {
293 + @Override
294 + public int get( UtilDateAdaptor pAdaptor )
295 + {
296 + return pAdaptor.getMilliSec();
297 + }
298 + } );
299 + chkRT( pOrigAdaptor, pRT_Adaptor, "ZuluOffsetMins", new IntAccessor()
300 + {
301 + @Override
302 + public int get( UtilDateAdaptor pAdaptor )
303 + {
304 + return pAdaptor.getZuluOffsetMins();
305 + }
306 + } );
307 + }
198 308
199 - assertEquals( "Year", pOrigAdaptor.getYear(), pRT_Adaptor.getYear() );
200 - assertEquals( "Month", pOrigAdaptor.getMonth(), pRT_Adaptor.getMonth() );
201 - assertEquals( "Day", pOrigAdaptor.getHour(), pRT_Adaptor.getHour() );
202 - assertEquals( "Hour", pOrigAdaptor.getHour(), pRT_Adaptor.getHour() );
203 - assertEquals( "Min", pOrigAdaptor.getMin(), pRT_Adaptor.getMin() );
204 - assertEquals( "Sec", pOrigAdaptor.getSec(), pRT_Adaptor.getSec() );
205 - assertEquals( "MilliSec", pOrigAdaptor.getMilliSec(), pRT_Adaptor.getMilliSec() );
309 + private void chkRT( UtilDateAdaptor pOrigAdaptor, UtilDateAdaptor pRT_Adaptor, String pWhat, IntAccessor pAccessor )
310 + {
311 + int zOA_int = pAccessor.get( pOrigAdaptor );
312 + int zRA_int = pAccessor.get( pRT_Adaptor );
313 + if ( zOA_int != zRA_int )
314 + {
315 + assertEquals( "(" + pOrigAdaptor + " <> " + pRT_Adaptor + ") " + pWhat, zOA_int, zRA_int );
316 + }
206 317 }
207 318 }