CS 3500 Assignment #2 Section: Proulx Assigned: Friday, 14 September 2012 Due: Friday, 21 September 2012 The purposes of this assignment are: * to construct black-box tests from a formal specification * to emphasize the distinction between clients and implementors You will write a black-box test program for the FListString ADT as specified below. Collaboration between students is forbidden on this assignment. You are responsible for keeping your code hidden from all other students. Turn in your work on this assignment before 10 pm on the due date by following instructions on the course's main assignments web page, http://www.ccs.neu.edu/course/cs3500wc/assignments.html Your file of Java code should begin with a block comment that lists 1. Your name, as you want the instructor to write it. 2. Your email address. 3. Any remarks that you wish to make to the instructor. Part of your grade will depend on the quality and correctness of your code and black-box tests, part will depend on the readability of your code (comments and indentation), and part will depend on how well you follow the procedure above for submitting your work. Late assignments may be discounted, and very late assignments may be discarded. -------------------------------------------------- Your assignment is to write the code for a single file, TestFListString.java, that implements a public static void main(String[]) method that, when called with any array of strings, performs black-box testing of any and all implementations of the FListString ADT that satisfy its specification given below. (Note: Your main method should probably just ignore the array of strings that it receives as an argument, since you cannot rely on the number of strings or their content.) A future assignment will require you to work with other students as a team, implementing a black-box test program and using that program to test implementations of the FListString ADT that were written by other students. -------------------------------------------------- Specification of the FListString ADT. FListString is an immutable abstract data type whose values represent homogeneous linear lists of strings. The FListString ADT shall be implemented in Java, and will be tested using Sun's Java 2 Runtime Environment, Standard Edition, version 1.6.0. The code for this implementation shall be in the default package, and shall define a public class named FListString. The operations of the FListString class shall be provided by the following public methods of of the FListString class: Signature: Static methods: emptyList() : -> FListString add : FListString x String -> FListString isEmpty : FListString -> boolean get : FListString x int -> String set : FListString x int x String -> FListString size : FListString -> int Dynamic methods (for which the receiver is an FListString): toString : -> String equals : Object -> boolean hashCode : -> int Algebraic specification: FListString.isEmpty (FListString.emptyList()) = true FListString.isEmpty (FListString.add (f, x)) = false FListString.get (FListString.add (f, x), n) = x if n == 0 FListString.get (FListString.add (f, x), n) = FListString.get (f, n - 1) if n > 0 FListString.set (FListString.add (f, x), n, y) = FListString.add (f, y) if n == 0 FListString.set (FListString.add (f, x), n, y) = FListString.add (FListString.set (f, n - 1, y), x) if n > 0 FListString.size (FListString.emptyList()) = 0 FListString.size (FListString.add (f, x)) = 1 + FListString.size (f) FListString.emptyList().toString() = "[]" FListString.add (f, x).toString() = "[" + x.toString() + "]" if FListString.isEmpty (f) FListString.add(f, x).toString() = "[" + x.toString() + ", " + f.toString().substring(1, f.toString().length()) if ! (FListString.isEmpty (f)) Values of the FListString ADT shall also implement the public dynamic methods equals(Object) and hashCode() such that If f1 is a value of the FListString ADT, but x is not, then f1.equals(x) returns false. If f1 and f2 are values of the FListString ADT, then f1.equals(f2) if and only if: (f1.isEmpty() && f2.isEmpty()) or ((f1.size() == f2.size()) and for every integer i such that 0 <= i < f1.size() f1.get(i).equals(f2.get(i)) If f1 and f2 are values of the FListString ADT, and f1.equals(f2) then f1.hashCode() == f2.hashCode(). If f1 and f2 are values of the FListString ADT, and !(f1.equals(f2)) then f1.hashCode() is unlikely to be equal to f2.hashCode(). --------------------------------------------------