1 // Tags: JDK1.1 |
|
2 |
|
3 // Copyright (C) 2004 David Gilbert <david.gilbert@object-refinery.com> |
|
4 |
|
5 // Mauve is free software; you can redistribute it and/or modify |
|
6 // it under the terms of the GNU General Public License as published by |
|
7 // the Free Software Foundation; either version 2, or (at your option) |
|
8 // any later version. |
|
9 |
|
10 // Mauve is distributed in the hope that it will be useful, |
|
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 // GNU General Public License for more details. |
|
14 |
|
15 // You should have received a copy of the GNU General Public License |
|
16 // along with Mauve; see the file COPYING. If not, write to |
|
17 // the Free Software Foundation, 59 Temple Place - Suite 330, |
|
18 // Boston, MA 02111-1307, USA. */ |
|
19 |
|
20 package gnu.testlet.java.math.BigInteger; |
|
21 |
|
22 import gnu.testlet.TestHarness; |
|
23 import gnu.testlet.Testlet; |
|
24 |
|
25 import java.math.BigInteger; |
|
26 |
|
27 /** |
|
28 * Some checks for the compareTo() method in the {@link BigInteger} class. |
|
29 */ |
|
30 public class compareTo implements Testlet |
|
31 { |
|
32 /** |
|
33 * Runs the test using the specified harness. |
|
34 * |
|
35 * @param harness the test harness (<code>null</code> not permitted). |
|
36 */ |
|
37 public void test(TestHarness harness) |
|
38 { |
|
39 BigInteger a = new BigInteger("-987654321098765432109876543210"); |
|
40 BigInteger b = new BigInteger("-1"); |
|
41 BigInteger c = new BigInteger("0"); |
|
42 BigInteger d = new BigInteger("1"); |
|
43 BigInteger e = new BigInteger("987654321098765432109876543210"); |
|
44 |
|
45 harness.check(a.compareTo(a) == 0); |
|
46 harness.check(a.compareTo(b) < 0); |
|
47 harness.check(a.compareTo(c) < 0); |
|
48 harness.check(a.compareTo(d) < 0); |
|
49 harness.check(a.compareTo(e) < 0); |
|
50 |
|
51 harness.check(b.compareTo(a) > 0); |
|
52 harness.check(b.compareTo(b) == 0); |
|
53 harness.check(b.compareTo(c) < 0); |
|
54 harness.check(b.compareTo(d) < 0); |
|
55 harness.check(b.compareTo(e) < 0); |
|
56 |
|
57 harness.check(c.compareTo(a) > 0); |
|
58 harness.check(c.compareTo(b) > 0); |
|
59 harness.check(c.compareTo(c) == 0); |
|
60 harness.check(c.compareTo(d) < 0); |
|
61 harness.check(c.compareTo(e) < 0); |
|
62 |
|
63 harness.check(d.compareTo(a) > 0); |
|
64 harness.check(d.compareTo(b) > 0); |
|
65 harness.check(d.compareTo(c) > 0); |
|
66 harness.check(d.compareTo(d) == 0); |
|
67 harness.check(d.compareTo(e) < 0); |
|
68 |
|
69 harness.check(e.compareTo(a) > 0); |
|
70 harness.check(e.compareTo(b) > 0); |
|
71 harness.check(e.compareTo(c) > 0); |
|
72 harness.check(e.compareTo(d) > 0); |
|
73 harness.check(e.compareTo(e) == 0); |
|
74 |
|
75 // try the compareTo(Object) method |
|
76 boolean pass = false; |
|
77 try |
|
78 { |
|
79 ((Comparable)a).compareTo(new Integer(1)); |
|
80 } |
|
81 catch (ClassCastException ee) |
|
82 { |
|
83 pass = true; |
|
84 } |
|
85 harness.check(pass); |
|
86 |
|
87 // try a null argument |
|
88 pass = false; |
|
89 try |
|
90 { |
|
91 a.compareTo(null); |
|
92 } |
|
93 catch (NullPointerException ee) |
|
94 { |
|
95 pass = true; |
|
96 } |
|
97 harness.check(pass); |
|
98 } |
|
99 |
|
100 } |
|