Package etherstrategy.simulation

Examples of etherstrategy.simulation.TestUElementComposite


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


     * @throws Exception
     */
    @Test
    public void compareBlankUniverseElementCompositess() throws Exception
    {
        TestUElementComposite testElement2 = new TestUElementComposite();

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

     * testing methods are functioning properly after the add.
     */
    @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 ) );

View Full Code Here

     */
    @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);
View Full Code Here

     * @throws Exception
     */
    @Test
    public void similarityOnDifferentOrderings() throws Exception
    {
        TestUElementComposite testElement2 = new TestUElementComposite();
        TestA element1 = new TestA();
        TestB element2 = new TestB();
        TestA element3 = new TestA();
        TestB element4 = new TestB();
       
        testElement.add( element1 );
        testElement.add( element2 );
       
        testElement2.add( element4 );
        testElement2.add( element3 );

       
        assertTrue(
                "Two UniverseElementComposites should be similar if they contain similar child elements, no matter the order in which those elements were added.",
                testElement.similar( testElement2 ) );
View Full Code Here

     * @throws Exception
     */
    @Test
    public void similarityForUniverseElementCompositeWithVariousSetsOfMemberData() throws Exception
    {
        TestUElementComposite elementToCompare = new TestUElementComposite();

        testElement.setCenter( 1, 1, 1 );
       
        assertFalse(
                "A newly created UniverseElementComposite with default member data should not be similar to an empty UniverseElementComposite 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 UniverseElementComposites that have had their centers set to different values should not be similar.",
                testElement.similar( elementToCompare ) );

        elementToCompare.setCenter( 1, 1, 1 );

        assertTrue(
                "Two empty UniverseElementComposites 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

    {
        testElement.add( new TestA() );
        testElement.add( new TestB() );
        testElement.add( new TestA() );

        TestUElementComposite nonsimilarElement = new TestUElementComposite();
        nonsimilarElement.add( new TestB() );
        nonsimilarElement.add( new TestA() );
        nonsimilarElement.add( new TestB() );

        assertFalse(
                "Two UniverseElementComposites that are not, in fact, similar because they contain different numbers of different kinds of elements should not be said to be similar when the similar() method is applied to them.",
                testElement.similar(nonsimilarElement) );
    }
View Full Code Here

     */
    @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(
                "Removing an non-existent child from a UniverseElementComposite should return false.",
                testElement.remove( element3 ) );
       
        assertTrue(
                "Removing a child element from a UniverseElementComposite should return true.",
                testElement.remove( element1 ) );
       
        assertEquals(
                "Having removed a child element from a UniverseElementComposite containing two children, the UniverseElementComposite should now have a count of 1.",
                testElement.size(), 1 );
       
        assertFalse(
                "Having removed a child element from a UniverseElementComposite, that UniverseElementComposite should not report containing that child.",
                testElement.contains(element1) );
       
        assertFalse(
                "A UniverseElement that has been removed from a UniverseElementComposite should not report itself as being contained.",
                element1.isContained() );
       
        testElement.remove( element2 );
       
        assertTrue(
                "Having removed all elements from a UniverseElementComposite, the UniverseElementComposite should now report that it is empty.",
                testElement.isEmpty() );

        assertFalse(
                "A UniverseElementComposite that has been removed from a UniverseElementComposite should not report itself as being contained.",
                element2.isContained() );
       
        assertTrue(
                "Having removed a child from a UniverseElementComposite, it should be possible to add that child back to the UniverseElementComposite.",
                testElement.add(element1) );
       
View Full Code Here

     */
    @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

    public void addingACollectionOfUniverseElementsToAUniverseElementComposite() throws Exception
    {
        LinkedList<UniverseElement> testCollection =
            new LinkedList<UniverseElement>();

        TestUElementComposite testElement2 = new TestUElementComposite();

        assertFalse(
                "Adding an empty collection to an empty UniverseElementComposite should return false, since the UniverseElementComposite was not modified.",
                testElement.addAll( testCollection ) );

        assertTrue(
                "Having added an empty collection to an empty UniverseElementComposite, the UniverseElementComposite should report itself as being empty.",
                testElement.isEmpty() );

        testCollection.add( new TestA() );
        testCollection.add( new TestB() );
        testCollection.add( new TestA() );
       
        assertTrue(
                "Adding a non-empty collection of UniverseElements to an empty UniverseElementComposite should return true.",
                testElement.addAll( testCollection ) );

        assertFalse(
                "Having added a non-empty collection of UniverseElements to an empty UniverseElementComposite, the UniverseElementComposite should not longer report itself as being empty.",
                testElement.isEmpty() );

        assertEquals(
                "Having added a non-empty collection to an empty UniverseElementComposite, the collection and the UniverseElementComposite should have the same size.",
                testElement.size(), testCollection.size() );

        assertTrue(
                "UniverseElements added through addAll should report themselves as being contained.",
                testCollection.get(0).isContained()
                && testCollection.get(1).isContained()
                && testCollection.get( 2 ).isContained() );

        /* Saved for a later test. */
        int size = testElement.size();

        assertFalse(
                "Trying to add a non-empty collection of UniverseElements to a UniverseElementComposite twice should return false the second time.",
                testElement.addAll( testCollection ) );

        assertEquals(
                "Having attempted to add a non-empty collection to an empty UniverseElementComposite twice, the UniverseElementComposite size should not have changed after the second add attempt.",
                testElement.size(), size );

        testCollection.clear();
        testCollection.add( new TestA() );
        testCollection.add( new TestA() );
       
        testElement2.addAll( testCollection );

        assertFalse(
                "Two UniverseElementComposites should not be similar if they were populated with collections of UniverseElements that were, themselves, not similar.",
                testElement.similar( testElement2 ) );
       
        testElement2.add( new TestB() );
       
        assertTrue(
                "Two UniverseElementComposites should be similar if they have similar elements, regardless of mixing add and addAll statements in building the UniverseElementComposites.",
                testElement.similar( testElement2 ) );

        assertFalse(
                "Attempting to add to a UniverseElementComposite a collection of UniverseElements that have already been added elsewhere should return false.",
                testElement.addAll( testCollection ) );
       
        assertFalse(
                "Attempting to add to a UniverseElementComposite a collection of UniverseElements that have already been added to a different UniverseElementComposite should cause the potential container UniverseElementComposite to report that it does not contain those elements.",
                testElement.contains( testCollection.get( 0 ) )
                || testElement.contains( testCollection.get( 1 ) ) );

        testCollection.add( new TestB() );

        assertTrue(
                "Adding a collection of UniverseElements to a UniverseElementComposite, where the container UniverseElementComposite already contains some, but not all, of the potential child UniverseElements in the collection, should return true.",
                testElement2.addAll( testCollection ) );
       
        assertTrue(
                "Having added a collection of UniverseElements to a UniverseElementComposite, where the container UniverseElementComposite already contained some, but not all, of the potential child UniverseElements in the collection, the container UniverseElementComposite should report containing all the elements in the added collection.",
                testElement2.contains( testCollection.get( 0 ) )
                && testElement2.contains( testCollection.get( 1 ) )
                && testElement2.contains( testCollection.get( 2 ) ) );

        assertEquals(
                "After a complex series of adding collections of, and individual elements to a UniverseElementComposite, the reported size of the UniverseElementComposite should still be correct (in this case, it should be 4).",
                testElement2.size(), 4);
    }
View Full Code Here

TOP

Related Classes of etherstrategy.simulation.TestUElementComposite

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.