test/java/util/Collection/BiggernYours.java

Print this page
rev 5382 : 7126277: Alternative hashing implementation


  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * 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  */
  23 
  24 /*
  25  * @test
  26  * @bug 6415641 6377302
  27  * @summary Concurrent collections are permitted to lie about their size
  28  * @author Martin Buchholz
  29  */
  30 
  31 import java.io.*;
  32 import java.util.*;
  33 import java.util.concurrent.*;
  34 
  35 @SuppressWarnings("unchecked")
  36 public class BiggernYours {
  37     static final Random rnd = new Random();
  38 
  39     static void compareCollections(Collection c1, Collection c2) {
  40         arrayEqual(c1.toArray(),
  41                    c2.toArray());
  42         arrayEqual(c1.toArray(new Object[0]),
  43                    c2.toArray(new Object[0]));
  44         arrayEqual(c1.toArray(new Object[5]),
  45                    c2.toArray(new Object[5]));










  46     }
  47 
  48     static void compareMaps(Map m1, Map m2) {
  49         compareCollections(m1.keySet(),
  50                            m2.keySet());
  51         compareCollections(m1.values(),
  52                            m2.values());
  53         compareCollections(m1.entrySet(),
  54                            m2.entrySet());
  55     }
  56 
  57     static void compareNavigableMaps(NavigableMap m1, NavigableMap m2) {
  58         compareMaps(m1, m2);
  59         compareMaps(m1.descendingMap(),
  60                     m2.descendingMap());
  61         compareMaps(m1.tailMap(Integer.MIN_VALUE),
  62                     m2.tailMap(Integer.MIN_VALUE));
  63         compareMaps(m1.headMap(Integer.MAX_VALUE),
  64                     m2.headMap(Integer.MAX_VALUE));
  65     }




  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * 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  */
  23 
  24 /*
  25  * @test
  26  * @bug 6415641 6377302
  27  * @summary Concurrent collections are permitted to lie about their size
  28  * @author Martin Buchholz
  29  */
  30 
  31 import java.io.*;
  32 import java.util.*;
  33 import java.util.concurrent.*;
  34 
  35 @SuppressWarnings("unchecked")
  36 public class BiggernYours {
  37     static final Random rnd = new Random(18675309);
  38 
  39     static void compareCollections(Collection c1, Collection c2) {
  40         Object[] c1Array = c1.toArray();
  41         Object[] c2Array = c2.toArray();
  42         
  43         check(c1Array.length == c2Array.length);
  44         for(Object aC1 : c1Array) {
  45             boolean found = false;
  46             for(Object aC2 : c2Array) {
  47                 if(Objects.equals(aC1, aC2)) {
  48                     found = true;
  49                     break;
  50                 }
  51             }
  52             
  53             if(!found) 
  54                 fail(aC1 + " not found in " + Arrays.toString(c2Array));
  55         }
  56     }
  57 
  58     static void compareMaps(Map m1, Map m2) {
  59         compareCollections(m1.keySet(),
  60                            m2.keySet());
  61         compareCollections(m1.values(),
  62                            m2.values());
  63         compareCollections(m1.entrySet(),
  64                            m2.entrySet());
  65     }
  66 
  67     static void compareNavigableMaps(NavigableMap m1, NavigableMap m2) {
  68         compareMaps(m1, m2);
  69         compareMaps(m1.descendingMap(),
  70                     m2.descendingMap());
  71         compareMaps(m1.tailMap(Integer.MIN_VALUE),
  72                     m2.tailMap(Integer.MIN_VALUE));
  73         compareMaps(m1.headMap(Integer.MAX_VALUE),
  74                     m2.headMap(Integer.MAX_VALUE));
  75     }