Package etherstrategy.simulation

Source Code of etherstrategy.simulation.UniverseTest

/**
* EtherStrategy: A simulation of space and interstellar civilization.
*
* Copyright * (C) 2007 Wayne Witzke
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY, without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* (COPYING.txt) along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* To contact the author of EtherStrategy, send e-mail to wwitzke at
* users.sourceforge.net
*/
package etherstrategy.simulation;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.Ignore;
import static org.junit.Assert.*;
import etherstrategy.simulation.Universe;
import etherstrategy.simulation.TestUElement;


/**
* @author Wayne Witzke
*
*/
public class UniverseTest
{
    Universe testUniverse;

    /**
     * @throws java.lang.Exception
     */
    @BeforeClass
    public static void setUpBeforeClass() throws Exception
    {
    }

    /**
     * @throws java.lang.Exception
     */
    @AfterClass
    public static void tearDownAfterClass() throws Exception
    {
    }

    /**
     * It's getting to be a drag creating a new universe for every single
     * method, so we'll do it once here. I suppose, in theory, that this should
     * take the place of the constructor test for Universe.
     *
     * @throws java.lang.Exception
     */
    @Before
    public void setUp() throws Exception
    {
        testUniverse = new Universe();
        assertNotNull( "A newly constructed Universe should not be null",
                testUniverse );
    }

    /**
     * Let's manually nullify that previous testUniverse, just to make sure we
     * start with a clean slate next time.
     *
     * @throws java.lang.Exception
     */
    @After
    public void tearDown() throws Exception
    {
        testUniverse = null;
    }

    /**
     * constructUniverse is just a simple, first test to insure that we can
     * construct a blank Universe without an exception occurring. Other tests
     * depend on this test actually executing properly (otherwise the Universe
     * constructor is broken).
     *
     * @throws Exception
     */
    @Ignore( "Irrelevant due to setUp()" )
    @Test
    public void constructUniverse() throws Exception
    {
        Universe testUniverse = new Universe();
        assertNotNull( "A newly constructed Universe should not be null",
                testUniverse );
        testUniverse = null;
    }

    /**
     * Okay, so it looks like the second test we want to perform is constructing
     * the semantic validator for the Universe. I wouldn't be so concerned about
     * validation of the simulation data, if it weren't for the fact that we're
     * storing the data in XML (i.e. something which is human readable and,
     * therefore, probably going to be changed by humans at some point and,
     * therefore, probably going to result in a semantically broken Universe at
     * some point).
     *
     * The SemanticValidator should make sure that the bounds set on the
     * Universe at the time of creation are not broken by information contained
     * in the Universe itself, and that the information in the Universe actually
     * has some measure of sanity applied to it (i.e., two planets cannot be
     * overlapping in space. . .). However, this test doesn't bother with all
     * that. It just insures that we can construct a validator.
     *
     * @throws Exception
     */
    @Test
    public void constructUniverseSemanticValidator() throws Exception
    {
        Universe.SemanticValidator testValidator = testUniverse.new SemanticValidator();
    }

    /**
     * In order to facilitate further testing, we need to implement a deep
     * comparison method for Universes. It's going to be horribly inefficient,
     * probably, but since the Universes we'll be testing with here should be
     * relatively small, usually, and since this comparison operation will
     * probably have very limited (if any) actual usage in the application
     * itself, this shouldn't be a problem. This test will insure that the
     * equality method functions properly and returns correct results for empty
     * Universes.
     *
     * @throws Exception
     */
    @Test
    public void compareBlankUniverses() throws Exception
    {
        Universe testUniverse2 = new Universe();

        assertTrue(
                "Two universes created with a default constructor should be identical, but are not",
                testUniverse.similar( testUniverse2 ) );
    }

    /**
     * Here we just want to make sure that we can get an iterator back from a
     * Universe. If this doesn't work, then the constructor for the iterator, or
     * the iterator accessor function, are broken. (I don't think that we want a
     * consumer to attempt to construct an iterator directly. . . They can clone
     * iterators, or get the beginning or end of the Universe, or whatever, but
     * direct construction of the iterator should, probably, be a no-no.)
     *
     * @throws Exception
     */
    @Test
    public void constructUniverseIterator() throws Exception
    {
        Universe.Iterator testIterator = testUniverse.iterator();
    }

    /**
     * We need to be able to get the first and last items out of the Universe,
     * to get the number of items in the Universe, and to get elements out of
     * the Universe by index value. The indexing method should throw an
     * exception if the index is out of range, and the first and last items
     * access should throw an exception if there is no first or last element in
     * the Universe. We can also check isEmpty() here, since that is kind of in
     * the same category as the other tests here.
     */
    @Test
    public void accessElementsInEmptyUniverse() throws Exception
    {
        assertEquals(
                "A newly created Universe should have a zero count of elements.",
                testUniverse.size(), 0 );
        assertTrue( "A newly created Universe should be empty.",
                testUniverse.isEmpty() );
    }

    /**
     * Next, we get to test adding items to a Universe. We'll be using
     * TestUElement here for these basic tests.
     *
     * While we're here, we might as well insure that the other Universe testing
     * methods are functioning properly.
     */
    @Test
    public void addTestElementsToUniverse() throws Exception
    {
        Universe testUniverse2 = new Universe();
        TestUElement testElement = new TestUElement();

        testUniverse.add( testElement );

        assertFalse(
                "A Universe that has had an element added should not be equal to a Universe that has no nodes.",
                testUniverse.equals( testUniverse2 ) );

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

        assertEquals(
                "A Universe that has exactly one element should report a size of one.",
                testUniverse.size(), 1 );
    }

    /*
     * @Ignore("Not yet implemented") @Test public void
     * constructUniverseFromFile() throws Exception { Universe testUniverse =
     * new Universe( "testUniverse.xml" ); }
     *
     * @Ignore("Not yet implemented") @Test public void
     * constructRandomUniverse() throws Exception { Universe testUniverse =
     * Universe.createRandom(); }
     */
TOP

Related Classes of etherstrategy.simulation.UniverseTest

TOP
Copyright © 2018 www.massapi.com. 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.