Package de.esoco.j2me.util

Source Code of de.esoco.j2me.util.IntArrayTest

//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// J2ME-Lib source file created in 2005 by Elmar Sonnenschein
// Copyright (c) 2005 Elmar Sonnenschein
//
// J2ME-Lib is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 2.1 of the License, or (at your option)
// any later version.
//
// J2ME-Lib 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 Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with J2ME-Lib; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA or use the contact
// information from the GNU website http://www.gnu.org
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
package de.esoco.j2me.util;

import j2meunit.framework.Test;
import j2meunit.framework.TestCase;
import j2meunit.framework.TestMethod;
import j2meunit.framework.TestSuite;


/********************************************************************
* Test suite for the IntArray class.
*
* @author eso
*/
public class IntArrayTest extends TestCase
{
  //~ Instance fields --------------------------------------------------------

  IntArray aTestArray;

  //~ Constructors -----------------------------------------------------------

  /***************************************
   * Default constructor.
   */
  public IntArrayTest()
  {
  }

  /***************************************
   * TestOne constructor for a particular method.
   *
   * @see TestCase#TestCase(String, TestMethod)
   */
  public IntArrayTest(String sTestName, TestMethod rTestMethod)
  {
    super(sTestName, rTestMethod);
  }

  //~ Methods ----------------------------------------------------------------

  /***************************************
   * Set up data for all tests.
   */
  public void setUp()
  {
    aTestArray = new IntArray(10);

    for (int i = 0; i < 10; i++)
    {
      aTestArray.push(i);
    }
  }

  /***************************************
   * To create the test suite.
   *
   * @see TestCase#suite()
   */
  public Test suite()
  {
    TestSuite aSuite = new TestSuite();

    aSuite.addTest(new IntArrayTest("testArrayAccess", new TestMethod()
      {
        public void run(TestCase tc)
        {
          ((IntArrayTest) tc).testArrayAccess();
        }
      }));

    return aSuite;
  }

  /***************************************
   * Test array access.
   */
  public void testArrayAccess()
  {
    assertTrue("Invalid get: " + aTestArray.get(5) + " - expected 5",
           aTestArray.get(5) == 5);

    aTestArray.push(12345);

    int nPop = aTestArray.pop();
    assertTrue("Invalid pop: " + nPop + " - expected 12345", nPop == 12345);
    assertTrue("Invalid size1: " + aTestArray.getSize() + " - expected 10",
           aTestArray.getSize() == 10);

    aTestArray.set(4567, 9);
    assertTrue("Invalid set: " + aTestArray.get(9) + " - expected 4567",
           aTestArray.get(9) == 4567);
    aTestArray.set(9, 9);

    aTestArray.insert(123, 2);
    assertTrue("Invalid insert: " + aTestArray.get(2) + " - expected 123",
           aTestArray.get(2) == 123);
    assertTrue("Invalid insert: " + aTestArray.get(3) + " - expected 2",
           aTestArray.get(3) == 2);
    assertTrue("Invalid size2: " + aTestArray.getSize() + " - expected 11",
           aTestArray.getSize() == 11);
    assertTrue("Invalid capacity: " + aTestArray.getCapacity() +
           " - expected > 10", aTestArray.getCapacity() > 10);

    aTestArray.remove(2);
    assertTrue("Invalid remove: " + aTestArray.get(2) + " - expected 2",
           aTestArray.get(2) == 2);
    assertTrue("Invalid size3: " + aTestArray.getSize() + " - expected 10",
           aTestArray.getSize() == 10);

    aTestArray.insertAscending(5, 0);
    assertTrue("Invalid insertAscending: " + aTestArray.get(6) +
           " - expected 5", aTestArray.get(6) == 5);
    assertTrue("Invalid size4: " + aTestArray.getSize() + " - expected 11",
           aTestArray.getSize() == 11);

    aTestArray.insertAscending(1, 8);
    assertTrue("Invalid insertAscending2: " + aTestArray.get(8) +
           " - expected 1", aTestArray.get(8) == 1);

    aTestArray.setSize(20);
    assertTrue("Invalid size5: " + aTestArray.getSize() + " - expected 20",
           aTestArray.getSize() == 20);
    assertTrue("Invalid get(19): " + aTestArray.get(19) + " - expected 0",
           aTestArray.get(19) == 0);
  }
}
TOP

Related Classes of de.esoco.j2me.util.IntArrayTest

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.