// ShortSequenceTest2.java
// Tests the insert and append methods of class ShortSequence.
// Tests insert for in-range indices only
public class ShortSequenceTest2 {
public static void main(String[] args)
{
ShortSequence sequence1 = new ShortSequence(2);
System.out.println("sequence1 is initially empty with capacity 2.");
list(sequence1, "sequence1", 2, 0);
System.out.println("We will now append 4 elements, "
+ "then insert 2 elements.");
System.out.println();
testAppend(sequence1, "sequence1", (short) 100, 2, 1);
testAppend(sequence1, "sequence1", (short) 110, 2, 2);
testAppend(sequence1, "sequence1", (short) 120, 12, 3);
testAppend(sequence1, "sequence1", (short) 130, 12, 4);
testInsert(sequence1, "sequence1", (short) 140, 3, false, 12, 5);
testInsert(sequence1, "sequence1", (short) 150, 0, false, 12, 6);
} // method main
public static void list(ShortSequence sequence,
String name,
int capacityShouldBe,
int numberOfElementsShouldBe)
{
System.out.println(name + ": capacity " + sequence.getCapacity() +
" should be " + capacityShouldBe +
", number of elements " +
sequence.getLengthFilled() +
" should be " + numberOfElementsShouldBe);
System.out.println("Following are the contents of " +
name + ":");
System.out.println(sequence);
System.out.println("Finished displaying contents of " +
name + ".");
ConsoleInput.pause();
} // method list
public static void testAppend(ShortSequence sequence,
String name,
short dataToBeAppended,
int newCapacityShouldBe,
int newNumberOfElementsShouldBe)
{
System.out.println(name + ".append(" + dataToBeAppended +
")");
sequence.append(dataToBeAppended);
list(sequence, name, newCapacityShouldBe, newNumberOfElementsShouldBe);
} // method testAppend
public static void testInsert(ShortSequence sequence,
String name,
short dataToBeInserted,
int position,
boolean shouldBeOutOfRange,
int newCapacityShouldBe,
int newNumberOfElementsShouldBe)
{
System.out.println(name + ".insert(" + position +
", " + dataToBeInserted + ")");
if ( shouldBeOutOfRange )
System.out.println("SHOULD be out of range.");
else
System.out.println("Should NOT be out of range.");
sequence.insert(position, dataToBeInserted);
list(sequence, name, newCapacityShouldBe, newNumberOfElementsShouldBe);
} // method testInsert
} // class ShortSequenceTest2