Package gnu.trove.list

Examples of gnu.trove.list.TIntList



    public void testInsert() {
        int element_count = 10;

        TIntList a = new TIntLinkedList();
        assertTrue( a.isEmpty() );

        for ( int i = 1; i <= element_count; i++ ) {
            a.add( i );
        }

        int testval = 1138;
        a.insert( 5, testval );

        for ( int i = 0; i < 5; i++ ) {
            int result = a.get( i );
            int expected = i + 1;
            assertTrue( "element " + result + " should be " + expected,
                    result == expected );
        }

        assertEquals( testval, a.get( 5 ) );

        for ( int i = 6; i < a.size(); i++ ) {
            int result = a.get( i );
            assertTrue("element " + result + " should be " + i,
                    result == i);
        }
    }
View Full Code Here



    public void testInsertAtEnd() {
        int element_count = 10;

        TIntList a = new TIntArrayList();
        assertTrue( a.isEmpty() );

        for ( int i = 1; i <= element_count; i++ ) {
            a.add( i );
        }

        a.insert( a.size(), 11 );

        for ( int i = 0; i < element_count; i++ ) {
            assertEquals( i + 1, a.get( i ) );
        }
        for ( int i = element_count;
              i < a.size();
              i++ ) {
            int expected = i + 1;
            assertEquals( expected, a.get( i ) );
        }
    }
View Full Code Here

    public void testInsertArrayAtEnd() {
        int element_count = 10;
        int[] ints = {1138, 42, 86, 99, 101};

        TIntList a = new TIntArrayList();
        assertTrue( a.isEmpty() );

        for ( int i = 1; i <= element_count; i++ ) {
            a.add( i );
        }

        a.insert( a.size(), ints );

        for ( int i = 0; i < element_count; i++ ) {
            assertEquals( i + 1, a.get( i ) );
        }
        for ( int i = element_count, j = 0;
              i < ints.length + element_count;
              i++, j++ ) {
            assertEquals( ints[j], a.get( i ) );
        }
    }
View Full Code Here

    public void testInsertArray() {
        int element_count = 10;
        int[] ints = {1138, 42, 86, 99, 101};

        TIntList a = new TIntLinkedList();
        assertTrue( a.isEmpty() );

        for ( int i = 1; i <= element_count; i++ ) {
            a.add( i );
        }

        a.insert( 0, ints );
        assertEquals(ints.length + element_count, a.size());

        for ( int i = 0; i < ints.length; i++ ) {
            assertEquals( ints[i], a.get( i ) );
        }
        for ( int i = ints.length, j = 1;
              i < ints.length + element_count;
              i++, j++ ) {
            assertEquals( j, a.get( i ) );
        }
    }
View Full Code Here


    public void testInsertAtEnd() {
        int element_count = 10;

        TIntList a = new TIntLinkedList();
        assertTrue( a.isEmpty() );

        for ( int i = 1; i <= element_count; i++ ) {
            a.add( i );
        }

        a.insert( a.size(), 11 );

        for ( int i = 0; i < element_count; i++ ) {
            assertEquals( i + 1, a.get( i ) );
        }
        for ( int i = element_count;
              i < a.size();
              i++ ) {
            int expected = i + 1;
            assertEquals( expected, a.get( i ) );
        }
    }
View Full Code Here

    public void testSetArray() {
        int element_count = 10;
        int[] ints = {1138, 42, 86, 99, 101};

        TIntList a = new TIntArrayList();
        assertTrue( a.isEmpty() );

        for ( int i = 1; i <= element_count; i++ ) {
            a.add( i );
        }

        a.set( a.size() - ints.length, ints );

        for ( int i = 0; i < element_count - ints.length; i++ ) {
            assertEquals( i + 1, a.get( i ) );
        }
        for ( int i = element_count - ints.length, j = 0;
              i < a.size();
              i++, j++ ) {
            assertEquals( ints[j], a.get( i ) );
        }

        try {
            a.set( a.size(), ints );
            fail( "Expected IndexOutOfBoundsException" );
        }
        catch ( IndexOutOfBoundsException ex ) {
            // Expected
        }
View Full Code Here

    public void testInsertArrayAtEnd() {
        int element_count = 10;
        int[] ints = {1138, 42, 86, 99, 101};

        TIntList a = new TIntLinkedList();
        assertTrue( a.isEmpty() );

        for ( int i = 1; i <= element_count; i++ ) {
            a.add( i );
        }

        a.insert(a.size(), ints);

        for ( int i = 0; i < element_count; i++ ) {
            assertEquals( i + 1, a.get( i ) );
        }
        for ( int i = element_count, j = 0;
              i < ints.length + element_count;
              i++, j++ ) {
            assertEquals( ints[j], a.get( i ) );
        }
    }
View Full Code Here


    public void testSet() {
        int element_count = 10;

        TIntList a = new TIntArrayList();
        assertTrue( a.isEmpty() );

        for ( int i = 1; i <= element_count; i++ ) {
            a.add( i );
        }

        int testval = 1138;
        a.set( 5, testval );

        for ( int i = 0; i < 5; i++ ) {
            int result = a.get( i );
            int expected = i + 1;
            assertTrue( "element " + result + " should be " + expected,
                    result == expected );
        }

        assertEquals( testval, a.get( 5 ) );

        for ( int i = 6; i < a.size(); i++ ) {
            int result = a.get( i );
            int expected = i + 1;
            assertTrue( "element " + result + " should be " + expected,
                    result == expected );
        }

        try {
            a.set( 100, 20 );
            fail( "Expected IndexOutOfBoundsException" );
        }
        catch ( IndexOutOfBoundsException ex ) {
            // Expected
        }
View Full Code Here

    public void testSetArray() {
        int element_count = 10;
        int[] ints = {1138, 42, 86, 99, 101};

        TIntList a = new TIntLinkedList();
        assertTrue( a.isEmpty() );

        for ( int i = 1; i <= element_count; i++ ) {
            a.add( i );
        }

        a.set( a.size() - ints.length, ints );

        for ( int i = 0; i < element_count - ints.length; i++ ) {
            assertEquals(i + 1, a.get(i));
        }
        for ( int i = element_count - ints.length, j = 0;
              i < a.size();
              i++, j++ ) {
            assertEquals(ints[j], a.get(i));
        }

        try {
            a.set( a.size(), ints );
            fail( "Expected IndexOutOfBoundsException" );
        }
        catch ( IndexOutOfBoundsException ex ) {
            // Expected
        }
View Full Code Here


    public void testReplace() {
        int element_count = 10;

        TIntList a = new TIntArrayList();
        assertTrue( a.isEmpty() );

        for ( int i = 1; i <= element_count; i++ ) {
            a.add( i );
        }

        int testval = 1138;
        assertEquals( 6, a.replace( 5, testval ) );

        for ( int i = 0; i < 5; i++ ) {
            int result = a.get( i );
            int expected = i + 1;
            assertTrue( "element " + result + " should be " + expected,
                    result == expected );
        }

        assertEquals( testval, a.get( 5 ) );

        for ( int i = 6; i < a.size(); i++ ) {
            int result = a.get( i );
            int expected = i + 1;
            assertTrue( "element " + result + " should be " + expected,
                    result == expected );
        }

        try {
            a.replace( 100, 20 );
            fail( "Expected IndexOutOfBoundsException" );
        }
        catch ( IndexOutOfBoundsException ex ) {
            // Expected
        }
View Full Code Here

TOP

Related Classes of gnu.trove.list.TIntList

Copyright © 2018 www.massapicom. 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.