Package gnu.trove.list

Examples of gnu.trove.list.TIntList


    }


    public void testEquals() {
        int element_count = 20;
        TIntList list = new TIntArrayList();
        for ( int i = 1; i <= element_count; i++ ) {
            list.add( i );
        }

        assertEquals( list, list );
        assertEquals( list, new TIntArrayList( list ) );


        TIntCollection collection = new TIntHashSet();
        for ( int i = 1; i <= element_count; i++ ) {
            collection.add( i );
        }

        assertFalse( list.equals( collection ) );

        collection.add( 1138 );
        assertFalse( list.equals( collection ) );

        TIntList other = new TIntArrayList( list );
        other.replace( 10, 1138 );
        assertFalse( list.equals( other ) );
    }
View Full Code Here


        assertEquals( 2, array_too_short[1] );
    }


    public void testSubList() throws Exception {
        TIntList subList = list.subList( 1, 4 );
        assertEquals( 3, subList.size() );
        assertEquals( 2, subList.get( 0 ) );
        assertEquals( 4, subList.get( 2 ) );
    }
View Full Code Here

    }


    public void testRetainAllTCollection() {
        int element_count = 20;
        TIntList other = new TIntArrayList();
        for ( int i = 0; i < element_count; i++ ) {
            other.add( i );
        }

        TIntList list = new TIntArrayList( 20 );
        for ( int i = 0; i < element_count; i++ ) {
            list.add( i );
        }

        assertEquals( element_count, list.size() );
        assertEquals( element_count, other.size() );

        assertFalse( list.retainAll( list ) );

        assertFalse( list.retainAll( other ) );
        assertEquals( element_count, list.size() );
        for ( int i = 0; i < list.size(); i++ ) {
            assertEquals( i , list.get( i ) );
        }

        other.remove( 0 );
        other.remove( 5 );
        other.remove( 10 );
        other.remove( 15 );
        assertTrue( list.retainAll( other ) );
        int expected = element_count - 4;
        assertEquals( expected, list.size() );
        for ( int i = 0; i < list.size(); i++ ) {
            expected = ( int ) Math.floor( i / 4 ) + i + 1;
            assertEquals( "expected: " + expected + ", was: " + list.get( i ) + ", list: " + list,
                expected , list.get( i ) );
        }
    }
View Full Code Here

        int ints[] = new int[element_count];
        for ( int i = 0; i < element_count; i++ ) {
            ints[i] = i;
        }

        TIntList list = new TIntLinkedList( 20 );
        for ( int i = 0; i < element_count; i++ ) {
            list.add( i );
        }

        assertEquals( element_count, list.size() );

        assertFalse( list.retainAll( ints ) );
        assertEquals( element_count, list.size() );
        for ( int i = 0; i < list.size(); i++ ) {
            assertEquals( i , list.get( i ) );
        }

        ints = new int[( element_count - 4 )] ;
        for ( int i = 0, j = 0; i < ints.length; i++, j++ ) {
            if ( i % 4 == 0 ) {
                j++;
            }
            ints[i] = j;
        }
        assertTrue( list.retainAll( ints ) );
        int expected = element_count - 4;
        assertEquals( expected, list.size() );
        for ( int i = 0; i < list.size(); i++ ) {
            expected = ( int ) Math.floor( i / 4 ) + i + 1;
            assertEquals( "expected: " + expected + ", was: " + list.get( i ) + ", list: " + list,
                expected , list.get( i ) );
        }
    }
