Package etherstrategy.simulation

Examples of etherstrategy.simulation.TestUElement


    @Test
    public void addUniverseElementsToUniverseElementComposite() throws Exception
    {
        TestUElementComposite testElementToAdd = new TestUElementComposite();
        TestUElementComposite emptyTestElement = new TestUElementComposite();
        TestUElement testElementToAdd2 = new TestUElement();

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

        assertFalse(
                "Prior to adding a UniverseElement to a UniverseElementComposite, the UniverseElement should report itself as not being contained.",
                testElementToAdd2.isContained() );

        assertTrue(
                "Adding a UniverseElementComposite to an empty UniverseElementComposite should return true",
                testElement.add( testElementToAdd ) );

        assertFalse(
                "A UniverseElementComposite that has had an element added should not be similar to a UniverseElementComposite that has no nodes.",
                testElement.similar( emptyTestElement ) );

        assertFalse(
                "A UniverseElementComposite that has an element should not be marked as empty.",
                testElement.isEmpty() );

        assertEquals(
                "A UniverseElementComposite that has exactly one element should report a size of one.",
                testElement.size(), 1 );

        assertFalse(
                "Trying to add a UniverseElementComposite twice to a UniverseElementComposite should return false",
                testElement.add( testElementToAdd ) );

        assertEquals(
                "After trying to add a UniverseElementComposite twice to a UniverseElementComposite should leave the original UniverseElementComposite (the parent) with a size of 1.",
                testElement.size(), 1 );

        assertFalse(
                "Trying to add a UniverseElementComposite to two different UniverseElementComposites should return false.",
                emptyTestElement.add( testElementToAdd ) );

        assertTrue(
                "After trying to add a UniverseElementComposite to two different UniverseElementComposites (the second being initially empty), the second UniverseElementComposite should still be empty.",
                emptyTestElement.isEmpty() );

        assertTrue(
                "We should be able to add an element to a different UniverseElementComposite after having already added a different UniverseElement to a different UniverseElementComposite.",
                emptyTestElement.add( testElementToAdd2 ) );

        assertFalse(
                "Having one UniverseElementComposite in another, then adding a different UniverseElement to a different UniverseElementComposite should leave the second parent UniverseElementComposite in a non-empty state.",
                emptyTestElement.isEmpty() );

        assertTrue(
                "Adding a second unique element to a UniverseElementComposite should return true.",
                testElement.add( emptyTestElement ) );

        assertEquals(
                "Adding a second element to a UniverseElementComposite should leave the UniverseElementComposite with a size of 2.",
                testElement.size(), 2 );
       
        assertTrue(
                "Having added one UniverseElementComposite to another, the added element should be reported itself as being contained by another UniverseElementComposite class.",
                testElementToAdd.isContained() );

        assertTrue(
                "Having added a UniverseElement to a UniverseElementComposite, the UniverseElement should report itself as being contained.",
                testElementToAdd2.isContained() );
    }
