1 //Tags: JDK1.2 |
|
2 |
|
3 //Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com> |
|
4 |
|
5 //This file is part of Mauve. |
|
6 |
|
7 //Mauve is free software; you can redistribute it and/or modify |
|
8 //it under the terms of the GNU General Public License as published by |
|
9 //the Free Software Foundation; either version 2, or (at your option) |
|
10 //any later version. |
|
11 |
|
12 //Mauve is distributed in the hope that it will be useful, |
|
13 //but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15 //GNU General Public License for more details. |
|
16 |
|
17 //You should have received a copy of the GNU General Public License |
|
18 //along with Mauve; see the file COPYING. If not, write to |
|
19 //the Free Software Foundation, 59 Temple Place - Suite 330, |
|
20 //Boston, MA 02111-1307, USA. */ |
|
21 |
|
22 package gnu.testlet.java.util.Arrays; |
|
23 |
|
24 import gnu.testlet.TestHarness; |
|
25 import gnu.testlet.Testlet; |
|
26 |
|
27 import java.util.Arrays; |
|
28 |
|
29 public class fill implements Testlet |
|
30 { |
|
31 public void test (TestHarness harness) |
|
32 { |
|
33 testBoolean(harness); |
|
34 testByte(harness); |
|
35 testChar(harness); |
|
36 testDouble(harness); |
|
37 testFloat(harness); |
|
38 testInt(harness); |
|
39 testLong(harness); |
|
40 testObject(harness); |
|
41 testShort(harness); |
|
42 } |
|
43 |
|
44 private void testBoolean(TestHarness harness) |
|
45 { |
|
46 harness.checkPoint("Arrays.fill(boolean[], boolean"); |
|
47 boolean[] b1 = new boolean[0]; |
|
48 boolean[] b2 = new boolean[1]; |
|
49 boolean[] b3 = new boolean[2]; |
|
50 |
|
51 Arrays.fill(b1, true); |
|
52 harness.check(b1.length == 0); |
|
53 |
|
54 Arrays.fill(b2, true); |
|
55 harness.check(b2[0] == true); |
|
56 |
|
57 Arrays.fill(b3, true); |
|
58 harness.check(b3[0] == true); |
|
59 harness.check(b3[1] == true); |
|
60 |
|
61 boolean pass = false; |
|
62 try |
|
63 { |
|
64 Arrays.fill((boolean[]) null, true); |
|
65 } |
|
66 catch (NullPointerException e) |
|
67 { |
|
68 pass = true; |
|
69 } |
|
70 harness.check(pass); |
|
71 |
|
72 harness.checkPoint("Arrays.fill(boolean[], int, int, boolean"); |
|
73 |
|
74 Arrays.fill(b1, 0, 0, false); |
|
75 |
|
76 Arrays.fill(b2, 0, 1, false); |
|
77 harness.check(b2[0] == false); |
|
78 |
|
79 Arrays.fill(b3, 1, 2, false); |
|
80 harness.check(b3[0] == true); |
|
81 harness.check(b3[1] == false); |
|
82 |
|
83 // from index should be <= toIndex |
|
84 pass = false; |
|
85 try |
|
86 { |
|
87 Arrays.fill(b3, 2, 1, false); |
|
88 } |
|
89 catch (IllegalArgumentException e) |
|
90 { |
|
91 pass = true; |
|
92 } |
|
93 harness.check(pass); |
|
94 |
|
95 // from index should be >= 0 |
|
96 pass = false; |
|
97 try |
|
98 { |
|
99 Arrays.fill(b3, -1, 1, false); |
|
100 } |
|
101 catch (ArrayIndexOutOfBoundsException e) |
|
102 { |
|
103 pass = true; |
|
104 } |
|
105 harness.check(pass); |
|
106 |
|
107 // to index should be < array.length |
|
108 pass = false; |
|
109 try |
|
110 { |
|
111 Arrays.fill(b3, 0, 4, false); |
|
112 } |
|
113 catch (ArrayIndexOutOfBoundsException e) |
|
114 { |
|
115 pass = true; |
|
116 } |
|
117 harness.check(pass); |
|
118 } |
|
119 |
|
120 private void testByte(TestHarness harness) |
|
121 { |
|
122 harness.checkPoint("Arrays.fill(byte[], byte"); |
|
123 byte[] b1 = new byte[0]; |
|
124 byte[] b2 = new byte[1]; |
|
125 byte[] b3 = new byte[2]; |
|
126 |
|
127 Arrays.fill(b1, (byte) 1); |
|
128 harness.check(b1.length == 0); |
|
129 |
|
130 Arrays.fill(b2, (byte) 1); |
|
131 harness.check(b2[0] == (byte) 1); |
|
132 |
|
133 Arrays.fill(b3, (byte) 1); |
|
134 harness.check(b3[0] == (byte) 1); |
|
135 harness.check(b3[1] == (byte) 1); |
|
136 |
|
137 boolean pass = false; |
|
138 try |
|
139 { |
|
140 Arrays.fill((byte[]) null, (byte) 1); |
|
141 } |
|
142 catch (NullPointerException e) |
|
143 { |
|
144 pass = true; |
|
145 } |
|
146 harness.check(pass); |
|
147 |
|
148 harness.checkPoint("Arrays.fill(byte[], int, int, byte"); |
|
149 |
|
150 Arrays.fill(b1, 0, 0, (byte) 2); |
|
151 |
|
152 Arrays.fill(b2, 0, 1, (byte) 2); |
|
153 harness.check(b2[0] == (byte) 2); |
|
154 |
|
155 Arrays.fill(b3, 1, 2, (byte) 2); |
|
156 harness.check(b3[0] == (byte) 1); |
|
157 harness.check(b3[1] == (byte) 2); |
|
158 |
|
159 // from index should be <= toIndex |
|
160 pass = false; |
|
161 try |
|
162 { |
|
163 Arrays.fill(b3, 2, 1, (byte) 0); |
|
164 } |
|
165 catch (IllegalArgumentException e) |
|
166 { |
|
167 pass = true; |
|
168 } |
|
169 harness.check(pass); |
|
170 |
|
171 // from index should be >= 0 |
|
172 pass = false; |
|
173 try |
|
174 { |
|
175 Arrays.fill(b3, -1, 1, (byte) 0); |
|
176 } |
|
177 catch (ArrayIndexOutOfBoundsException e) |
|
178 { |
|
179 pass = true; |
|
180 } |
|
181 harness.check(pass); |
|
182 |
|
183 // to index should be < array.length |
|
184 pass = false; |
|
185 try |
|
186 { |
|
187 Arrays.fill(b3, 0, 4, (byte) 0); |
|
188 } |
|
189 catch (ArrayIndexOutOfBoundsException e) |
|
190 { |
|
191 pass = true; |
|
192 } |
|
193 harness.check(pass); |
|
194 } |
|
195 |
|
196 private void testChar(TestHarness harness) |
|
197 { |
|
198 harness.checkPoint("Arrays.fill(char[], char"); |
|
199 char[] b1 = new char[0]; |
|
200 char[] b2 = new char[1]; |
|
201 char[] b3 = new char[2]; |
|
202 |
|
203 Arrays.fill(b1, 'A'); |
|
204 harness.check(b1.length == 0); |
|
205 |
|
206 Arrays.fill(b2, 'A'); |
|
207 harness.check(b2[0] == 'A'); |
|
208 |
|
209 Arrays.fill(b3, 'A'); |
|
210 harness.check(b3[0] == 'A'); |
|
211 harness.check(b3[1] == 'A'); |
|
212 |
|
213 boolean pass = false; |
|
214 try |
|
215 { |
|
216 Arrays.fill((char[]) null, 'A'); |
|
217 } |
|
218 catch (NullPointerException e) |
|
219 { |
|
220 pass = true; |
|
221 } |
|
222 harness.check(pass); |
|
223 |
|
224 harness.checkPoint("Arrays.fill(char[], int, int, char"); |
|
225 |
|
226 Arrays.fill(b1, 0, 0, 'B'); |
|
227 |
|
228 Arrays.fill(b2, 0, 1, 'B'); |
|
229 harness.check(b2[0] == 'B'); |
|
230 |
|
231 Arrays.fill(b3, 1, 2, 'B'); |
|
232 harness.check(b3[0] == 'A'); |
|
233 harness.check(b3[1] == 'B'); |
|
234 |
|
235 // from index should be <= toIndex |
|
236 pass = false; |
|
237 try |
|
238 { |
|
239 Arrays.fill(b3, 2, 1, 'B'); |
|
240 } |
|
241 catch (IllegalArgumentException e) |
|
242 { |
|
243 pass = true; |
|
244 } |
|
245 harness.check(pass); |
|
246 |
|
247 // from index should be >= 0 |
|
248 pass = false; |
|
249 try |
|
250 { |
|
251 Arrays.fill(b3, -1, 1, 'B'); |
|
252 } |
|
253 catch (ArrayIndexOutOfBoundsException e) |
|
254 { |
|
255 pass = true; |
|
256 } |
|
257 harness.check(pass); |
|
258 |
|
259 // to index should be < array.length |
|
260 pass = false; |
|
261 try |
|
262 { |
|
263 Arrays.fill(b3, 0, 4, 'B'); |
|
264 } |
|
265 catch (ArrayIndexOutOfBoundsException e) |
|
266 { |
|
267 pass = true; |
|
268 } |
|
269 harness.check(pass); |
|
270 } |
|
271 |
|
272 private void testDouble(TestHarness harness) |
|
273 { |
|
274 harness.checkPoint("Arrays.fill(double[], double"); |
|
275 double[] b1 = new double[0]; |
|
276 double[] b2 = new double[1]; |
|
277 double[] b3 = new double[2]; |
|
278 |
|
279 Arrays.fill(b1, 1.0); |
|
280 harness.check(b1.length == 0); |
|
281 |
|
282 Arrays.fill(b2, 1.0); |
|
283 harness.check(b2[0] == 1.0); |
|
284 |
|
285 Arrays.fill(b3, 1.0); |
|
286 harness.check(b3[0] == 1.0); |
|
287 harness.check(b3[1] == 1.0); |
|
288 |
|
289 boolean pass = false; |
|
290 try |
|
291 { |
|
292 Arrays.fill((double[]) null, 1.0); |
|
293 } |
|
294 catch (NullPointerException e) |
|
295 { |
|
296 pass = true; |
|
297 } |
|
298 harness.check(pass); |
|
299 |
|
300 harness.checkPoint("Arrays.fill(double[], int, int, double"); |
|
301 |
|
302 Arrays.fill(b1, 0, 0, 2.0); |
|
303 |
|
304 Arrays.fill(b2, 0, 1, 2.0); |
|
305 harness.check(b2[0] == 2.0); |
|
306 |
|
307 Arrays.fill(b3, 1, 2, 2.0); |
|
308 harness.check(b3[0] == 1.0); |
|
309 harness.check(b3[1] == 2.0); |
|
310 |
|
311 // from index should be <= toIndex |
|
312 pass = false; |
|
313 try |
|
314 { |
|
315 Arrays.fill(b3, 2, 1, 2.0); |
|
316 } |
|
317 catch (IllegalArgumentException e) |
|
318 { |
|
319 pass = true; |
|
320 } |
|
321 harness.check(pass); |
|
322 |
|
323 // from index should be >= 0 |
|
324 pass = false; |
|
325 try |
|
326 { |
|
327 Arrays.fill(b3, -1, 1, 2.0); |
|
328 } |
|
329 catch (ArrayIndexOutOfBoundsException e) |
|
330 { |
|
331 pass = true; |
|
332 } |
|
333 harness.check(pass); |
|
334 |
|
335 // to index should be < array.length |
|
336 pass = false; |
|
337 try |
|
338 { |
|
339 Arrays.fill(b3, 0, 4, 2.0); |
|
340 } |
|
341 catch (ArrayIndexOutOfBoundsException e) |
|
342 { |
|
343 pass = true; |
|
344 } |
|
345 harness.check(pass); |
|
346 } |
|
347 |
|
348 private void testFloat(TestHarness harness) |
|
349 { |
|
350 harness.checkPoint("Arrays.fill(float[], float"); |
|
351 float[] b1 = new float[0]; |
|
352 float[] b2 = new float[1]; |
|
353 float[] b3 = new float[2]; |
|
354 |
|
355 Arrays.fill(b1, 1.0f); |
|
356 harness.check(b1.length == 0); |
|
357 |
|
358 Arrays.fill(b2, 1.0f); |
|
359 harness.check(b2[0] == 1.0f); |
|
360 |
|
361 Arrays.fill(b3, 1.0f); |
|
362 harness.check(b3[0] == 1.0f); |
|
363 harness.check(b3[1] == 1.0f); |
|
364 |
|
365 boolean pass = false; |
|
366 try |
|
367 { |
|
368 Arrays.fill((float[]) null, 1.0f); |
|
369 } |
|
370 catch (NullPointerException e) |
|
371 { |
|
372 pass = true; |
|
373 } |
|
374 harness.check(pass); |
|
375 |
|
376 harness.checkPoint("Arrays.fill(float[], int, int, float"); |
|
377 |
|
378 Arrays.fill(b1, 0, 0, 2.0f); |
|
379 |
|
380 Arrays.fill(b2, 0, 1, 2.0f); |
|
381 harness.check(b2[0] == 2.0f); |
|
382 |
|
383 Arrays.fill(b3, 1, 2, 2.0f); |
|
384 harness.check(b3[0] == 1.0); |
|
385 harness.check(b3[1] == 2.0); |
|
386 |
|
387 // from index should be <= toIndex |
|
388 pass = false; |
|
389 try |
|
390 { |
|
391 Arrays.fill(b3, 2, 1, 2.0f); |
|
392 } |
|
393 catch (IllegalArgumentException e) |
|
394 { |
|
395 pass = true; |
|
396 } |
|
397 harness.check(pass); |
|
398 |
|
399 // from index should be >= 0 |
|
400 pass = false; |
|
401 try |
|
402 { |
|
403 Arrays.fill(b3, -1, 1, 2.0f); |
|
404 } |
|
405 catch (ArrayIndexOutOfBoundsException e) |
|
406 { |
|
407 pass = true; |
|
408 } |
|
409 harness.check(pass); |
|
410 |
|
411 // to index should be < array.length |
|
412 pass = false; |
|
413 try |
|
414 { |
|
415 Arrays.fill(b3, 0, 4, 2.0f); |
|
416 } |
|
417 catch (ArrayIndexOutOfBoundsException e) |
|
418 { |
|
419 pass = true; |
|
420 } |
|
421 harness.check(pass); |
|
422 } |
|
423 |
|
424 private void testInt(TestHarness harness) |
|
425 { |
|
426 harness.checkPoint("Arrays.fill(int[], int"); |
|
427 int[] b1 = new int[0]; |
|
428 int[] b2 = new int[1]; |
|
429 int[] b3 = new int[2]; |
|
430 |
|
431 Arrays.fill(b1, 1); |
|
432 harness.check(b1.length == 0); |
|
433 |
|
434 Arrays.fill(b2, 1); |
|
435 harness.check(b2[0] == 1); |
|
436 |
|
437 Arrays.fill(b3, 1); |
|
438 harness.check(b3[0] == 1); |
|
439 harness.check(b3[1] == 1); |
|
440 |
|
441 boolean pass = false; |
|
442 try |
|
443 { |
|
444 Arrays.fill((int[]) null, 1); |
|
445 } |
|
446 catch (NullPointerException e) |
|
447 { |
|
448 pass = true; |
|
449 } |
|
450 harness.check(pass); |
|
451 |
|
452 harness.checkPoint("Arrays.fill(int[], int, int, int"); |
|
453 |
|
454 Arrays.fill(b1, 0, 0, 2); |
|
455 |
|
456 Arrays.fill(b2, 0, 1, 2); |
|
457 harness.check(b2[0] == 2); |
|
458 |
|
459 Arrays.fill(b3, 1, 2, 2); |
|
460 harness.check(b3[0] == 1); |
|
461 harness.check(b3[1] == 2); |
|
462 |
|
463 // from index should be <= toIndex |
|
464 pass = false; |
|
465 try |
|
466 { |
|
467 Arrays.fill(b3, 2, 1, 2); |
|
468 } |
|
469 catch (IllegalArgumentException e) |
|
470 { |
|
471 pass = true; |
|
472 } |
|
473 harness.check(pass); |
|
474 |
|
475 // from index should be >= 0 |
|
476 pass = false; |
|
477 try |
|
478 { |
|
479 Arrays.fill(b3, -1, 1, 2); |
|
480 } |
|
481 catch (ArrayIndexOutOfBoundsException e) |
|
482 { |
|
483 pass = true; |
|
484 } |
|
485 harness.check(pass); |
|
486 |
|
487 // to index should be < array.length |
|
488 pass = false; |
|
489 try |
|
490 { |
|
491 Arrays.fill(b3, 0, 4, 2); |
|
492 } |
|
493 catch (ArrayIndexOutOfBoundsException e) |
|
494 { |
|
495 pass = true; |
|
496 } |
|
497 harness.check(pass); |
|
498 } |
|
499 |
|
500 private void testLong(TestHarness harness) |
|
501 { |
|
502 harness.checkPoint("Arrays.fill(long[], long"); |
|
503 long[] b1 = new long[0]; |
|
504 long[] b2 = new long[1]; |
|
505 long[] b3 = new long[2]; |
|
506 |
|
507 Arrays.fill(b1, 1); |
|
508 harness.check(b1.length == 0); |
|
509 |
|
510 Arrays.fill(b2, 1); |
|
511 harness.check(b2[0] == 1); |
|
512 |
|
513 Arrays.fill(b3, 1); |
|
514 harness.check(b3[0] == 1); |
|
515 harness.check(b3[1] == 1); |
|
516 |
|
517 boolean pass = false; |
|
518 try |
|
519 { |
|
520 Arrays.fill((long[]) null, 1); |
|
521 } |
|
522 catch (NullPointerException e) |
|
523 { |
|
524 pass = true; |
|
525 } |
|
526 harness.check(pass); |
|
527 |
|
528 harness.checkPoint("Arrays.fill(long[], int, int, long"); |
|
529 |
|
530 Arrays.fill(b1, 0, 0, 2); |
|
531 |
|
532 Arrays.fill(b2, 0, 1, 2); |
|
533 harness.check(b2[0] == 2); |
|
534 |
|
535 Arrays.fill(b3, 1, 2, 2); |
|
536 harness.check(b3[0] == 1); |
|
537 harness.check(b3[1] == 2); |
|
538 |
|
539 // from index should be <= toIndex |
|
540 pass = false; |
|
541 try |
|
542 { |
|
543 Arrays.fill(b3, 2, 1, 2); |
|
544 } |
|
545 catch (IllegalArgumentException e) |
|
546 { |
|
547 pass = true; |
|
548 } |
|
549 harness.check(pass); |
|
550 |
|
551 // from index should be >= 0 |
|
552 pass = false; |
|
553 try |
|
554 { |
|
555 Arrays.fill(b3, -1, 1, 2); |
|
556 } |
|
557 catch (ArrayIndexOutOfBoundsException e) |
|
558 { |
|
559 pass = true; |
|
560 } |
|
561 harness.check(pass); |
|
562 |
|
563 // to index should be < array.length |
|
564 pass = false; |
|
565 try |
|
566 { |
|
567 Arrays.fill(b3, 0, 4, 2); |
|
568 } |
|
569 catch (ArrayIndexOutOfBoundsException e) |
|
570 { |
|
571 pass = true; |
|
572 } |
|
573 harness.check(pass); |
|
574 } |
|
575 |
|
576 private void testObject(TestHarness harness) |
|
577 { |
|
578 harness.checkPoint("Arrays.fill(Object[], Object"); |
|
579 Object[] b1 = new Object[0]; |
|
580 Object[] b2 = new Object[1]; |
|
581 Object[] b3 = new Object[2]; |
|
582 |
|
583 Arrays.fill(b1, "1"); |
|
584 harness.check(b1.length == 0); |
|
585 |
|
586 Arrays.fill(b2, "1"); |
|
587 harness.check(b2[0] == "1"); |
|
588 |
|
589 Arrays.fill(b3, "1"); |
|
590 harness.check(b3[0] == "1"); |
|
591 harness.check(b3[1] == "1"); |
|
592 |
|
593 boolean pass = false; |
|
594 try |
|
595 { |
|
596 Arrays.fill((Object[]) null, "1"); |
|
597 } |
|
598 catch (NullPointerException e) |
|
599 { |
|
600 pass = true; |
|
601 } |
|
602 harness.check(pass); |
|
603 |
|
604 harness.checkPoint("Arrays.fill(Object[], int, int, long"); |
|
605 |
|
606 Arrays.fill(b1, 0, 0, "2"); |
|
607 |
|
608 Arrays.fill(b2, 0, 1, "2"); |
|
609 harness.check(b2[0] == "2"); |
|
610 |
|
611 Arrays.fill(b3, 1, 2, "2"); |
|
612 harness.check(b3[0] == "1"); |
|
613 harness.check(b3[1] == "2"); |
|
614 |
|
615 // from index should be <= toIndex |
|
616 pass = false; |
|
617 try |
|
618 { |
|
619 Arrays.fill(b3, 2, 1, "2"); |
|
620 } |
|
621 catch (IllegalArgumentException e) |
|
622 { |
|
623 pass = true; |
|
624 } |
|
625 harness.check(pass); |
|
626 |
|
627 // from index should be >= 0 |
|
628 pass = false; |
|
629 try |
|
630 { |
|
631 Arrays.fill(b3, -1, 1, "2"); |
|
632 } |
|
633 catch (ArrayIndexOutOfBoundsException e) |
|
634 { |
|
635 pass = true; |
|
636 } |
|
637 harness.check(pass); |
|
638 |
|
639 // to index should be < array.length |
|
640 pass = false; |
|
641 try |
|
642 { |
|
643 Arrays.fill(b3, 0, 4, "2"); |
|
644 } |
|
645 catch (ArrayIndexOutOfBoundsException e) |
|
646 { |
|
647 pass = true; |
|
648 } |
|
649 harness.check(pass); |
|
650 } |
|
651 |
|
652 private void testShort(TestHarness harness) |
|
653 { |
|
654 harness.checkPoint("Arrays.fill(short[], short"); |
|
655 short[] b1 = new short[0]; |
|
656 short[] b2 = new short[1]; |
|
657 short[] b3 = new short[2]; |
|
658 |
|
659 Arrays.fill(b1, (short) 1); |
|
660 harness.check(b1.length == 0); |
|
661 |
|
662 Arrays.fill(b2, (short) 1); |
|
663 harness.check(b2[0] == 1); |
|
664 |
|
665 Arrays.fill(b3, (short) 1); |
|
666 harness.check(b3[0] == 1); |
|
667 harness.check(b3[1] == 1); |
|
668 |
|
669 boolean pass = false; |
|
670 try |
|
671 { |
|
672 Arrays.fill((int[]) null, 1); |
|
673 } |
|
674 catch (NullPointerException e) |
|
675 { |
|
676 pass = true; |
|
677 } |
|
678 harness.check(pass); |
|
679 |
|
680 harness.checkPoint("Arrays.fill(short)[], int, int, short"); |
|
681 |
|
682 Arrays.fill(b1, 0, 0, (short) 2); |
|
683 |
|
684 Arrays.fill(b2, 0, 1, (short) 2); |
|
685 harness.check(b2[0] == 2); |
|
686 |
|
687 Arrays.fill(b3, 1, 2, (short) 2); |
|
688 harness.check(b3[0] == 1); |
|
689 harness.check(b3[1] == 2); |
|
690 |
|
691 // from index should be <= toIndex |
|
692 pass = false; |
|
693 try |
|
694 { |
|
695 Arrays.fill(b3, 2, 1, (short) 2); |
|
696 } |
|
697 catch (IllegalArgumentException e) |
|
698 { |
|
699 pass = true; |
|
700 } |
|
701 harness.check(pass); |
|
702 |
|
703 // from index should be >= 0 |
|
704 pass = false; |
|
705 try |
|
706 { |
|
707 Arrays.fill(b3, -1, 1, (short) 2); |
|
708 } |
|
709 catch (ArrayIndexOutOfBoundsException e) |
|
710 { |
|
711 pass = true; |
|
712 } |
|
713 harness.check(pass); |
|
714 |
|
715 // to index should be < array.length |
|
716 pass = false; |
|
717 try |
|
718 { |
|
719 Arrays.fill(b3, 0, 4, (short) 2); |
|
720 } |
|
721 catch (ArrayIndexOutOfBoundsException e) |
|
722 { |
|
723 pass = true; |
|
724 } |
|
725 harness.check(pass); |
|
726 } |
|
727 |
|
728 } |
|