ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/jtreg/util/Hashtable/IllegalLoadFactor.java
Revision: 1.1
Committed: Tue Sep 1 01:25:04 2009 UTC (14 years, 9 months ago) by jsr166
Branch: MAIN
Log Message:
import tests from openjdk

File Contents

# User Rev Content
1 jsr166 1.1 /*
2     * Copyright 1997-1998 Sun Microsystems, Inc. All Rights Reserved.
3     * 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     * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20     * CA 95054 USA or visit www.sun.com if you need additional information or
21     * have any questions.
22     */
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     try{
42     // this should generate an IllegalArgumentException
43     Hashtable bad1 = new Hashtable(100, -3);
44     }
45     catch (IllegalArgumentException e1) {
46     testSucceeded = true;
47     }
48     if(!testSucceeded)
49     throw new Exception("Hashtable, negative load factor");
50    
51     testSucceeded = false;
52     try{
53     // this should generate an IllegalArgumentException
54     Hashtable bad1 = new Hashtable(100, Float.NaN);
55     }
56     catch (IllegalArgumentException e1) {
57     testSucceeded = true;
58     }
59     if(!testSucceeded)
60     throw new Exception("Hashtable, NaN load factor");
61    
62     testSucceeded = false;
63     try{
64     // this should generate an IllegalArgumentException
65     HashMap bad1 = new HashMap(100, -3);
66     }
67     catch (IllegalArgumentException e1) {
68     testSucceeded = true;
69     }
70     if(!testSucceeded)
71     throw new Exception("HashMap, negative load factor");
72    
73     testSucceeded = false;
74     try{
75     // this should generate an IllegalArgumentException
76     HashMap bad1 = new HashMap(100, Float.NaN);
77     }
78     catch (IllegalArgumentException e1) {
79     testSucceeded = true;
80     }
81     if(!testSucceeded)
82     throw new Exception("HashMap, NaN load factor");
83    
84    
85     testSucceeded = false;
86     try{
87     // this should generate an IllegalArgumentException
88     HashSet bad1 = new HashSet(100, -3);
89     }
90     catch (IllegalArgumentException e1) {
91     testSucceeded = true;
92     }
93     if(!testSucceeded)
94     throw new Exception("HashSet, negative load factor");
95    
96     testSucceeded = false;
97     try{
98     // this should generate an IllegalArgumentException
99     HashSet bad1 = new HashSet(100, Float.NaN);
100     }
101     catch (IllegalArgumentException e1) {
102     testSucceeded = true;
103     }
104     if(!testSucceeded)
105     throw new Exception("HashSet, NaN load factor");
106    
107     testSucceeded = false;
108     try{
109     // this should generate an IllegalArgumentException
110     WeakHashMap bad1 = new WeakHashMap(100, -3);
111     }
112     catch (IllegalArgumentException e1) {
113     testSucceeded = true;
114     }
115     if(!testSucceeded)
116     throw new Exception("WeakHashMap, negative load factor");
117    
118     testSucceeded = false;
119     try{
120     // this should generate an IllegalArgumentException
121     WeakHashMap bad1 = new WeakHashMap(100, Float.NaN);
122     }
123     catch (IllegalArgumentException e1) {
124     testSucceeded = true;
125     }
126     if(!testSucceeded)
127     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     }