import components.stack.Stack; /** * JUnit test fixture for {@code Stack}'s constructor and kernel * methods. * * @author Put your name here * */ public abstract class StackTest { /** * Invokes the appropriate {@code Stack} constructor for the implementation * under test and returns the result. * * @return the new stack * @ensures constructorTest = <> */ protected abstract Stack constructorTest(); /** * Invokes the appropriate {@code Stack} constructor for the reference * implementation and returns the result. * * @return the new stack * @ensures constructorRef = <> */ protected abstract Stack constructorRef(); /** * * Creates and returns a {@code Stack} of the implementation under * test type with the given entries. * * @param args * the entries for the stack * @return the constructed stack * @ensures createFromArgsTest = [entries in args] */ private Stack createFromArgsTest(String... args) { Stack stack = this.constructorTest(); for (String s : args) { stack.push(s); } stack.flip(); return stack; } /** * * Creates and returns a {@code Stack} of the reference * implementation type with the given entries. * * @param args * the entries for the stack * @return the constructed stack * @ensures createFromArgsRef = [entries in args] */ private Stack createFromArgsRef(String... args) { Stack stack = this.constructorRef(); for (String s : args) { stack.push(s); } stack.flip(); return stack; } // TODO - add test cases for constructor, push, pop, and length }