Homework: Testing Sequence Smooth


This homework is necessary preparation for the lab. Make sure you type your answers in a file you bring to the lab so that you will not have to waste time entering your test cases during the lab.

  1. Develop a complete test plan for the following static method smooth.
        /**
         * Smooths a given {@code Sequence<Integer>}.
         * 
         * @param s1
         *            the sequence to smooth
         * @param s2
         *            the resulting sequence 
         * @replaces s2
         * @requires |s1| >= 1
         * @ensures <pre>
         * |s2| = |s1| - 1  and
         *  for all i, j: integer, a, b: string of integer
         *      where (s1 = a * <i> * <j> * b)
         *    (there exists c, d: string of integer
         *       (|c| = |a|  and
         *        s2 = c * <(i+j)/2> * d))
         * </pre>
         */
        public static void smooth(Sequence<Integer> s1, Sequence<Integer> s2) {...}
    
  2. Code your test cases in the JUnit test fixture accessible from the link below. Make sure you have access to an electronic version of the completed file in closed lab. Turn in a PDF copy as your homework.

A JUnit Test Fixture

Download the SequenceSmoothTest.java file and edit it to add your own test cases. The file already contains a couple of example test cases to remind you of how JUnit test fixtures are organized. Pay attention to the createFromArgs(Integer... args) private method which is used to construct a Sequence<Integer> from an arbitrary number of Integer (or int) arguments. This method uses a Java notation that you are probably not familiar with. The formal parameter notation Integer... args is known as varargs and allows methods in Java to have an arbitrary (greater than or equal to zero) number of parameters of the same type. The file shows examples of how to call such a method. If you want to learn more about this feature, see this link or search the web for more information.

Note that your JUnit test fixture will not compile until we provide you with the SequenceSmooth class in the lab.