// ShortSequenceTest4.java
// Tests the insert method of class ShortSequence
// for in-range and out-of-range indices.
public class ShortSequenceTest4 {
public static void main(String[] args)
{
ShortSequence s1 = new ShortSequence(2);
ShortSequence s2 = new ShortSequence(2);
System.out.println("Testing an empty ShortSequence and a String:");
testEquals(s1, "Hello", false);
System.out.println("Testing two empty ShortSequence objects:");
testEquals(s1, s2, true);
ConsoleInput.pause();
System.out.println("Appending an element to one ShortSequence:");
s1.append((short) 3);
testEquals(s1, s2, false);
testEquals(s2, s1, false);
System.out.println("Appending an element to the empty ShortSequence:");
s2.append((short) 3);
testEquals(s1, s2, true);
ConsoleInput.pause();
System.out.println("Appending an element to one ShortSequence:");
s1.append((short) 4);
testEquals(s1, s2, false);
testEquals(s2, s1, false);
System.out.println("Appending an element to the shorter ShortSequence:");
s2.append((short) 4);
testEquals(s1, s2, true);
ConsoleInput.pause();
System.out.println("Appending an element to one ShortSequence:");
s1.append((short) 5);
testEquals(s1, s2, false);
testEquals(s2, s1, false);
System.out.println("Appending an element to the shorter ShortSequence:");
s2.append((short) 6);
testEquals(s1, s2, false);
testEquals(s2, s1, false);
} // method main
public static void testEquals(ShortSequence thisSeq,
Object other,
boolean shouldBe)
{
System.out.println("This: " + thisSeq.toString());
System.out.println("Other: " + other.toString());
System.out.print("According to the equals method, they ");
System.out.print((thisSeq.equals(other))?"ARE":"are NOT");
System.out.print(" equal. They ");
System.out.print((shouldBe)?"SHOULD be":"should NOT be");
System.out.println(" equal.");
System.out.println();
} // method testEquals
} // class ShortSequenceTest4