View Full Code Here

        int ints[] = new int[element_count];
        for ( int i = 0; i < element_count; i++ ) {
            ints[i] = i;
        }

        TIntList list = new TIntArrayList( 20 );
        for ( int i = 0; i < element_count; i++ ) {
            list.add( i );
        }

        assertEquals( element_count, list.size() );

        assertFalse( list.retainAll( ints ) );
        assertEquals( element_count, list.size() );
        for ( int i = 0; i < list.size(); i++ ) {
            assertEquals( i , list.get( i ) );
        }

        ints = new int[( element_count - 4 )] ;
        for ( int i = 0, j = 0; i < ints.length; i++, j++ ) {
            if ( i % 4 == 0 ) {
                j++;
            }
            ints[i] = j;
        }
        assertTrue( list.retainAll( ints ) );
        int expected = element_count - 4;
        assertEquals( expected, list.size() );
        for ( int i = 0; i < list.size(); i++ ) {
            expected = ( int ) Math.floor( i / 4 ) + i + 1;
            assertEquals( "expected: " + expected + ", was: " + list.get( i ) + ", list: " + list,
                expected , list.get( i ) );
        }
    }
View Full Code Here

        SortedSet<Integer> set = new TreeSet<Integer>();
        for ( int i = 0; i < element_count; i++ ) {
            set.add( Integer.valueOf( i ) );
        }

        TIntList list = new TIntLinkedList( 20 );
        for ( int i = 0; i < element_count; i++ ) {
            list.add( i );
        }

        assertEquals( element_count, set.size() );
        assertEquals( element_count, list.size() );

        assertTrue( list.removeAll( set ) );
        assertTrue( list.isEmpty() );
        assertEquals( 0, list.size() );
        assertEquals( element_count, set.size() );
        for ( int i = 0; i < set.size(); i++ ) {
            assertTrue( set.contains( Integer.valueOf( i ) ) );
        }


        // Reset the list
        list = new TIntLinkedList( 20 );
        for ( int i = 0; i < element_count; i++ ) {
            list.add( i );
        }

        set.remove( 0 );
        set.remove( 5 );
        set.remove( 10 );
        set.remove( 15 );
        assertTrue( list.removeAll( set ) );
        int expected = 4;
        assertEquals( "expected: " + expected + ", was: " + list.size() + ", list: " + list ,
                expected, list.size() );
        for ( int i = 0; i < list.size(); i++ ) {
            expected = i * 5;
            assertEquals( "expected: " + expected + ", was: " + list.get( i ) + ", list: " + list,
                expected , list.get( i ) );
        }
    }
View Full Code Here

        SortedSet<Integer> set = new TreeSet<Integer>();
        for ( int i = 0; i < element_count; i++ ) {
            set.add( Integer.valueOf( i ) );
        }

        TIntList list = new TIntArrayList( 20 );
        for ( int i = 0; i < element_count; i++ ) {
            list.add( i );
        }

        assertEquals( element_count, set.size() );
        assertEquals( element_count, list.size() );

        assertTrue( list.removeAll( set ) );
        assertTrue( list.isEmpty() );
        assertEquals( 0, list.size() );
        assertEquals( element_count, set.size() );
        for ( int i = 0; i < set.size(); i++ ) {
            assertTrue( set.contains( Integer.valueOf( i ) ) );
        }


        // Reset the list
        list = new TIntArrayList( 20 );
        for ( int i = 0; i < element_count; i++ ) {
            list.add( i );
        }

        set.remove( 0 );
        set.remove( 5 );
        set.remove( 10 );
        set.remove( 15 );
        assertTrue( list.removeAll( set ) );
        int expected = 4;
        assertEquals( "expected: " + expected + ", was: " + list.size() + ", list: " + list ,
                expected, list.size() );
        for ( int i = 0; i < list.size(); i++ ) {
            expected = i * 5;
            assertEquals( "expected: " + expected + ", was: " + list.get( i ) + ", list: " + list,
                expected , list.get( i ) );
        }
    }
