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.Collections; |
|
23 |
|
24 import gnu.testlet.TestHarness; |
|
25 import gnu.testlet.Testlet; |
|
26 |
|
27 import java.util.ArrayList; |
|
28 import java.util.Collection; |
|
29 import java.util.Collections; |
|
30 import java.util.List; |
|
31 import java.util.NoSuchElementException; |
|
32 |
|
33 public class max implements Testlet |
|
34 { |
|
35 |
|
36 public void test(TestHarness harness) |
|
37 { |
|
38 List list = new ArrayList(); |
|
39 |
|
40 // try an empty list |
|
41 boolean pass = false; |
|
42 try |
|
43 { |
|
44 Object m = Collections.max(list); |
|
45 } |
|
46 catch (NoSuchElementException e) |
|
47 { |
|
48 pass = true; |
|
49 } |
|
50 harness.check(true); |
|
51 |
|
52 // try a regular list |
|
53 list.add(new Integer(12)); |
|
54 list.add(new Integer(9)); |
|
55 list.add(new Integer(17)); |
|
56 harness.check(Collections.max(list).equals(new Integer(17))); |
|
57 |
|
58 // try a null list |
|
59 pass = false; |
|
60 try |
|
61 { |
|
62 Object ignore = Collections.max((Collection)null); |
|
63 } |
|
64 catch (NullPointerException e) |
|
65 { |
|
66 pass = true; |
|
67 } |
|
68 harness.check(pass); |
|
69 |
|
70 // try a list with non-comparable items |
|
71 list.clear(); |
|
72 list.add("A"); list.add(new Long(1)); |
|
73 pass = false; |
|
74 try |
|
75 { |
|
76 Object ignore = Collections.max(list); |
|
77 } |
|
78 catch (ClassCastException e) |
|
79 { |
|
80 pass = true; |
|
81 } |
|
82 harness.check(pass); |
|
83 |
|
84 } |
|
85 } |
|