import static org.junit.Assert.assertEquals; import org.junit.Test; import components.map.Map; /** * JUnit test fixture for {@code Map}'s constructor and kernel * methods. * * @author Put your name here * */ public abstract class MapTest { /** * Invokes the appropriate {@code Map} constructor for the implementation * under test and returns the result. * * @return the new map * @ensures constructorTest = {} */ protected abstract Map constructorTest(); /** * Invokes the appropriate {@code Map} constructor for the reference * implementation and returns the result. * * @return the new map * @ensures constructorRef = {} */ protected abstract Map constructorRef(); /** * * Creates and returns a {@code Map} of the implementation * under test type with the given entries. * * @param args * the (key, value) pairs for the map * @return the constructed map * @requires
     * [args.length is even]  and  
     * [the 'key' entries in args are unique]
     * 
* @ensures createFromArgsTest = [pairs in args] */ private Map createFromArgsTest(String... args) { assert args.length % 2 == 0 : "Violation of: args.length is even"; Map map = this.constructorTest(); for (int i = 0; i < args.length; i += 2) { assert !map.hasKey(args[i]) : "" + "Violation of: the 'key' entries in args are unique"; map.add(args[i], args[i + 1]); } return map; } /** * * Creates and returns a {@code Map} of the reference * implementation type with the given entries. * * @param args * the (key, value) pairs for the map * @return the constructed map * @requires
     * [args.length is even]  and  
     * [the 'key' entries in args are unique]
     * 
* @ensures createFromArgsRef = [pairs in args] */ private Map createFromArgsRef(String... args) { assert args.length % 2 == 0 : "Violation of: args.length is even"; Map map = this.constructorRef(); for (int i = 0; i < args.length; i += 2) { assert !map.hasKey(args[i]) : "" + "Violation of: the 'key' entries in args are unique"; map.add(args[i], args[i + 1]); } return map; } // TODO - add test cases for constructor, add, remove, removeAny, value, hasKey, and size }