Package etherstrategy.simulation

Examples of etherstrategy.simulation.TestUElement


        TestC cElement = new TestC();
        TestC cElement2 = new TestC();

        UniverseElement[] tooSmallUEArray =
            {
             new TestUElement(), new TestUElement(), new TestUElement(),
            };
        UniverseElement[] bigEnoughUEArray =
            { new TestUElement(), new TestUElement(), new TestUElement(),
              new TestUElement(), new TestUElement(), new TestUElement(),
              new TestUElement(), new TestUElement(),
            };
        UniverseElement[] returnedUEArray;

        returnedUEArray = testElement.toArray(tooSmallUEArray);
       
View Full Code Here


        testElement.add( new TestC() );
        testElement.add( new TestDerivedFromC() );
        testElement.add( new TestA() );
        testElement.add( new TestB() );
        testElement.add( new TestA() );
        testElement.add( new TestUElement() );
        testElement.add( new TestUElementComposite() );

        testIter = testElement.iterator();

        try
        {
            testIter.remove();
            fail("Attempting to call remove() on an iterator before next() has been called should throw an exception, but did not.");
        }
        catch ( IllegalStateException e )
        {
        }
        catch ( Exception e )
        {
            fail("Attempting to call remove() on an iterator before next() has been called should only throw an IllegalStateException, but a(n) " + e.getClass().getName() + " was thrown.");
        }

        assertTrue(
                "An new iterator for a UniverseElementComposite that has child elements should recognize that there is a next element when next has never been called for the iterator.",
                testIter.hasNext() );

        LinkedList<UniverseElement> testList = new LinkedList<UniverseElement>();

        while ( testIter.hasNext() )
        {
            testList.add( (UniverseElement) testIter.next() );
        }

        assertEquals(
                "After iterating through a UniverseElementComposite and adding each individual element returned from next() to an external list, the list and the UniverseElementComposite should have the same size",
                testElement.size(), testList.size() );

        assertTrue(
                "After iterating through a UniverseElementComposite and adding each individual element returned from next() to an external list, the UniverseElementComposite should contain all the elements in the external list.",
                testElement.containsAll( testList ) );

        assertFalse(
                "After iterating through the last child element of a UniverseElementComposite, an iterator should recognize that there is not next element.",
                testIter.hasNext() );

        try
        {
            testIter.next();
            fail("Attempting to iterate to the next element when an iterator has already iterated past the last element in a UniverseElementComposite should throw an exception, but did not.");
        }
        catch ( NoSuchElementException e )
        {
        }
        catch ( Exception e )
        {
            fail("Attempting to iterate to the next element when an iterator has already iterated past the last element in a UniverseElementComposite should only throw a NoSuchElementException, but a(n) " + e.getClass().getName() + " was thrown.");
        }

        int savedSize = testElement.size();
        UniverseElement savedItem = null;

        testIter = testElement.iterator();

        savedItem = testIter.next();

        assertTrue(
                "Before a call to remove an item through an iterator, the item being removed should report itself as being contained.",
                savedItem.isContained() );

        testIter.remove();
       
        assertFalse(
                "After a call to remove an item through an iterator, the item being removed should not report itself as being contained.",
                savedItem.isContained() );

        assertTrue(
                "An item saved from a call to an iterator's next() method should exist in a list of all items already saved from the related UniverseElementComposite, even after a call has been made through the iterator to remove that item.",
                testList.contains(savedItem) );

        assertFalse(
                "An item saved from a call to an iterator's next() method should not exist in the related UniverseElementComposite after a call has been made through the iterator to remove that item.",
                testElement.contains( savedItem ) );

        assertEquals(
                "After using an iterator to remove an item from a UniverseElementComposite, the size of the UniverseElementComposite should be one less than it was previously.",
                savedSize - 1, testElement.size() );

        testList.remove(savedItem);

        assertTrue(
                "After removing an item from UniverseElementComposite through a call to an iterator, and then removing that same item from a list of elements saved from that UniverseElementComposite before the original remove operation, the UniverseElementComposite should contain all the elements in the list.",
                testElement.containsAll(testList) );

        savedSize = testElement.size();

        try
        {
            testIter.remove();
            fail("Attempting to call remove for an iterator twice in a row, with no intervening call to that iterator to advance to the next element, should throw an exception, but did not.");
        }
        catch ( IllegalStateException e )
        {
        }
        catch ( Exception e )
        {
            fail("Attempting to call remove for an iterator twice in a row, with no intervening call to that iterator to advance to the next element, should only throw an IllegalStateException, but a(n) " + e.getClass().getName() + " was thrown.");
        }

        assertEquals(
                "After attempting (and failing) to call remove() on an iterator twice in a row with no intervening call to next(), the related UniverseElementComposite should not have changed size.",
                testElement.size(), savedSize );

        assertTrue(
                "After attempting (and failing) to call remove() on an iterator twice in a row with no intervening call to next(), the related UniverseElementComposite should contain all the elements it did before the call.",
                testElement.containsAll( testList ) );

        assertTrue(
                "After calling remove() (twice) on an iterator, the iterator should still recognize that there is another element in a UniverseElementComposite that does, in fact, have additional child elements.",
                testIter.hasNext() );

        savedItem = testIter.next();

        assertTrue(
                "After calling remove() (twice) on an iterator, calling next() should still return the next element in the UniverseElementComposite.",
                testElement.contains( savedItem ) );

        testIter.remove();

        assertFalse(
                "After calling remove() twice in a row on an iterator and handling the exception, then calling next, removing an element through the iterator should still work as expected and the UniverseElementComposite should not contain the removed element.",
                testElement.contains( savedItem ) );

        int numElements = 0;
       
        while ( testIter.hasNext() )
        {
            testIter.next();
            ++numElements;
        }

        assertEquals(
                "After calling remove any number of times on the logical beginning of a UniverseElementComposite, the number of elements you can get back from a UniverseElementComposite through an iterator using the next() method should still be the same as the size of the UniverseElementComposite.",
                testElement.size(), numElements );

        /* These tests are probably unnecessary. */
        testElement.clear();
        testElement.add( new TestUElement() );

        testIter = testElement.iterator();

        assertNotNull(
                "The item returned from a call to an iterator's next() method, even when it returns the last element in a UniverseElementComposite, should not be null.",
View Full Code Here

        TestB element5 = new TestB();
        TestC element6 = new TestC();
        TestC element7 = new TestC();
        TestDerivedFromC element8 = new TestDerivedFromC();
        TestDerivedFromC element9 = new TestDerivedFromC();
        TestUElement element10 = new TestUElement();
        TestUElementComposite element11 = new TestUElementComposite();

        element1.add( element2 );
        element1.add( element7 );
        element1.add( element11 );
View Full Code Here

     * @throws java.lang.Exception
     */
    @Before
    public void setUp() throws Exception
    {
        testElement = new TestUElement();
        assertNotNull( "A newly constructed test element should not be null",
                testElement );
    }
View Full Code Here

     * @throws Exception
     */
    @Test
    public void compareBlankUniverseElements() throws Exception
    {
        TestUElement testElement2 = new TestUElement();

        assertTrue(
                "Two UniverseElements created with a default constructor should be similar, but are not",
                testElement.similar( testElement2 ) );
    }
View Full Code Here

     * side effects.
     */
    @Test
    public void addTestElementsToUniverseElement() throws Exception
    {
        TestUElement testElementToAdd = new TestUElement();
        TestUElement emptyTestElement = new TestUElement();

        assertFalse(
                "Prior to adding a UniverseElement to another UniverseElement, the potential child UniverseElement should not report itself as being contained within another UniverseElement",
                testElementToAdd.isContained() );

View Full Code Here

     * @throws Exception
     */
    @Test
    public void checkIfElementInUniverseElement() throws Exception
    {
       TestUElement element1 = new TestUElement();
       TestUElement element2 = new TestUElement();
       TestUElement element3 = new TestUElement();
       TestUElement elementNotAdded = new TestUElement();
      
       testElement.add(element1);
       testElement.add( element2 );
       testElement.add(element3);
      
View Full Code Here

     * @throws Exception
     */
    @Test
    public void similarityForUniverseElementWithVariousSetsOfMemberData() throws Exception
    {
        TestUElement elementToCompare = new TestUElement();

        testElement.setCenter( 1, 1, 1 );
       
        assertFalse(
                "A newly created UniverseElement with no members should not be similar to an empty UniverseElement where the center has been changed so that it is not (0, 0, 0).",
                testElement.similar( elementToCompare ) );

        elementToCompare.setCenter( 2, 2, 2 );

        assertFalse(
                "Two empty UniverseElements that have had their centers set to different values should not be similar.",
                testElement.similar( elementToCompare ) );

        elementToCompare.setCenter( 1, 1, 1 );

        assertTrue(
                "Two empty UniverseElements that have had their centers set to the same value, and have all other members the same, should be similar.",
                testElement.similar( elementToCompare ) );
    }
View Full Code Here

     * @throws Exception
     */
    @Test
    public void removeFromUniverseElement() throws Exception
    {
        TestUElement element1 = new TestUElement();
        TestUElement element2 = new TestUElement();
        TestUElement element3 = new TestUElement();
       
        testElement.add(element1);
        testElement.add(element2);
       
        assertFalse(
View Full Code Here

        LinkedList<Object> testCollection =
            new LinkedList<Object>();
        LinkedList<Object> emptyCollection =
            new LinkedList<Object>();

        TestUElement element1 = new TestUElement();
        TestUElement element2 = new TestUElement();
        TestUElement element3 = new TestUElement();

        testCollection.add(element1);
        testCollection.add(element2);
       
        assertTrue(
View Full Code Here

TOP

Related Classes of etherstrategy.simulation.TestUElement

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.