< prev index next >

test/jdk/java/util/Spliterator/SpliteratorTraversingAndSplittingTest.java

Print this page

   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 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  * @summary Spliterator traversing and splitting tests
  27  * @library /lib/testlibrary/bootlib

  28  * @build java.base/java.util.SpliteratorOfIntDataBuilder
  29  *        java.base/java.util.SpliteratorTestHelper
  30  * @run testng SpliteratorTraversingAndSplittingTest
  31  * @bug 8020016 8071477 8072784 8169838

  32  */
  33 


  34 import org.testng.annotations.DataProvider;
  35 import org.testng.annotations.Test;
  36 
  37 import java.nio.CharBuffer;
  38 import java.util.AbstractCollection;
  39 import java.util.AbstractList;
  40 import java.util.AbstractSet;
  41 import java.util.ArrayDeque;
  42 import java.util.ArrayList;
  43 import java.util.Arrays;
  44 import java.util.Collection;
  45 import java.util.Collections;
  46 import java.util.Comparator;
  47 import java.util.HashMap;
  48 import java.util.HashSet;
  49 import java.util.IdentityHashMap;
  50 import java.util.Iterator;
  51 import java.util.LinkedHashMap;
  52 import java.util.LinkedHashSet;
  53 import java.util.LinkedList;

 629 
 630             db.addMap(m -> {
 631                 // Create a Map ensuring that for large sizes
 632                 // buckets will contain 2 or more entries
 633                 HashMap<Integer, Integer> cm = new HashMap<>(1, m.size() + 1);
 634                 // Don't use putAll which inflates the table by
 635                 // m.size() * loadFactor, thus creating a very sparse
 636                 // map for 1000 entries defeating the purpose of this test,
 637                 // in addition it will cause the split until null test to fail
 638                 // because the number of valid splits is larger than the
 639                 // threshold
 640                 for (Map.Entry<Integer, Integer> e : m.entrySet())
 641                     cm.put(e.getKey(), e.getValue());
 642                 return cm;
 643             }, "new java.util.HashMap(1, size + 1)");
 644 
 645             db.addMap(LinkedHashMap::new);
 646 
 647             db.addMap(IdentityHashMap::new);
 648 
 649             db.addMap(WeakHashMap::new);
 650 
 651             db.addMap(m -> {
 652                 // Create a Map ensuring that for large sizes
 653                 // buckets will be consist of 2 or more entries
 654                 WeakHashMap<Integer, Integer> cm = new WeakHashMap<>(1, m.size() + 1);
 655                 for (Map.Entry<Integer, Integer> e : m.entrySet())
 656                     cm.put(e.getKey(), e.getValue());
 657                 return cm;
 658             }, "new java.util.WeakHashMap(1, size + 1)");



 659 
 660             db.addMap(TreeMap::new);
 661             db.addMap(m -> new TreeMap<>(m).tailMap(Integer.MIN_VALUE));
 662             db.addMap(m -> new TreeMap<>(m).headMap(Integer.MAX_VALUE));
 663             db.addMap(m -> new TreeMap<>(m).subMap(Integer.MIN_VALUE, Integer.MAX_VALUE));
 664             db.addDescendingMap(m -> new TreeMap<>(m).descendingMap());
 665             db.addDescendingMap(m -> new TreeMap<>(m).descendingMap().tailMap(Integer.MAX_VALUE));
 666             db.addDescendingMap(m -> new TreeMap<>(m).descendingMap().headMap(Integer.MIN_VALUE));
 667             db.addDescendingMap(m -> new TreeMap<>(m).descendingMap().subMap(Integer.MAX_VALUE, Integer.MIN_VALUE));
 668 
 669             db.addMap(ConcurrentHashMap::new);
 670 
 671             db.addMap(ConcurrentSkipListMap::new);
 672 
 673             if (size == 0) {
 674                 db.addMap(m -> Collections.<Integer, Integer>emptyMap());
 675             }
 676             else if (size == 1) {
 677                 db.addMap(m -> Collections.singletonMap(exp.get(0), exp.get(0)));
 678             }

   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 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  * @summary Spliterator traversing and splitting tests
  27  * @library /lib/testlibrary/bootlib
  28  * @modules java.base/jdk.internal.misc
  29  * @build java.base/java.util.SpliteratorOfIntDataBuilder
  30  *        java.base/java.util.SpliteratorTestHelper
  31  * @run testng SpliteratorTraversingAndSplittingTest
  32  * @run testng/othervm --enable-preview SpliteratorTraversingAndSplittingTest
  33  * @bug 8020016 8071477 8072784 8169838 8336672
  34  */
  35 
  36 import jdk.internal.misc.PreviewFeatures;
  37 
  38 import org.testng.annotations.DataProvider;
  39 import org.testng.annotations.Test;
  40 
  41 import java.nio.CharBuffer;
  42 import java.util.AbstractCollection;
  43 import java.util.AbstractList;
  44 import java.util.AbstractSet;
  45 import java.util.ArrayDeque;
  46 import java.util.ArrayList;
  47 import java.util.Arrays;
  48 import java.util.Collection;
  49 import java.util.Collections;
  50 import java.util.Comparator;
  51 import java.util.HashMap;
  52 import java.util.HashSet;
  53 import java.util.IdentityHashMap;
  54 import java.util.Iterator;
  55 import java.util.LinkedHashMap;
  56 import java.util.LinkedHashSet;
  57 import java.util.LinkedList;

 633 
 634             db.addMap(m -> {
 635                 // Create a Map ensuring that for large sizes
 636                 // buckets will contain 2 or more entries
 637                 HashMap<Integer, Integer> cm = new HashMap<>(1, m.size() + 1);
 638                 // Don't use putAll which inflates the table by
 639                 // m.size() * loadFactor, thus creating a very sparse
 640                 // map for 1000 entries defeating the purpose of this test,
 641                 // in addition it will cause the split until null test to fail
 642                 // because the number of valid splits is larger than the
 643                 // threshold
 644                 for (Map.Entry<Integer, Integer> e : m.entrySet())
 645                     cm.put(e.getKey(), e.getValue());
 646                 return cm;
 647             }, "new java.util.HashMap(1, size + 1)");
 648 
 649             db.addMap(LinkedHashMap::new);
 650 
 651             db.addMap(IdentityHashMap::new);
 652 
 653             if (!PreviewFeatures.isEnabled()) {
 654                 // With --enable-preview, WeakHashmap is not tested with Integer, a value class
 655                 db.addMap(WeakHashMap::new);
 656 
 657                 db.addMap(m -> {
 658                     // Create a Map ensuring that for large sizes
 659                     // buckets will consist of 2 or more entries
 660                     WeakHashMap<Integer, Integer> cm = new WeakHashMap<>(1, m.size() + 1);
 661                     for (Map.Entry<Integer, Integer> e : m.entrySet())
 662                         cm.put(e.getKey(), e.getValue());
 663                     return cm;
 664                 }, "new java.util.WeakHashMap(1, size + 1)");
 665             }
 666 
 667             db.addMap(TreeMap::new);
 668             db.addMap(m -> new TreeMap<>(m).tailMap(Integer.MIN_VALUE));
 669             db.addMap(m -> new TreeMap<>(m).headMap(Integer.MAX_VALUE));
 670             db.addMap(m -> new TreeMap<>(m).subMap(Integer.MIN_VALUE, Integer.MAX_VALUE));
 671             db.addDescendingMap(m -> new TreeMap<>(m).descendingMap());
 672             db.addDescendingMap(m -> new TreeMap<>(m).descendingMap().tailMap(Integer.MAX_VALUE));
 673             db.addDescendingMap(m -> new TreeMap<>(m).descendingMap().headMap(Integer.MIN_VALUE));
 674             db.addDescendingMap(m -> new TreeMap<>(m).descendingMap().subMap(Integer.MAX_VALUE, Integer.MIN_VALUE));
 675 
 676             db.addMap(ConcurrentHashMap::new);
 677 
 678             db.addMap(ConcurrentSkipListMap::new);
 679 
 680             if (size == 0) {
 681                 db.addMap(m -> Collections.<Integer, Integer>emptyMap());
 682             }
 683             else if (size == 1) {
 684                 db.addMap(m -> Collections.singletonMap(exp.get(0), exp.get(0)));
 685             }
< prev index next >