Assignment 4, due Feb 8

Part of the homework for CS:2820, Spring 2019
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Assignments are to be turned in on paper. On every assignment, write your name, course and section number at the top of each page. Write your name as it appears in your university records! Use the section number for which you are registered! We will not do detective work to figure out who did what. Work must be legible.

Homework is due on paper in discussion section, usually at the start except when the assignment indicates that time to work on the assignment will be provided in class. Exceptions will be made only by advance arrangement with your TA (excepting "acts of God" outside your control). Never push homework under someone's door!

  1. Background: Every Java for loop can be rewritten in several forms. Consider the following loop:
    String s = "something";
    for ( int i = 0; i < s.length(); i++ ) {
        system.out.print( s.charAt( i ) );
    }
    

    a) Rewrite this as a while loop, still using an integer control variable. (0.5 points)

    b) Rewrite this using a while loop, but using class StringCharacterIterator to deliver consecutive characters of the string. (0.5 points)

    Note: Class StringCharacterIterator is a wretched class that ought to correspond in some way to Iterator <Character> but isn't even vaguely compatible.

  2. Background: Think about testing a program that builds the data structure representing a system of digital logic gates. At the very least, you want every statement in the program to be executed at least once by some test case. A test suite that does this is said to use path testing. Path testing is dumb, all you are trying to do is make the program follow every path through the code, so the only data values that matter are values that push determine the control structure.

    Assuming that your solution to MP2 will process an input file looking something like this:

    gate a xor 6.7
    gate b threshold 1 3.6
    wire a 3.2 b
    wire b 1.5 a 1.8 a
    

    Wires must contain at least one destination but may contain more, each preceeded by the delay from the source. Gates must have a delay, and threshold gates have a threshold given before the delay. Of course, the input file must be given on the command line, and it must be possible to open it.

    A problem: Given what you know about MP1 and what you can guess about your solution to MP2, what is the minimum number of distinct test runs required to do path testing on the program. Give a very brief justification for each run, showing the parameters you would provide when you launch the program and the test file, if any. (1.0 point)

    Note: A fully developed path test suite can only be developed after you write the code, but this problem asks you to start designing some appropriate tests before you have any code, in keeping with the extreme programming philosophy of developing tests before writing code. With no code, you can try to work on testing all the ways you could make an error in the input text.