View Full Code Here


        assertFalse(
                "After failing to add an non-contained UniverseElementComposite to itself, the UniverseElementComposite should still report itself as not being contained.",
                testElement.isContained() );

        TestUElement element1 = new TestUElement();
        testElement.add( element1 );

        try
        {
            testElement.add(testElement);
View Full Code Here

        assertTrue(
                "After failing to add a null reference to an empty UniverseElementComposite, the UniverseElementComposite should still be empty.",
                testElement.isEmpty() );

        TestUElement element1 = new TestUElement();
        testElement.add( element1 );

        try
        {
            testElement.add(null);
View Full Code Here

     * @throws Exception
     */
    @Test
    public void checkIfUniverseElementInUniverseElementComposite() throws Exception
    {
       TestUElement element1 = new TestUElement();
       TestUElementComposite element2 = new TestUElementComposite();
       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 removeFromUniverseElementComposite() throws Exception
    {
        TestUElement element1 = new TestUElement();
        TestUElementComposite element2 = new TestUElementComposite();
        TestUElement element3 = new TestUElement();
       
        testElement.add(element1);
        testElement.add(element2);
       
        assertFalse(
View Full Code Here

        assertTrue(
                "After failing to remove a null reference from an empty UniverseElementComposite, the UniverseElementComposite should still be empty.",
                testElement.isEmpty() );

        TestUElement element1 = new TestUElement();
        testElement.add( element1 );

        try
        {
            testElement.remove(null);
View Full Code Here

        assertTrue(
                "After failing to remove a non-UniverseElement object from an empty UniverseElementComposite, the UniverseElementComposite should still be empty.",
                testElement.isEmpty() );

        TestUElement element1 = new TestUElement();
        testElement.add( element1 );

        try
        {
            testElement.remove( new Integer(1) );
View Full Code Here

     * @throws Exception
     */
    @Test
    public void clearingUniverseElementComposite() throws Exception
    {
        TestUElement element1 = new TestUElement();
        TestUElementComposite element2 = new TestUElementComposite();
        TestUElement element3 = new TestUElement();

        testElement.clear();
        assertTrue(
                "Clearing a newly created UniverseElementComposite should still leave it in the empty state.",
                testElement.isEmpty() );
       
        testElement.add(element1);
        testElement.add(element2);
        testElement.add(element3);

        testElement.clear();
       
        assertEquals(
                "Clearing a UniverseElementComposite should leave it with a size of zero.",
                testElement.size(), 0 );
       
        assertFalse(
                "Having cleared the UniverseElementComposite, it should not report any of the elements that it previously contained as being contained currently.",
                testElement.contains( element1 )
                || testElement.contains( element2 )
                || testElement.contains( element3 ) );
       
        assertFalse(
                "Elements that were contained in a UniverseElementComposite prior to a call to clear() should not reported themselves as being contained after the call to clear().",
                element1.isContained()
                || element2.isContained()
                || element3.isContained() );
       
        assertTrue(
                "After clearing a UniverseElementComposite, the UniverseElementComposite should report itself as being empty, even if it had elements previously.",
                testElement.isEmpty() );
       
View Full Code Here

     * @throws Exception
     */
    @Test
    public void addingSelfToUniverseElementCompositeThroughAddingACollection() throws Exception
    {
        TestUElement element1 = new TestUElement();

        testElement.add(element1);

        LinkedList<UniverseElement> testCollection =
            new LinkedList<UniverseElement>();
        testCollection.add( new TestUElement() );
        testCollection.add(testElement);
        testCollection.add( new TestUElementComposite() );

        try
        {
            testElement.addAll( testCollection );
            fail("Adding a collection with a reference to the UniverseElementComposite it is being added to, and other valid elements, should throw an IllegalArgumentException due to the self reference, but did not.");
        }
        catch ( IllegalArgumentException e )
        {
        }
        catch ( Exception e )
        {
            fail("Adding a collection with a reference to the UniverseElementComposite it is being added to should throw only an IllegalArgumentException, but a(n) " + e.getClass().getName() + " exception was thrown.");
        }
       
        assertTrue(
                "After failing to add a collection containing a reference to the UniverseElementComposite to which it was being added, the UniverseElementComposite should not have changed.",
                testElement.size() == 1
                && testElement.contains( element1 ) );

        testCollection.clear();
        testCollection.add( new TestUElementComposite() );
        testCollection.add( new TestUElement() );
        testCollection.add( testElement );

        try
        {
            testElement.addAll( testCollection );
            fail("Adding a collection with valid elements and a reference to the UniverseElementComposite to which it is being added as the last element should throw an IllegalArgumentException due to the self reference, but did not.");
        }
        catch ( IllegalArgumentException e )
        {
        }
        catch ( Exception e )
        {
            fail("Adding a collection with a reference to the UniverseElementComposite it is being added to as the last element in the collection should throw only an IllegalArgumentException, but a(n) " + e.getClass().getName() + " exception was thrown.");
        }

        assertTrue(
                "After failing to add a collection containing a reference to the UniverseElementComposite to which it was being added, the UniverseElementComposite should not have changed.",
                testElement.size() == 1
                && testElement.contains(element1) );

        testCollection.clear();
        testCollection.add( testElement );
        testCollection.add( new TestUElement() );
        testCollection.add( new TestUElementComposite() );

        try
        {
            testElement.addAll( testCollection );
View Full Code Here

     * @throws Exception
     */
    @Test
    public void addingANullCollectionToAUniverseElementComposite() throws Exception
    {
        TestUElement element1 = new TestUElement();

        testElement.add(element1);

        try
        {
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.