⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 concurrentskiplistsettest.java

📁 SRI international 发布的OAA框架软件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * Written by Doug Lea with assistance from members of JCP JSR-166
 * Expert Group and released to the public domain, as explained at
 * http://creativecommons.org/licenses/publicdomain
 */

import junit.framework.*;
import java.util.*;
import edu.emory.mathcs.backport.java.util.concurrent.*;
import java.io.*;

public class ConcurrentSkipListSetTest extends JSR166TestCase {
//    public static void main(String[] args) {
//	junit.textui.TestRunner.run (suite());
//    }
//    public static Test suite() {
//	return new TestSuite(ConcurrentSkipListSetTest.class);
//    }
//
//    static class MyReverseComparator implements Comparator {
//        public int compare(Object x, Object y) {
//            int i = ((Integer)x).intValue();
//            int j = ((Integer)y).intValue();
//            if (i < j) return 1;
//            if (i > j) return -1;
//            return 0;
//        }
//    }
//
//    /**
//     * Create a set of given size containing consecutive
//     * Integers 0 ... n.
//     */
//    private ConcurrentSkipListSet populatedSet(int n) {
//        ConcurrentSkipListSet q = new ConcurrentSkipListSet();
//        assertTrue(q.isEmpty());
//	for(int i = n-1; i >= 0; i-=2)
//	    assertTrue(q.add(new Integer(i)));
//	for(int i = (n & 1); i < n; i+=2)
//	    assertTrue(q.add(new Integer(i)));
//        assertFalse(q.isEmpty());
//	assertEquals(n, q.size());
//        return q;
//    }
//
//    /**
//     * Create set of first 5 ints
//     */
//    private ConcurrentSkipListSet set5() {
//        ConcurrentSkipListSet q = new ConcurrentSkipListSet();
//        assertTrue(q.isEmpty());
//        q.add(one);
//        q.add(two);
//        q.add(three);
//        q.add(four);
//        q.add(five);
//	assertEquals(5, q.size());
//        return q;
//    }
//
//    /**
//     * A new set has unbounded capacity
//     */
//    public void testConstructor1() {
//        assertEquals(0, new ConcurrentSkipListSet().size());
//    }
//
//    /**
//     * Initializing from null Collection throws NPE
//     */
//    public void testConstructor3() {
//        try {
//            ConcurrentSkipListSet q = new ConcurrentSkipListSet((Collection)null);
//            shouldThrow();
//        }
//        catch (NullPointerException success) {}
//    }
//
//    /**
//     * Initializing from Collection of null elements throws NPE
//     */
//    public void testConstructor4() {
//        try {
//            Integer[] ints = new Integer[SIZE];
//            ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints));
//            shouldThrow();
//        }
//        catch (NullPointerException success) {}
//    }
//
//    /**
//     * Initializing from Collection with some null elements throws NPE
//     */
//    public void testConstructor5() {
//        try {
//            Integer[] ints = new Integer[SIZE];
//            for (int i = 0; i < SIZE-1; ++i)
//                ints[i] = new Integer(i);
//            ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints));
//            shouldThrow();
//        }
//        catch (NullPointerException success) {}
//    }
//
//    /**
//     * Set contains all elements of collection used to initialize
//     */
//    public void testConstructor6() {
//        try {
//            Integer[] ints = new Integer[SIZE];
//            for (int i = 0; i < SIZE; ++i)
//                ints[i] = new Integer(i);
//            ConcurrentSkipListSet q = new ConcurrentSkipListSet(Arrays.asList(ints));
//            for (int i = 0; i < SIZE; ++i)
//                assertEquals(ints[i], q.pollFirst());
//        }
//        finally {}
//    }
//
//    /**
//     * The comparator used in constructor is used
//     */
//    public void testConstructor7() {
//        try {
//            MyReverseComparator cmp = new MyReverseComparator();
//            ConcurrentSkipListSet q = new ConcurrentSkipListSet(cmp);
//            assertEquals(cmp, q.comparator());
//            Integer[] ints = new Integer[SIZE];
//            for (int i = 0; i < SIZE; ++i)
//                ints[i] = new Integer(i);
//            q.addAll(Arrays.asList(ints));
//            for (int i = SIZE-1; i >= 0; --i)
//                assertEquals(ints[i], q.pollFirst());
//        }
//        finally {}
//    }
//
//    /**
//     * isEmpty is true before add, false after
//     */
//    public void testEmpty() {
//        ConcurrentSkipListSet q = new ConcurrentSkipListSet();
//        assertTrue(q.isEmpty());
//        q.add(new Integer(1));
//        assertFalse(q.isEmpty());
//        q.add(new Integer(2));
//        q.pollFirst();
//        q.pollFirst();
//        assertTrue(q.isEmpty());
//    }
//
//    /**
//     * size changes when elements added and removed
//     */
//    public void testSize() {
//        ConcurrentSkipListSet q = populatedSet(SIZE);
//        for (int i = 0; i < SIZE; ++i) {
//            assertEquals(SIZE-i, q.size());
//            q.pollFirst();
//        }
//        for (int i = 0; i < SIZE; ++i) {
//            assertEquals(i, q.size());
//            q.add(new Integer(i));
//        }
//    }
//
//    /**
//     * add(null) throws NPE
//     */
//    public void testAddNull() {
//	try {
//            ConcurrentSkipListSet q = new ConcurrentSkipListSet();
//            q.add(null);
//            shouldThrow();
//        } catch (NullPointerException success) { }
//    }
//
//    /**
//     * Add of comparable element succeeds
//     */
//    public void testAdd() {
//        ConcurrentSkipListSet q = new ConcurrentSkipListSet();
//        assertTrue(q.add(zero));
//        assertTrue(q.add(one));
//    }
//
//    /**
//     * Add of duplicate element fails
//     */
//    public void testAddDup() {
//        ConcurrentSkipListSet q = new ConcurrentSkipListSet();
//        assertTrue(q.add(zero));
//        assertFalse(q.add(zero));
//    }
//
//    /**
//     * Add of non-Comparable throws CCE
//     */
//    public void testAddNonComparable() {
//        try {
//            ConcurrentSkipListSet q = new ConcurrentSkipListSet();
//            q.add(new Object());
//            q.add(new Object());
//            q.add(new Object());
//            shouldThrow();
//        }
//        catch(ClassCastException success) {}
//    }
//
//    /**
//     * addAll(null) throws NPE
//     */
//    public void testAddAll1() {
//        try {
//            ConcurrentSkipListSet q = new ConcurrentSkipListSet();
//            q.addAll(null);
//            shouldThrow();
//        }
//        catch (NullPointerException success) {}
//    }
//    /**
//     * addAll of a collection with null elements throws NPE
//     */
//    public void testAddAll2() {
//        try {
//            ConcurrentSkipListSet q = new ConcurrentSkipListSet();
//            Integer[] ints = new Integer[SIZE];
//            q.addAll(Arrays.asList(ints));
//            shouldThrow();
//        }
//        catch (NullPointerException success) {}
//    }
//    /**
//     * addAll of a collection with any null elements throws NPE after
//     * possibly adding some elements
//     */
//    public void testAddAll3() {
//        try {
//            ConcurrentSkipListSet q = new ConcurrentSkipListSet();
//            Integer[] ints = new Integer[SIZE];
//            for (int i = 0; i < SIZE-1; ++i)
//                ints[i] = new Integer(i);
//            q.addAll(Arrays.asList(ints));
//            shouldThrow();
//        }
//        catch (NullPointerException success) {}
//    }
//
//    /**
//     * Set contains all elements of successful addAll
//     */
//    public void testAddAll5() {
//        try {
//            Integer[] empty = new Integer[0];
//            Integer[] ints = new Integer[SIZE];
//            for (int i = 0; i < SIZE; ++i)
//                ints[i] = new Integer(SIZE-1-i);
//            ConcurrentSkipListSet q = new ConcurrentSkipListSet();
//            assertFalse(q.addAll(Arrays.asList(empty)));
//            assertTrue(q.addAll(Arrays.asList(ints)));
//            for (int i = 0; i < SIZE; ++i)
//                assertEquals(new Integer(i), q.pollFirst());
//        }
//        finally {}
//    }
//
//    /**
//     * pollFirst succeeds unless empty
//     */
//    public void testPollFirst() {
//        ConcurrentSkipListSet q = populatedSet(SIZE);
//        for (int i = 0; i < SIZE; ++i) {
//            assertEquals(i, ((Integer)q.pollFirst()).intValue());
//        }
//	assertNull(q.pollFirst());
//    }
//
//    /**
//     * pollLast succeeds unless empty
//     */
//    public void testPollLast() {
//        ConcurrentSkipListSet q = populatedSet(SIZE);
//        for (int i = SIZE-1; i >= 0; --i) {
//            assertEquals(i, ((Integer)q.pollLast()).intValue());
//        }
//	assertNull(q.pollFirst());
//    }
//
//
//    /**
//     * remove(x) removes x and returns true if present
//     */
//    public void testRemoveElement() {
//        ConcurrentSkipListSet q = populatedSet(SIZE);
//        for (int i = 1; i < SIZE; i+=2) {
//            assertTrue(q.remove(new Integer(i)));
//        }
//        for (int i = 0; i < SIZE; i+=2) {
//            assertTrue(q.remove(new Integer(i)));
//            assertFalse(q.remove(new Integer(i+1)));
//        }
//        assertTrue(q.isEmpty());
//    }
//
//    /**
//     * contains(x) reports true when elements added but not yet removed
//     */
//    public void testContains() {
//        ConcurrentSkipListSet q = populatedSet(SIZE);
//        for (int i = 0; i < SIZE; ++i) {
//            assertTrue(q.contains(new Integer(i)));
//            q.pollFirst();
//            assertFalse(q.contains(new Integer(i)));
//        }
//    }
//
//    /**
//     * clear removes all elements
//     */
//    public void testClear() {
//        ConcurrentSkipListSet q = populatedSet(SIZE);
//        q.clear();
//        assertTrue(q.isEmpty());
//        assertEquals(0, q.size());
//        q.add(new Integer(1));
//        assertFalse(q.isEmpty());
//        q.clear();
//        assertTrue(q.isEmpty());
//    }
//
//    /**
//     * containsAll(c) is true when c contains a subset of elements
//     */
//    public void testContainsAll() {
//        ConcurrentSkipListSet q = populatedSet(SIZE);
//        ConcurrentSkipListSet p = new ConcurrentSkipListSet();
//        for (int i = 0; i < SIZE; ++i) {
//            assertTrue(q.containsAll(p));
//            assertFalse(p.containsAll(q));
//            p.add(new Integer(i));
//        }
//        assertTrue(p.containsAll(q));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -