亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? testprioritybuffer.java

?? iBATIS似乎已遠離眾說紛紜的OR框架之列
?? JAVA
字號:
/*
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.apache.commons.collections.buffer;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Random;

import junit.framework.Test;
import junit.framework.TestSuite;

import org.apache.commons.collections.Buffer;
import org.apache.commons.collections.BufferUnderflowException;
import org.apache.commons.collections.ComparatorUtils;
import org.apache.commons.collections.collection.AbstractTestCollection;
import org.apache.commons.collections.comparators.ComparableComparator;
import org.apache.commons.collections.comparators.ReverseComparator;

/**
 * Tests the PriorityBuffer.
 * 
 * @version $Revision: 646780 $ $Date: 2008-04-10 13:48:07 +0100 (Thu, 10 Apr 2008) $
 * 
 * @author Michael A. Smith
 * @author Steve Phelps
 */
public class TestPriorityBuffer extends AbstractTestCollection {

    public static void main(String[] args) {
        junit.textui.TestRunner.run(suite());
    }

    public static Test suite() {
        return new TestSuite(TestPriorityBuffer.class);
    }

    public TestPriorityBuffer(String testName) {
        super(testName);
    }

    //-----------------------------------------------------------------------  
    public void verify() {
        super.verify();
        PriorityBuffer heap = (PriorityBuffer) collection;

        Comparator c = heap.comparator;
        if (c == null) {
            c = ComparatorUtils.naturalComparator();
        }
        if (!heap.ascendingOrder) {
            c = ComparatorUtils.reversedComparator(c);
        }

        Object[] tree = heap.elements;
        for (int i = 1; i <= heap.size; i++) {
            Object parent = tree[i];
            if (i * 2 <= heap.size) {
                assertTrue("Parent is less than or equal to its left child", c.compare(parent, tree[i * 2]) <= 0);
            }
            if (i * 2 + 1 < heap.size) {
                assertTrue("Parent is less than or equal to its right child", c.compare(parent, tree[i * 2 + 1]) <= 0);
            }
        }
    }

    //-----------------------------------------------------------------------  
    /**
     * Overridden because BinaryBuffer isn't fail fast.
     * @return false
     */
    public boolean isFailFastSupported() {
        return false;
    }

    //-----------------------------------------------------------------------  
    public Collection makeConfirmedCollection() {
        return new ArrayList();
    }

    public Collection makeConfirmedFullCollection() {
        ArrayList list = new ArrayList();
        list.addAll(Arrays.asList(getFullElements()));
        return list;
    }

    /**
     * Return a new, empty {@link Object} to used for testing.
     */
    public Collection makeCollection() {
        return new PriorityBuffer();
    }

    //-----------------------------------------------------------------------  
    public Object[] getFullElements() {
        return getFullNonNullStringElements();
    }

    public Object[] getOtherElements() {
        return getOtherNonNullStringElements();
    }

    //-----------------------------------------------------------------------  
    public void testBufferEmpty() {
        resetEmpty();
        Buffer buffer = (Buffer) collection;

        assertEquals(0, buffer.size());
        assertEquals(true, buffer.isEmpty());
        try {
            buffer.get();
            fail();
        } catch (BufferUnderflowException ex) {}

        try {
            buffer.remove();
            fail();
        } catch (BufferUnderflowException ex) {}
    }
    
    public void testBasicOps() {
        PriorityBuffer heap = new PriorityBuffer();

        heap.add("a");
        heap.add("c");
        heap.add("e");
        heap.add("b");
        heap.add("d");
        heap.add("n");
        heap.add("m");
        heap.add("l");
        heap.add("k");
        heap.add("j");
        heap.add("i");
        heap.add("h");
        heap.add("g");
        heap.add("f");

        assertTrue("heap should not be empty after adds", !heap.isEmpty());

        for (int i = 0; i < 14; i++) {
            assertEquals(
                "get using default constructor should return minimum value in the binary heap",
                String.valueOf((char) ('a' + i)),
                heap.get());

            assertEquals(
                "remove using default constructor should return minimum value in the binary heap",
                String.valueOf((char) ('a' + i)),
                heap.remove());

            if (i + 1 < 14) {
                assertTrue("heap should not be empty before all elements are removed", !heap.isEmpty());
            } else {
                assertTrue("heap should be empty after all elements are removed", heap.isEmpty());
            }
        }

        try {
            heap.get();
            fail("NoSuchElementException should be thrown if get is called after all elements are removed");
        } catch (BufferUnderflowException ex) {}

        try {
            heap.remove();
            fail("NoSuchElementException should be thrown if remove is called after all elements are removed");
        } catch (BufferUnderflowException ex) {}
    }

    public void testBasicComparatorOps() {
        PriorityBuffer heap = new PriorityBuffer(new ReverseComparator(new ComparableComparator()));

        assertTrue("heap should be empty after create", heap.isEmpty());

        try {
            heap.get();
            fail("NoSuchElementException should be thrown if get is called before any elements are added");
        } catch (BufferUnderflowException ex) {}

        try {
            heap.remove();
            fail("NoSuchElementException should be thrown if remove is called before any elements are added");
        } catch (BufferUnderflowException ex) {}

        heap.add("a");
        heap.add("c");
        heap.add("e");
        heap.add("b");
        heap.add("d");
        heap.add("n");
        heap.add("m");
        heap.add("l");
        heap.add("k");
        heap.add("j");
        heap.add("i");
        heap.add("h");
        heap.add("g");
        heap.add("f");

        assertTrue("heap should not be empty after adds", !heap.isEmpty());

        for (int i = 0; i < 14; i++) {

            // note: since we're using a comparator that reverses items, the
            // "minimum" item is "n", and the "maximum" item is "a".

            assertEquals(
                "get using default constructor should return minimum value in the binary heap",
                String.valueOf((char) ('n' - i)),
                heap.get());

            assertEquals(
                "remove using default constructor should return minimum value in the binary heap",
                String.valueOf((char) ('n' - i)),
                heap.remove());

            if (i + 1 < 14) {
                assertTrue("heap should not be empty before all elements are removed", !heap.isEmpty());
            } else {
                assertTrue("heap should be empty after all elements are removed", heap.isEmpty());
            }
        }

        try {
            heap.get();
            fail("NoSuchElementException should be thrown if get is called after all elements are removed");
        } catch (BufferUnderflowException ex) {}

        try {
            heap.remove();
            fail("NoSuchElementException should be thrown if remove is called after all elements are removed");
        } catch (BufferUnderflowException ex) {}
    }

    /**
     * Illustrates bad internal heap state reported in Bugzilla PR #235818. 
     */  
    public void testAddRemove() {
        resetEmpty();
        PriorityBuffer heap = (PriorityBuffer) collection;
        heap.add(new Integer(0));
        heap.add(new Integer(2));
        heap.add(new Integer(4));
        heap.add(new Integer(3));
        heap.add(new Integer(8));
        heap.add(new Integer(10));
        heap.add(new Integer(12));
        heap.add(new Integer(3));
        confirmed.addAll(heap);
        // System.out.println(heap);
        Object obj = new Integer(10);
        heap.remove(obj);
        confirmed.remove(obj);
        // System.out.println(heap);
        verify();
    }
    
    /**
     * Generate heaps staring with Integers from 0 - heapSize - 1.
     * Then perform random add / remove operations, checking
     * heap order after modifications. Alternates minHeaps, maxHeaps.
     *
     * Based on code provided by Steve Phelps in PR #25818
     *
     */
    public void testRandom() {
        int iterations = 500;
        int heapSize = 100;
        int operations = 20;
        Random randGenerator = new Random();
        PriorityBuffer h = null;
        for(int i=0; i < iterations; i++) {
            if (i < iterations / 2) {          
                h = new PriorityBuffer(true);
            } else {
                h = new PriorityBuffer(false);
            }
            for(int r = 0; r < heapSize; r++) {
                h.add( new Integer( randGenerator.nextInt(heapSize)) );
            }
            for( int r = 0; r < operations; r++ ) {
                h.remove(new Integer(r));
                h.add(new Integer(randGenerator.nextInt(heapSize)));
            }
            checkOrder(h);
        }
    }
     
    /**
     * Pops all elements from the heap and verifies that the elements come off
     * in the correct order.  NOTE: this method empties the heap.
     */
    protected void checkOrder(PriorityBuffer h) {
        Integer lastNum = null;
        Integer num = null;
        while (!h.isEmpty()) {
            num = (Integer) h.remove();
            if (h.ascendingOrder) {
                assertTrue(lastNum == null || num.intValue() >= lastNum.intValue());
            } else { // max heap
                assertTrue(lastNum == null || num.intValue() <= lastNum.intValue());
            }
            lastNum = num;
            num = null;
        }
    }
    
    /**
     * Returns a string showing the contents of the heap formatted as a tree.
     * Makes no attempt at padding levels or handling wrapping. 
     */
    protected String showTree(PriorityBuffer h) {
        int count = 1;
        StringBuffer buffer = new StringBuffer();
        for (int offset = 1; count < h.size() + 1; offset *= 2) {
            for (int i = offset; i < offset * 2; i++) {
                if (i < h.elements.length && h.elements[i] != null) 
                    buffer.append(h.elements[i] + " ");
                count++;
            }
            buffer.append('\n');
        }
        return buffer.toString();
    }

    /**
     * Generates 500 randomly initialized heaps of size 100
     * and tests that after serializing and restoring them to a byte array
     * that the following conditions hold:
     * 
     *  - the size of the restored heap is the same 
     *      as the size of the orignal heap
     *  
     *  - all elements in the original heap are present in the restored heap
     *  
     *  - the heap order of the restored heap is intact as 
     *      verified by checkOrder()
     */
    public void testSerialization() {
        int iterations = 500;
        int heapSize = 100;
        PriorityBuffer h;
        Random randGenerator = new Random();
        for (int i = 0; i < iterations; i++) {
            if (i < iterations / 2) {
                h = new PriorityBuffer(true);
            } else {
                h = new PriorityBuffer(false);
            }
            for (int r = 0; r < heapSize; r++) {
                h.add(new Integer(randGenerator.nextInt(heapSize)));
            }
            assertTrue(h.size() == heapSize);
            PriorityBuffer h1 = serializeAndRestore(h);
            assertTrue(h1.size() == heapSize);
            Iterator hit = h.iterator();
            while (hit.hasNext()) {
                Integer n = (Integer) hit.next();
                assertTrue(h1.contains(n));
            }
            checkOrder(h1);
        }
    }

    public PriorityBuffer serializeAndRestore(PriorityBuffer h) {
        PriorityBuffer h1 = null;
        try {
            byte[] objekt = writeExternalFormToBytes(h);
            h1 = (PriorityBuffer) readExternalFormFromBytes(objekt);
        } catch (IOException e) {
            e.printStackTrace();
            fail(e.toString());
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            fail(e.toString());
        }
        return h1;
    }

