ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/jtreg/util/Hashtable/IllegalLoadFactor.java
Revision: 1.4
Committed: Sat Oct 16 16:00:28 2010 UTC (13 years, 7 months ago) by jsr166
Branch: MAIN
CVS Tags: release-1_7_0
Changes since 1.3: +8 -8 lines
Log Message:
whitespace

File Contents

# User Rev Content
1 jsr166 1.1 /*
2 jsr166 1.3 * Copyright (c) 1997, 1998, Oracle and/or its affiliates. All rights reserved.
3 jsr166 1.1 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4     *
5     * This code is free software; you can redistribute it and/or modify it
6     * under the terms of the GNU General Public License version 2 only, as
7     * published by the Free Software Foundation.
8     *
9     * This code is distributed in the hope that it will be useful, but WITHOUT
10     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11     * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12     * version 2 for more details (a copy is included in the LICENSE file that
13     * accompanied this code).
14     *
15     * You should have received a copy of the GNU General Public License version
16     * 2 along with this work; if not, write to the Free Software Foundation,
17     * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18     *
19 jsr166 1.3 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20     * or visit www.oracle.com if you need additional information or have any
21     * questions.
22 jsr166 1.1 */
23    
24     /* @test
25     @bug 4093817 4189594
26     @summary Test for an illegalargumentexception on loadFactor
27     */
28    
29    
30    
31     import java.util.*;
32    
33     /**
34     * This class tests to see if creating a hash table with an
35     * illegal value of loadFactor results in an IllegalArgumentException
36     */
37     public class IllegalLoadFactor {
38    
39     public static void main(String argv[]) throws Exception {
40     boolean testSucceeded = false;
41 jsr166 1.4 try {
42 jsr166 1.1 // this should generate an IllegalArgumentException
43     Hashtable bad1 = new Hashtable(100, -3);
44     }
45     catch (IllegalArgumentException e1) {
46     testSucceeded = true;
47     }
48 jsr166 1.2 if (!testSucceeded)
49 jsr166 1.1 throw new Exception("Hashtable, negative load factor");
50    
51     testSucceeded = false;
52 jsr166 1.4 try {
53 jsr166 1.1 // this should generate an IllegalArgumentException
54     Hashtable bad1 = new Hashtable(100, Float.NaN);
55     }
56     catch (IllegalArgumentException e1) {
57     testSucceeded = true;
58     }
59 jsr166 1.2 if (!testSucceeded)
60 jsr166 1.1 throw new Exception("Hashtable, NaN load factor");
61    
62     testSucceeded = false;
63 jsr166 1.4 try {
64 jsr166 1.1 // this should generate an IllegalArgumentException
65     HashMap bad1 = new HashMap(100, -3);
66     }
67     catch (IllegalArgumentException e1) {
68     testSucceeded = true;
69     }
70 jsr166 1.2 if (!testSucceeded)
71 jsr166 1.1 throw new Exception("HashMap, negative load factor");
72    
73     testSucceeded = false;
74 jsr166 1.4 try {
75 jsr166 1.1 // this should generate an IllegalArgumentException
76     HashMap bad1 = new HashMap(100, Float.NaN);
77     }
78     catch (IllegalArgumentException e1) {
79     testSucceeded = true;
80     }
81 jsr166 1.2 if (!testSucceeded)
82 jsr166 1.1 throw new Exception("HashMap, NaN load factor");
83    
84    
85     testSucceeded = false;
86 jsr166 1.4 try {
87 jsr166 1.1 // this should generate an IllegalArgumentException
88     HashSet bad1 = new HashSet(100, -3);
89     }
90     catch (IllegalArgumentException e1) {
91     testSucceeded = true;
92     }
93 jsr166 1.2 if (!testSucceeded)
94 jsr166 1.1 throw new Exception("HashSet, negative load factor");
95    
96     testSucceeded = false;
97 jsr166 1.4 try {
98 jsr166 1.1 // this should generate an IllegalArgumentException
99     HashSet bad1 = new HashSet(100, Float.NaN);
100     }
101     catch (IllegalArgumentException e1) {
102     testSucceeded = true;
103     }
104 jsr166 1.2 if (!testSucceeded)
105 jsr166 1.1 throw new Exception("HashSet, NaN load factor");
106    
107     testSucceeded = false;
108 jsr166 1.4 try {
109 jsr166 1.1 // this should generate an IllegalArgumentException
110     WeakHashMap bad1 = new WeakHashMap(100, -3);
111     }
112     catch (IllegalArgumentException e1) {
113     testSucceeded = true;
114     }
115 jsr166 1.2 if (!testSucceeded)
116 jsr166 1.1 throw new Exception("WeakHashMap, negative load factor");
117    
118     testSucceeded = false;
119 jsr166 1.4 try {
120 jsr166 1.1 // this should generate an IllegalArgumentException
121     WeakHashMap bad1 = new WeakHashMap(100, Float.NaN);
122     }
123     catch (IllegalArgumentException e1) {
124     testSucceeded = true;
125     }
126 jsr166 1.2 if (!testSucceeded)
127 jsr166 1.1 throw new Exception("WeakHashMap, NaN load factor");
128    
129     // Make sure that legal creates don't throw exceptions
130     Map goodMap = new Hashtable(100, .69f);
131     goodMap = new HashMap(100, .69f);
132     Set goodSet = new HashSet(100, .69f);
133     goodMap = new WeakHashMap(100, .69f);
134     }
135    
136     }