CS 3500 Assignment #2 Due: Tuesday, 24 September 2013 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 FListInteger ADT as specified below. Collaboration between students is forbidden on this assignment. You are responsible for keeping your code hidden from all other students. You will submit this assignment within Web-CAT. 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. Assignments submitted between 12:00 am and 11:59 pm the day after the due date will receive a 20 percentage point penalty on the assignment. -------------------------------------------------- Your assignment is to write the code for a single file, TestFListInteger.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 FListInteger 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 FListInteger ADT that were written by other students. -------------------------------------------------- Specification of the FListInteger ADT. FListInteger is an immutable abstract data type whose values represent homogeneous linear lists of integers. The FListInteger 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 FListInteger. The operations of the FListInteger class shall be provided by the following public methods of of the FListInteger class: Signature: Static methods: emptyList : -> FListInteger add : FListInteger x Integer -> FListInteger isEmpty : FListInteger -> boolean get : FListInteger x int -> Integer set : FListInteger x int x Integer -> FListInteger size : FListInteger -> int Dynamic methods (for which the receiver is an FListInteger): toString : -> String equals : Object -> boolean hashCode : -> int Algebraic specification: FListInteger.isEmpty (FListInteger.emptyList()) = true FListInteger.isEmpty (FListInteger.add (f, x)) = false FListInteger.get (FListInteger.add (f, x), n) = x if n == 0 FListInteger.get (FListInteger.add (f, x), n) = FListInteger.get (f, n - 1) if n > 0 FListInteger.set (FListInteger.add (f, x), n, y) = FListInteger.add (f, y) if n == 0 FListInteger.set (FListInteger.add (f, x), n, y) = FListInteger.add (FListInteger.set (f, n - 1, y), x) if n > 0 FListInteger.size (FListInteger.emptyList()) = 0 FListInteger.size (FListInteger.add (f, x)) = 1 + FListInteger.size (f) FListInteger.emptyList().toString() = "[]" FListInteger.add (f, x).toString() = "[" + x.toString() + "]" if FListInteger.isEmpty (f) FListInteger.add(f, x).toString() = "[" + x.toString() + ", " + f.toString().substring(1, f.toString().length()) if ! (FListInteger.isEmpty (f)) Values of the FListInteger ADT shall also implement the public dynamic methods equals(Object) and hashCode() such that If f1 is a value of the FListInteger ADT, but x is not, then f1.equals(x) returns false. If f1 and f2 are values of the FListInteger ADT, then f1.equals(f2) if and only if: (FListInteger.isEmpty(f1) && FListInteger.isEmpty(f2)) or ((FListInteger.size(f1) == FListInteger.size(f2)) and for every integer i such that 0 <= i < FListInteger.size(f1) FListInteger.get(f1,i).equals(FListInteger.get(f2,i)) If f1 and f2 are values of the FListInteger ADT, and f1.equals(f2) then f1.hashCode() == f2.hashCode(). If f1 and f2 are values of the FListInteger ADT, and !(f1.equals(f2)) then f1.hashCode() is unlikely to be equal to f2.hashCode(). -------------------------------------------------- Note: For the hashCode no exact tests are possible, but your test program should issue a warning if it detects the same hashCode for two different values of f1 and f2.