    public String getCompatibilityVersion() {
        return "3.2";
    }

//    public void testCreate() throws Exception {
//        resetEmpty();
//        writeExternalFormToDisk((java.io.Serializable) collection, "C:/commons/collections/data/test/PriorityBuffer.emptyCollection.version3.2.obj");
//        resetFull();
//        writeExternalFormToDisk((java.io.Serializable) collection, "C:/commons/collections/data/test/PriorityBuffer.fullCollection.version3.2.obj");
//    }

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
全国精品久久少妇| 白白色 亚洲乱淫| 亚洲影院在线观看| 亚洲男人的天堂网| 亚洲人精品午夜| 国产精品久久久一本精品 | 欧美在线看片a免费观看| 99久久免费精品高清特色大片| 国产精品亚洲一区二区三区在线| 精品一区二区三区免费毛片爱| 老司机免费视频一区二区| 老司机免费视频一区二区| 老司机一区二区| 国产一区91精品张津瑜| 国产一区二区三区在线观看精品| 国产自产高清不卡| 风间由美一区二区av101 | 99久久婷婷国产| 色吊一区二区三区| 欧美日韩午夜在线| 日韩一区二区视频| 26uuu精品一区二区三区四区在线| 精品少妇一区二区三区在线播放| 欧美成人女星排行榜| 久久精品一区蜜桃臀影院| 国产欧美一区二区三区沐欲| 国产精品乱人伦| 成人欧美一区二区三区黑人麻豆| 亚洲男女一区二区三区| 日韩一区欧美二区| 国产老肥熟一区二区三区| 丁香五精品蜜臀久久久久99网站| 91色九色蝌蚪| 欧美浪妇xxxx高跟鞋交| 日韩精品一区二区三区在线观看| 久久久久久久久久久久电影 | 亚洲午夜电影网| 午夜精品久久久久久不卡8050| 免费在线看成人av| 国产白丝精品91爽爽久久| 91丨九色丨国产丨porny| 欧美福利视频导航| 久久网这里都是精品| 中文字幕亚洲在| 日韩二区三区在线观看| 国产福利91精品一区| 日本电影欧美片| 欧美电影免费观看高清完整版在 | 亚洲精品中文字幕乱码三区| 日韩av网站免费在线| 国产成人在线视频免费播放| 日本黄色一区二区| 亚洲精品一区二区三区精华液| 亚洲欧洲精品一区二区三区不卡| 天堂久久一区二区三区| 国产激情精品久久久第一区二区 | 97精品国产97久久久久久久久久久久 | 国产成人在线影院 | 国产精品久久久爽爽爽麻豆色哟哟| 亚洲男人天堂av网| 久久国内精品视频| 91浏览器打开| 精品美女在线观看| 亚洲国产日韩一级| 不卡影院免费观看| 精品久久久久久无| 亚洲电影一区二区| jizz一区二区| 日韩视频一区二区| 夜夜嗨av一区二区三区网页 | 色综合亚洲欧洲| 精品国产免费人成电影在线观看四季| 一区二区三区视频在线看| 国产精品99久久久久| 欧美一卡2卡3卡4卡| 一区二区三区在线视频播放| 国产河南妇女毛片精品久久久 | 国产免费成人在线视频| 爽好久久久欧美精品| 色婷婷综合激情| 国产精品色眯眯| 狠狠色丁香久久婷婷综合_中| 欧美日韩一区二区欧美激情| 欧美国产日韩精品免费观看| 久久黄色级2电影| 91精品婷婷国产综合久久性色| 一区二区三区在线免费视频| 成人av电影在线| 国产亚洲精品7777| 国产一本一道久久香蕉| 日韩精品自拍偷拍| 日本不卡视频在线观看| 精品视频一区二区三区免费| 亚洲免费观看视频| 色婷婷综合久久久中文字幕| 亚洲同性同志一二三专区| 成人av影院在线| 国产精品福利影院| 成人av资源在线| 中文字幕中文字幕中文字幕亚洲无线| 国产经典欧美精品| 国产精品每日更新| 成人国产精品免费观看视频| 中文无字幕一区二区三区| 成人精品免费看| 中文字幕av一区二区三区高 | 在线中文字幕一区二区| 亚洲欧洲中文日韩久久av乱码| 99久久精品费精品国产一区二区| 国产精品女主播av| 99久久久久久| 亚洲精品国产a| 欧美少妇一区二区| 石原莉奈在线亚洲二区| 欧美日韩国产一二三| 视频一区中文字幕| 欧美一区二区啪啪| 寂寞少妇一区二区三区| 久久久久久久久久美女| 成人美女在线视频| 亚洲手机成人高清视频| 精品久久久影院| 国产91在线|亚洲| 国产精品美女视频| 91久久精品国产91性色tv| 亚洲伊人色欲综合网| 欧美精品三级在线观看| 麻豆国产欧美一区二区三区| 欧美精品一区二区三| 国产高清不卡一区二区| 亚洲欧美日韩国产成人精品影院| 欧美日韩一区二区三区免费看| 蜜臀av在线播放一区二区三区| 亚洲精品一区二区三区影院| 成人av资源下载| 亚洲一区二区在线视频| 91精品国产色综合久久| 国内精品自线一区二区三区视频| 中文无字幕一区二区三区| 91免费版pro下载短视频| 亚洲福利视频导航| 精品成人一区二区三区四区| 国产成人在线网站| 天堂久久一区二区三区| 久久久久88色偷偷免费| 99麻豆久久久国产精品免费| 琪琪久久久久日韩精品| 国产精品视频一区二区三区不卡| 欧美综合在线视频| 国产精品一区一区三区| 亚洲精品v日韩精品| 日韩美女在线视频| 99久久国产综合精品色伊| 蜜臀久久久99精品久久久久久| 国产精品免费观看视频| 欧美一区二区三区成人| 99国产欧美另类久久久精品| 日韩精品一二三四| 国产精品免费aⅴ片在线观看| 制服丝袜中文字幕一区| 成人免费毛片a| 蜜臀av一区二区| 一卡二卡三卡日韩欧美| 国产午夜精品久久久久久免费视 | 97久久超碰国产精品| 理论电影国产精品| 亚洲影院久久精品| 中文字幕一区二| www国产精品av| 91麻豆精品国产91久久久| 9l国产精品久久久久麻豆| 蜜桃精品在线观看| 亚洲一区二区三区爽爽爽爽爽| 国产丝袜美腿一区二区三区| 91精品午夜视频| 欧美中文字幕久久 | 国产精品色婷婷久久58| 日韩一区二区精品在线观看| 欧美专区日韩专区| www.欧美日韩国产在线| 国产一区91精品张津瑜| 久久精品国产精品亚洲综合| 亚洲成精国产精品女| 中文字幕一区二区三区在线不卡| 精品91自产拍在线观看一区| 91精品国产手机| 欧美三级电影一区| 色婷婷久久99综合精品jk白丝| 成人一级片在线观看| 激情综合色播激情啊| 男男成人高潮片免费网站| 日韩综合在线视频| 亚洲国产中文字幕| 亚洲最大成人网4388xx| 一区二区三区欧美日韩| 亚洲色图第一区| 亚洲欧美中日韩| 国产精品免费久久| 国产精品久久久久久久久久久免费看| 久久久久国产精品麻豆ai换脸|