View Full Code Here

    }


    public void testRemoveAllTCollection() {
        int element_count = 20;
        TIntList other = new TIntLinkedList();
        for ( int i = 0; i < element_count; i++ ) {
            other.add( i );
        }

        TIntList list = new TIntLinkedList( 20 );
        for ( int i = 0; i < element_count; i++ ) {
            list.add( i );
        }

        assertEquals( element_count, list.size() );
        assertEquals( element_count, other.size() );

        assertTrue( list.removeAll( list ) );
        assertEquals( 0, list.size() );
        assertTrue( list.isEmpty() );

        // Reset the list
        list = new TIntLinkedList( 20 );
        for ( int i = 0; i < element_count; i++ ) {
            list.add( i );
        }

        assertTrue( list.removeAll( other ) );
        assertEquals( 0, list.size() );
        assertTrue( list.isEmpty() );
        for ( int i = 0; i < list.size(); i++ ) {
            assertEquals( i , list.get( i ) );
        }

        // Reset the list
        list = new TIntLinkedList( 20 );
        for ( int i = 0; i < element_count; i++ ) {
            list.add( i );
        }

        other.remove( 0 );
        other.remove( 5 );
        other.remove( 10 );
        other.remove( 15 );
        assertTrue( list.removeAll( other ) );
        int expected = 4;
        assertEquals( "expected: " + expected + ", was: " + list.size() + ", list: " + list ,
                expected, list.size() );
        for ( int i = 0; i < list.size(); i++ ) {
            expected = i * 5;
            assertEquals( "expected: " + expected + ", was: " + list.get( i ) + ", list: " + list,
                expected , list.get( i ) );
        }
    }
View Full Code Here

    }


    public void testRemoveAllTCollection() {
        int element_count = 20;
        TIntList other = new TIntArrayList();
        for ( int i = 0; i < element_count; i++ ) {
            other.add( i );
        }

        TIntList list = new TIntArrayList( 20 );
        for ( int i = 0; i < element_count; i++ ) {
            list.add( i );
        }

        assertEquals( element_count, list.size() );
        assertEquals( element_count, other.size() );

        assertTrue( list.removeAll( list ) );
        assertEquals( 0, list.size() );
        assertTrue( list.isEmpty() );

        // Reset the list
        list = new TIntArrayList( 20 );
        for ( int i = 0; i < element_count; i++ ) {
            list.add( i );
        }

        assertTrue( list.removeAll( other ) );
        assertEquals( 0, list.size() );
        assertTrue( list.isEmpty() );
        for ( int i = 0; i < list.size(); i++ ) {
            assertEquals( i , list.get( i ) );
        }

        // Reset the list
        list = new TIntArrayList( 20 );
        for ( int i = 0; i < element_count; i++ ) {
            list.add( i );
        }

        other.remove( 0 );
        other.remove( 5 );
        other.remove( 10 );
        other.remove( 15 );
        assertTrue( list.removeAll( other ) );
        int expected = 4;
        assertEquals( "expected: " + expected + ", was: " + list.size() + ", list: " + list ,
                expected, list.size() );
        for ( int i = 0; i < list.size(); i++ ) {
            expected = i * 5;
            assertEquals( "expected: " + expected + ", was: " + list.get( i ) + ", list: " + list,
                expected , list.get( i ) );
        }
    }
View Full Code Here

        int ints[] = new int[element_count];
        for ( int i = 0; i < element_count; i++ ) {
            ints[i] = i;
        }

        TIntList list = new TIntLinkedList( 20 );
        for ( int i = 0; i < element_count; i++ ) {
            list.add( i );
        }

        assertEquals( element_count, list.size() );

        assertTrue( list.removeAll( ints ) );
        assertEquals( 0, list.size() );
        assertTrue( list.isEmpty() );

        // Reset the list
        list = new TIntLinkedList( 20 );
        for ( int i = 0; i < element_count; i++ ) {
            list.add( i );
        }

        ints = new int[( element_count - 4 )] ;
        for ( int i = 0, j = 0; i < ints.length; i++, j++ ) {
            if ( i % 4 == 0 ) {
                j++;
            }
            ints[i] = j;
        }

        assertTrue( list.removeAll( ints ) );
        int expected = 4;
        assertEquals( expected, list.size() );
        for ( int i = 0; i < list.size(); i++ ) {
            expected = i * 5;
            assertEquals( "expected: " + expected + ", was: " + list.get( i ) + ", list: " + list,
                expected , list.get( i ) );
        }
    }
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.