001: /*
002: *******************************************************************************
003: * Copyright (C) 1996-2005, International Business Machines Corporation and *
004: * others. All Rights Reserved. *
005: *******************************************************************************
006: *
007: */
008:
009: package com.ibm.icu.dev.test.timescale;
010:
011: import com.ibm.icu.math.BigDecimal;
012: import com.ibm.icu.util.UniversalTimeScale;
013: import com.ibm.icu.dev.test.TestFmwk;
014:
015: /**
016: * @author Owner
017: *
018: * TODO To change the template for this generated type comment go to
019: * Window - Preferences - Java - Code Style - Code Templates
020: */
021: public class TimeScaleAPITest extends TestFmwk {
022:
023: /**
024: *
025: */
026: public TimeScaleAPITest() {
027: }
028:
029: public void TestBigDecimalFromBigDecimal() {
030: BigDecimal bigZero = new BigDecimal(0);
031: BigDecimal result;
032:
033: try {
034: result = UniversalTimeScale.bigDecimalFrom(bigZero, -1);
035: errln("bigDecimalFrom(bigZero, -1) did not throw IllegalArgumentException.");
036: } catch (IllegalArgumentException iae) {
037: logln("PASS: UniversalTimeScale.bigDecimalFrom failed as expected");
038: }
039:
040: for (int scale = 0; scale < UniversalTimeScale.MAX_SCALE; scale += 1) {
041: try {
042: result = UniversalTimeScale.bigDecimalFrom(bigZero,
043: scale);
044: } catch (IllegalArgumentException iae) {
045: errln("bigDecimalFrom(bigZero, " + scale
046: + ") threw IllegalArgumentException.");
047: }
048: }
049:
050: try {
051: result = UniversalTimeScale.bigDecimalFrom(bigZero,
052: UniversalTimeScale.MAX_SCALE);
053: errln("from(bigZero, MAX_SCALE) did not throw IllegalArgumetException.");
054: } catch (IllegalArgumentException iae) {
055: logln("PASS: UniversalTimeScale.bigDecimalFrom failed as expected");
056: }
057: }
058:
059: public void TestBigDecimalFromDouble() {
060: BigDecimal result;
061:
062: try {
063: result = UniversalTimeScale.bigDecimalFrom(0.0, -1);
064: errln("bigDecimalFrom(0.0, -1) did not throw IllegalArgumentException.");
065: } catch (IllegalArgumentException iae) {
066: logln("PASS: UniversalTimeScale.bigDecimalFrom failed as expected");
067: }
068:
069: for (int scale = 0; scale < UniversalTimeScale.MAX_SCALE; scale += 1) {
070: try {
071: result = UniversalTimeScale.bigDecimalFrom(0.0, scale);
072: } catch (IllegalArgumentException iae) {
073: errln("bigDecimalFrom(0.0, " + scale
074: + ") threw IllegalArgumentException.");
075: }
076: }
077:
078: try {
079: result = UniversalTimeScale.bigDecimalFrom(0.0,
080: UniversalTimeScale.MAX_SCALE);
081: errln("from(0.0, MAX_SCALE) did not throw IllegalArgumetException.");
082: } catch (IllegalArgumentException iae) {
083: logln("PASS: UniversalTimeScale.bigDecimalFrom failed as expected");
084: }
085: }
086:
087: public void TestBigDecimalFromLong() {
088: BigDecimal result;
089:
090: try {
091: result = UniversalTimeScale.bigDecimalFrom(0L, -1);
092: errln("bigDecimalFrom(0L, -1) did not throw IllegalArgumentException.");
093: } catch (IllegalArgumentException iae) {
094: logln("PASS: UniversalTimeScale.bigDecimalFrom failed as expected");
095: }
096:
097: for (int scale = 0; scale < UniversalTimeScale.MAX_SCALE; scale += 1) {
098: try {
099: result = UniversalTimeScale.bigDecimalFrom(0L, scale);
100: } catch (IllegalArgumentException iae) {
101: errln("bigDecimalFrom(0L, " + scale
102: + ") threw IllegalArgumentException.");
103: }
104: }
105:
106: try {
107: result = UniversalTimeScale.bigDecimalFrom(0L,
108: UniversalTimeScale.MAX_SCALE);
109: errln("from(0L, MAX_SCALE) did not throw IllegalArgumetException.");
110: } catch (IllegalArgumentException iae) {
111: logln("PASS: UniversalTimeScale.bigDecimalFrom failed as expected");
112: }
113: }
114:
115: public void TestFromLong() {
116: long result;
117:
118: try {
119: result = UniversalTimeScale.from(0L, -1);
120: errln("from(0L, -1) did not throw IllegalArgumentException.");
121: } catch (IllegalArgumentException iae) {
122: logln("PASS: UniversalTimeScale.from failed as expected");
123: }
124:
125: for (int scale = 0; scale < UniversalTimeScale.MAX_SCALE; scale += 1) {
126: long fromMin = UniversalTimeScale.getTimeScaleValue(scale,
127: UniversalTimeScale.FROM_MIN_VALUE);
128: long fromMax = UniversalTimeScale.getTimeScaleValue(scale,
129: UniversalTimeScale.FROM_MAX_VALUE);
130:
131: try {
132: result = UniversalTimeScale.from(0L, scale);
133: } catch (IllegalArgumentException iae) {
134: errln("from(0L, " + scale
135: + ") threw IllegalArgumentException.");
136: }
137:
138: try {
139: result = UniversalTimeScale.from(fromMin, scale);
140: } catch (IllegalArgumentException iae) {
141: errln("from(fromMin, " + scale
142: + ") threw IllegalArgumentException.");
143: }
144:
145: if (fromMin > Long.MIN_VALUE) {
146: try {
147: result = UniversalTimeScale
148: .from(fromMin - 1, scale);
149: errln("from(fromMin - 1, "
150: + scale
151: + ") did not throw IllegalArgumentException.");
152: } catch (IllegalArgumentException iae) {
153: logln("PASS: UniversalTimeScale.from failed as expected");
154: }
155: }
156:
157: try {
158: result = UniversalTimeScale.from(fromMax, scale);
159: } catch (IllegalArgumentException iae) {
160: errln("from(fromMax, " + scale
161: + ") threw IllegalArgumentException.");
162: }
163:
164: if (fromMax < Long.MAX_VALUE) {
165: try {
166: result = UniversalTimeScale
167: .from(fromMax + 1, scale);
168: errln("from(fromMax + 1, "
169: + scale
170: + ") did not throw IllegalArgumentException.");
171: } catch (IllegalArgumentException iae) {
172: logln("PASS: UniversalTimeScale.from failed as expected");
173: }
174: }
175: }
176:
177: try {
178: result = UniversalTimeScale.from(0L,
179: UniversalTimeScale.MAX_SCALE);
180: errln("from(0L, MAX_SCALE) did not throw IllegalArgumetException.");
181: } catch (IllegalArgumentException iae) {
182: logln("PASS: UniversalTimeScale.from failed as expected");
183: }
184: }
185:
186: public void TestGetTimeScale() {
187: long value;
188:
189: try {
190: value = UniversalTimeScale.getTimeScaleValue(-1, 0);
191: errln("getTimeScaleValue(-1, 0) did not throw IllegalArgumentException.");
192: } catch (IllegalArgumentException iae) {
193: logln("PASS: UniversalTimeScale.getTimeScaleValue failed as expected");
194: }
195:
196: try {
197: value = UniversalTimeScale.getTimeScaleValue(0, -1);
198: errln("getTimeScaleValue(0, -1) did not throw IllegalArgumentException.");
199: } catch (IllegalArgumentException iae) {
200: logln("PASS: UniversalTimeScale.getTimeScaleValue failed as expected");
201: }
202:
203: for (int scale = 0; scale < UniversalTimeScale.MAX_SCALE; scale += 1) {
204: try {
205: value = UniversalTimeScale.getTimeScaleValue(scale, 0);
206: } catch (IllegalArgumentException iae) {
207: errln("getTimeScaleValue(" + scale
208: + ", 0) threw IllegalArgumentException.");
209: }
210: }
211:
212: try {
213: value = UniversalTimeScale.getTimeScaleValue(
214: UniversalTimeScale.MAX_SCALE, 0);
215: errln("getTimeScaleValue(MAX_SCALE, 0) did not throw IllegalArgumentException");
216: } catch (IllegalArgumentException iae) {
217: logln("PASS: UniversalTimeScale.getTimeScaleValue failed as expected");
218: }
219:
220: try {
221: value = UniversalTimeScale.getTimeScaleValue(0,
222: UniversalTimeScale.MAX_SCALE_VALUE);
223: errln("getTimeScaleValue(0, MAX_SCALE_VALUE) did not throw IllegalArgumentException");
224: } catch (IllegalArgumentException iae) {
225: logln("PASS: UniversalTimeScale.getTimeScaleValue failed as expected");
226: }
227: }
228:
229: public void TestToBigDecimalFromBigDecimal() {
230: BigDecimal bigZero = new BigDecimal(0);
231: BigDecimal result;
232:
233: try {
234: result = UniversalTimeScale.toBigDecimal(bigZero, -1);
235: errln("toBigDecimal(bigZero, -1) did not throw IllegalArgumentException.");
236: } catch (IllegalArgumentException iae) {
237: logln("PASS: UniversalTimeScale.toBigDecimal failed as expected");
238: }
239:
240: for (int scale = 0; scale < UniversalTimeScale.MAX_SCALE; scale += 1) {
241: try {
242: result = UniversalTimeScale
243: .toBigDecimal(bigZero, scale);
244: } catch (IllegalArgumentException iae) {
245: errln("toBigDecimal(bigZero, " + scale
246: + ") threw IllegalArgumentException.");
247: }
248: }
249:
250: try {
251: result = UniversalTimeScale.toBigDecimal(bigZero,
252: UniversalTimeScale.MAX_SCALE);
253: errln("toBigDecimal(bigZero, MAX_SCALE) did not throw IllegalArgumetException.");
254: } catch (IllegalArgumentException iae) {
255: logln("PASS: UniversalTimeScale.toBigDecimal failed as expected");
256: }
257: }
258:
259: public void TestToBigDecimalTrunc() {
260: BigDecimal bigZero = new BigDecimal(0);
261: BigDecimal result;
262:
263: try {
264: result = UniversalTimeScale.toBigDecimalTrunc(bigZero, -1);
265: errln("toBigDecimalTrunc(bigZero, -1) did not throw IllegalArgumentException.");
266: } catch (IllegalArgumentException iae) {
267: logln("PASS: UniversalTimeScale.toBigDecimalTrunc failed as expected");
268: }
269:
270: for (int scale = 0; scale < UniversalTimeScale.MAX_SCALE; scale += 1) {
271: try {
272: result = UniversalTimeScale.toBigDecimalTrunc(bigZero,
273: scale);
274: } catch (IllegalArgumentException iae) {
275: errln("toBigDecimalTrunc(bigZero, " + scale
276: + ") threw IllegalArgumentException.");
277: }
278: }
279:
280: try {
281: result = UniversalTimeScale.toBigDecimalTrunc(bigZero,
282: UniversalTimeScale.MAX_SCALE);
283: errln("toBigDecimalTrunc(bigZero, MAX_SCALE) did not throw IllegalArgumetException.");
284: } catch (IllegalArgumentException iae) {
285: logln("PASS: UniversalTimeScale.toBigDecimalTrunc failed as expected");
286: }
287: }
288:
289: public void TestToBigDecimalFromLong() {
290: BigDecimal result;
291:
292: try {
293: result = UniversalTimeScale.toBigDecimal(0L, -1);
294: errln("toBigDecimal(0L, -1) did not throw IllegalArgumentException.");
295: } catch (IllegalArgumentException iae) {
296: logln("PASS: UniversalTimeScale.toBigDecimal failed as expected");
297: }
298:
299: for (int scale = 0; scale < UniversalTimeScale.MAX_SCALE; scale += 1) {
300: try {
301: result = UniversalTimeScale.toBigDecimal(0L, scale);
302: } catch (IllegalArgumentException iae) {
303: errln("toBigDecimal(0L, " + scale
304: + ") threw IllegalArgumentException.");
305: }
306: }
307:
308: try {
309: result = UniversalTimeScale.toBigDecimal(0L,
310: UniversalTimeScale.MAX_SCALE);
311: errln("toBigDecimal(0L, MAX_SCALE) did not throw IllegalArgumetException.");
312: } catch (IllegalArgumentException iae) {
313: logln("PASS: UniversalTimeScale.toBigDecimal failed as expected");
314: }
315: }
316:
317: public void TestToLong() {
318: long result;
319:
320: try {
321: result = UniversalTimeScale.toLong(0L, -1);
322: errln("toLong(0L, -1) did not throw IllegalArgumentException.");
323: } catch (IllegalArgumentException iae) {
324: logln("PASS: UniversalTimeScale.toLong failed as expected");
325: }
326:
327: for (int scale = 0; scale < UniversalTimeScale.MAX_SCALE; scale += 1) {
328: long toMin = UniversalTimeScale.getTimeScaleValue(scale,
329: UniversalTimeScale.TO_MIN_VALUE);
330: long toMax = UniversalTimeScale.getTimeScaleValue(scale,
331: UniversalTimeScale.TO_MAX_VALUE);
332:
333: try {
334: result = UniversalTimeScale.toLong(0L, scale);
335: } catch (IllegalArgumentException iae) {
336: errln("toLong(0L, " + scale
337: + ") threw IllegalArgumentException.");
338: }
339:
340: try {
341: result = UniversalTimeScale.toLong(toMin, scale);
342: } catch (IllegalArgumentException iae) {
343: errln("toLong(toMin, " + scale
344: + ") threw IllegalArgumentException.");
345: }
346:
347: if (toMin > Long.MIN_VALUE) {
348: try {
349: result = UniversalTimeScale
350: .toLong(toMin - 1, scale);
351: errln("toLong(toMin - 1, "
352: + scale
353: + ") did not throw IllegalArgumentException.");
354: } catch (IllegalArgumentException iae) {
355: logln("PASS: UniversalTimeScale.toLong failed as expected");
356: }
357: }
358:
359: try {
360: result = UniversalTimeScale.toLong(toMax, scale);
361: } catch (IllegalArgumentException iae) {
362: errln("toLong(toMax, " + scale
363: + ") threw IllegalArgumentException.");
364: }
365:
366: if (toMax < Long.MAX_VALUE) {
367: try {
368: result = UniversalTimeScale
369: .toLong(toMax + 1, scale);
370: errln("toLong(toMax + 1, "
371: + scale
372: + ") did not throw IllegalArgumentException.");
373: } catch (IllegalArgumentException iae) {
374: logln("PASS: UniversalTimeScale.toLong failed as expected");
375: }
376: }
377: }
378:
379: try {
380: result = UniversalTimeScale.toLong(0L,
381: UniversalTimeScale.MAX_SCALE);
382: errln("toLong(0L, MAX_SCALE) did not throw IllegalArgumetException.");
383: } catch (IllegalArgumentException iae) {
384: logln("PASS: UniversalTimeScale.toLong failed as expected");
385: }
386: }
387:
388: public static void main(String[] args) {
389: new TimeScaleAPITest().run(args);
390: }
391: }
|