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

📄 collectiontest.java

📁 Java的面向对象数据库系统的源代码
💻 JAVA
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// The original code and portions created by SMB are// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.//// $Id$package test.ozoneDB.DxLib;import org.ozoneDB.DxLib.*;/** * * * @author <a href="http://www.softwarebuero.de/">SMB</a> * @version $Revision$Date$ */public class CollectionTest extends AbstractTest {    final static int SIZE = 2000;    public CollectionTest() {        super("testCollections");    }    public CollectionTest(String name) {        super(name);    }    public void testCollections() throws Exception {        Class[] factories =                {DxListBag.class, DxArrayBag.class, DxHashSet.class, DxTreeSet.class, DxHashMap.class, DxTreeMap.class};        CollectionTest collTest = new CollectionTest();        System.out.println("\n*** CollectionTest ***\n");        // add_iterate        for (int i = 0; i < factories.length; i++) {            collTest.add_iterate((DxCollection) factories[i].newInstance(), CollectionTest.newDxStrings());        }        collTest.add_iterate(new DxTreeSet(new DxStringComparator()), CollectionTest.newStrings());        collTest.add_iterate(new DxTreeMap(new DxStringComparator()), CollectionTest.newStrings());        // contains        for (int i = 0; i < factories.length; i++) {            collTest.contains((DxCollection) factories[i].newInstance(), CollectionTest.newDxStrings());        }        collTest.contains(new DxTreeSet(new DxStringComparator()), CollectionTest.newStrings());        collTest.contains(new DxTreeMap(new DxStringComparator()), CollectionTest.newStrings());        // containsAll        for (int i = 0; i < factories.length; i++) {            collTest.containsAll((DxCollection) factories[i].newInstance(), CollectionTest.newDxStrings());        }        // remove_count_isEmpty        for (int i = 0; i < factories.length; i++) {            collTest.remove_count_isEmpty((DxCollection) factories[i].newInstance(), CollectionTest.newDxStrings());        }        // removeAll        for (int i = 0; i < factories.length; i++) {            collTest.removeAll((DxCollection) factories[i].newInstance(), CollectionTest.newDxStrings());        }        // equals        for (int i = 0; i < factories.length; i++) {            collTest.equals((DxCollection) factories[i].newInstance(), (DxCollection) factories[i].newInstance(),                    CollectionTest.newDxStrings());        }        // toArray_clone_clear        for (int i = 0; i < factories.length; i++) {            collTest.toArray_clone_clear((DxCollection) factories[i].newInstance(), CollectionTest.newDxStrings());        }    }    /**     */    public static Object[] newStrings() {        Object[] objs = new Object[SIZE];        for (int i = 0; i < SIZE; i++) {            objs[i] = String.valueOf(i);        }        return objs;    }    /**     */    public static Object[] newIntegers() {        Object[] objs = new Object[SIZE];        for (int i = 0; i < SIZE; i++) {            objs[i] = new Integer(i);        }        return objs;    }    /**     */    public static Object[] newDxStrings() {        Object[] objs = new Object[SIZE];        for (int i = 0; i < SIZE; i++) {            objs[i] = new DxString(String.valueOf(i));        }        return objs;    }    /**     */    public void add_iterate(DxCollection coll, Object[] objs) throws Exception {        startTimer(coll.getClass().getName(), "add_iterate");        for (int i = 0; i < objs.length; i++) {            coll.add(objs[i]);        }        stopTimer();        DxIterator it = coll.iterator();        while (it.next() != null) {            boolean found = false;            Object obj = it.object();            for (int j = 0; j < SIZE; j++) {                if (obj == objs[j]) {                    found = true;                }            }            assertTrue("iterating through collection looking for added object", found);        }        stopTimer();    }    /**     */    public void contains(DxCollection coll, Object[] objs) throws Exception {        for (int i = 0; i < objs.length; i++) {            coll.add(objs[i]);        }        startTimer(coll.getClass().getName(), "contains");        for (int i = 0; i < SIZE; i++) {            assertTrue("contains should report existance of added object", coll.contains(objs[i]));        }        stopTimer();    }    /**     */    public void containsAll(DxCollection coll, Object[] objs) throws Exception {        for (int i = 0; i < objs.length; i++) {            coll.add(objs[i]);        }        DxBag bag = new DxArrayBag();        bag.addAll(objs);        startTimer(coll.getClass().getName(), "containsAll");        assertTrue("contains all should report true for an added collection", coll.containsAll(bag));        assertTrue("contains all should report true for an empty collection", coll.containsAll(new DxArrayBag()));        DxBag emptyBag = new DxArrayBag();        assertFalse("contains all should report false for an empty collection coparing with a populated one", emptyBag.containsAll(coll));        stopTimer();    }    /**     */    public void removeAll(DxCollection coll, Object[] objs) throws Exception {        coll.addAll(objs);        startTimer(coll.getClass().getName(), "removeAll");        DxBag bag = new DxArrayBag();        bag.addAll(objs);        coll.removeAll(bag);        assertFalse("after removeAll there should be no objects", coll.contains(objs[0]));        assertTrue("after removeAll collection should be empty", coll.isEmpty());        assertEquals("after removeAll number of elements should be 0", coll.count(), 0);        stopTimer();    }    /**     */    public void remove_count_isEmpty(DxCollection coll, Object[] objs) throws Exception {        startTimer(coll.getClass().getName(), "remove_count_isEmpty");        assertTrue(coll.isEmpty());        assertEquals(coll.count(),0);        coll.addAll(objs);        coll.remove(objs[0]);        coll.remove(objs[2]);        coll.remove (objs[50]);        assertEquals(coll.count(),(SIZE - 3));        assertFalse(coll.isEmpty());        assertFalse(coll.contains(objs[0]));        assertFalse(coll.contains(objs[2]));        assertFalse(coll.contains(objs[50]));        assertTrue(coll.contains(objs[1]));        stopTimer();    }    /**     */    public void equals(DxCollection coll1, DxCollection coll2, Object[] objs) throws Exception {        coll1.addAll(objs);        assertFalse(coll1.equals(coll2));        coll2.addAll(objs);        startTimer(coll1.getClass().getName(), "equals");        assertEquals(coll1,coll2);        coll2.remove(objs[0]);        assertFalse(coll1.equals(coll2));        stopTimer();    }    /**     */    public void toArray_clone_clear(DxCollection coll, Object[] objs) {        coll.addAll(objs);        DxCollection clone = (DxCollection) coll.clone();        assertEquals(coll, clone);        startTimer(coll.getClass().getName(), "toArray");        Object[] array = coll.toArray();        stopTimer();        coll.clear();        assertFalse(coll.equals(clone));        coll.addAll(array);        assertEquals(coll, clone);    }}

⌨️ 快捷键说明

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