Package com.mobixess.jodb.tests

Source Code of com.mobixess.jodb.tests.UnitTests

/*
Copyright (C) 2007  Mobixess Inc. http://www.java-objects-database.com

This file is part of the JODB (Java Objects Database) open source project.

JODB is free software; you can redistribute it and/or modify it under
the terms of version 2 of the GNU General Public License as published
by the Free Software Foundation.

JODB is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package com.mobixess.jodb.tests;

import com.mobixess.jodb.core.query.LArrayChunkedBuffer;

public class UnitTests {

    /**
     * @param args
     */
    public static void main(String[] args) {
        testLongChunkBuffer();
    }
   
    public static void testLongChunkBuffer(){
        LArrayChunkedBuffer arrayChunkedBuffer = new LArrayChunkedBuffer();
        if(arrayChunkedBuffer.hasNext()){
            throw new RuntimeException();
        }
        int max = 2000;
        for (int i = 0; i < max; i++) {
            arrayChunkedBuffer.add(i);
        }
       
        for (int i = 0; i < max; i++) {
            if(!arrayChunkedBuffer.hasNext()){
                throw new RuntimeException();
            }
            if(arrayChunkedBuffer.next()!=i){
                throw new RuntimeException();
            }
        }
       
        arrayChunkedBuffer.setIteratorDirection(false);
       
        for (int i = max-1; i >= 0 ; i--) {
            if(!arrayChunkedBuffer.hasNext()){
                throw new RuntimeException();
            }
            if(arrayChunkedBuffer.next()!=i){
                throw new RuntimeException();
            }
        }
       
        long[] bufferAsArray = arrayChunkedBuffer.toArray();
       
        for (int i = 0; i < bufferAsArray.length; i++) {
            if(bufferAsArray[i]!=max-i-1){
                throw new RuntimeException();
            }
        }
       
        arrayChunkedBuffer.setIteratorDirection(true);
       

        bufferAsArray = arrayChunkedBuffer.toArray();

        for (int i = 0; i < bufferAsArray.length; i++) {
            if (bufferAsArray[i] != i) {
                throw new RuntimeException();
            }
        }
    }

}
TOP

Related Classes of com.mobixess.jodb.tests.UnitTests

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.