Figure 5: Tests DynamicStack

class StackTest2
{
    public static void main(String[] args)
    {
        DynamicStack s = new DynamicStack();
        doTest(s);
    }

    public static void doTest(DynamicStack s)
    {
        // No exceptions to check here:
        System.out.println("Initial size = " + s.size());
        s.push("one");
        s.push(new Integer(2));
        s.push(new Float(3.0));
        s.push("one too many");

        try
        {
            System.out.println("Top: " + s.top());
            System.out.println("Popping...");

            while (s.size() > 0)
                System.out.println(s.pop());
        }
        catch(StackException x)
        {
            throw new InternalError(x.toString());
        }
    }
}

/* Output:
Initial size = 0
Top: one too many
Popping...
one too many
3.0
2
one
*/