import static org.junit.Assert.assertEquals; import org.junit.Test; import components.set.Set; /** * JUnit test fixture for {@code Set}'s constructor and kernel methods. * * @author Put your name here * */ public abstract class SetTest { /** * Invokes the appropriate {@code Set} constructor and returns the result. * * @return the new set * @ensures constructorTest = {} */ protected abstract Set constructorTest(); /** * Invokes the appropriate {@code Set} constructor and returns the result. * * @return the new set * @ensures constructorRef = {} */ protected abstract Set constructorRef(); /** * Creates and returns a {@code Set} of the implementation under * test type with the given entries. * * @param args * the entries for the set * @return the constructed set * @requires [every entry in args is unique] * @ensures createFromArgsTest = [entries in args] */ private Set createFromArgsTest(String... args) { Set set = this.constructorTest(); for (String s : args) { assert !set.contains(s) : "Violation of: every entry in args is unique"; set.add(s); } return set; } /** * Creates and returns a {@code Set} of the reference implementation * type with the given entries. * * @param args * the entries for the set * @return the constructed set * @requires [every entry in args is unique] * @ensures createFromArgsRef = [entries in args] */ private Set createFromArgsRef(String... args) { Set set = this.constructorRef(); for (String s : args) { assert !set.contains(s) : "Violation of: every entry in args is unique"; set.add(s); } return set; } // TODO - add test cases for constructor, add, remove, removeAny, contains, and size }