ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/jtreg/util/Hashtable/IllegalLoadFactor.java
Revision: 1.5
Committed: Sun Oct 11 00:58:42 2015 UTC (8 years, 7 months ago) by jsr166
Branch: MAIN
Changes since 1.4: +0 -2 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     import java.util.*;
30    
31     /**
32     * This class tests to see if creating a hash table with an
33     * illegal value of loadFactor results in an IllegalArgumentException
34     */
35     public class IllegalLoadFactor {
36    
37     public static void main(String argv[]) throws Exception {
38     boolean testSucceeded = false;
39 jsr166 1.4 try {
40 jsr166 1.1 // this should generate an IllegalArgumentException
41     Hashtable bad1 = new Hashtable(100, -3);
42     }
43     catch (IllegalArgumentException e1) {
44     testSucceeded = true;
45     }
46 jsr166 1.2 if (!testSucceeded)
47 jsr166 1.1 throw new Exception("Hashtable, negative load factor");
48    
49     testSucceeded = false;
50 jsr166 1.4 try {
51 jsr166 1.1 // this should generate an IllegalArgumentException
52     Hashtable bad1 = new Hashtable(100, Float.NaN);
53     }
54     catch (IllegalArgumentException e1) {
55     testSucceeded = true;
56     }
57 jsr166 1.2 if (!testSucceeded)
58 jsr166 1.1 throw new Exception("Hashtable, NaN load factor");
59    
60     testSucceeded = false;
61 jsr166 1.4 try {
62 jsr166 1.1 // this should generate an IllegalArgumentException
63     HashMap bad1 = new HashMap(100, -3);
64     }
65     catch (IllegalArgumentException e1) {
66     testSucceeded = true;
67     }
68 jsr166 1.2 if (!testSucceeded)
69 jsr166 1.1 throw new Exception("HashMap, negative load factor");
70    
71     testSucceeded = false;
72 jsr166 1.4 try {
73 jsr166 1.1 // this should generate an IllegalArgumentException
74     HashMap bad1 = new HashMap(100, Float.NaN);
75     }
76     catch (IllegalArgumentException e1) {
77     testSucceeded = true;
78     }
79 jsr166 1.2 if (!testSucceeded)
80 jsr166 1.1 throw new Exception("HashMap, NaN load factor");
81    
82    
83     testSucceeded = false;
84 jsr166 1.4 try {
85 jsr166 1.1 // this should generate an IllegalArgumentException
86     HashSet bad1 = new HashSet(100, -3);
87     }
88     catch (IllegalArgumentException e1) {
89     testSucceeded = true;
90     }
91 jsr166 1.2 if (!testSucceeded)
92 jsr166 1.1 throw new Exception("HashSet, negative load factor");
93    
94     testSucceeded = false;
95 jsr166 1.4 try {
96 jsr166 1.1 // this should generate an IllegalArgumentException
97     HashSet bad1 = new HashSet(100, Float.NaN);
98     }
99     catch (IllegalArgumentException e1) {
100     testSucceeded = true;
101     }
102 jsr166 1.2 if (!testSucceeded)
103 jsr166 1.1 throw new Exception("HashSet, NaN load factor");
104    
105     testSucceeded = false;
106 jsr166 1.4 try {
107 jsr166 1.1 // this should generate an IllegalArgumentException
108     WeakHashMap bad1 = new WeakHashMap(100, -3);
109     }
110     catch (IllegalArgumentException e1) {
111     testSucceeded = true;
112     }
113 jsr166 1.2 if (!testSucceeded)
114 jsr166 1.1 throw new Exception("WeakHashMap, negative load factor");
115    
116     testSucceeded = false;
117 jsr166 1.4 try {
118 jsr166 1.1 // this should generate an IllegalArgumentException
119     WeakHashMap bad1 = new WeakHashMap(100, Float.NaN);
120     }
121     catch (IllegalArgumentException e1) {
122     testSucceeded = true;
123     }
124 jsr166 1.2 if (!testSucceeded)
125 jsr166 1.1 throw new Exception("WeakHashMap, NaN load factor");
126    
127     // Make sure that legal creates don't throw exceptions
128     Map goodMap = new Hashtable(100, .69f);
129     goodMap = new HashMap(100, .69f);
130     Set goodSet = new HashSet(100, .69f);
131     goodMap = new WeakHashMap(100, .69f);
132     }
133    
134     }