For the following program, provide the following:
(a) a control flow graph
(b) the set of unique paths through the program
(c) for each feasible path, exact values of program variables that would cause the path to be executed.
Program 1. The following function, written in a Pascal-like pseudo-code, takes as input a string assumed to be a URL and checks to see if it contains any characters that are illegal. Illegal URL characters are control characters (0-31, 127 decimal), space (32 decimal), and delimeter characters (">", "<", "#", "%", and the double quote character). The function returns true if the URL is valid (does not contain an illegal character), and false if the URL is invalid (contains an illegal character).
Below, italics denote comments. For the switch statement, the conditional is evaluated, then code associated with the conditional runs, then execution goes to the statement immediately after the end of the switch. Strings are represented as a (length, character buffer) pair. That is, you do not need to explicitly null terminate your strings.
is_illegal(input String url, output Boolean valid)
begin Integer i; Char c;
valid =TRUEe;
i = 1;
loop through characters in string
while (i <= length(url) AND valid == TRUE) begin
c = url[i]; get i'th character of string
if (c >= 0 AND c <= 32) then check for control chars and space
valid = false;
else
switch (c) look for delimeters
case ">":
valid = false;
case "<":
valid = false;
case "#":
valid = false;
case "%":
valid = false;
case "\"": check for quote character
valid = false;
end switch;
end if;
end while;
end; end of function
For the following function, perform the following:
(a) pick one of the variables that is an input to the function, and
(a.1) give three example values of that variable that can be derived by performing equivalence partitioning
(a.2) explain why these inputs are representative of equivalence partitioning
(b) for the same input variable to the function,
(b.1) give six example values of that variable that can be derived from boundary value analysis
(b.2) explain why these inputs are representative of boundary value analysis
(c) for all five input variables,
(c.1) give example values of all five that can be derived by performing equivalence partitioning
(c.2) give example values of all five that can be derived by performing boundary value analysis.
Program 2. The embedded software for a digitally controlled VCR has a function that sets the time to automatically record a program. The function's parameter list is:
boolean set_timed_program(input Integer start_hour,
input Integer start_min,
input Integer end_hour,
input Integer end_min,
input Integer channel)
The start and end times are expressed as an (hour, minute) pair, with the hour expressed using 24hr time. The channel ranges from 2 to 99. The function returns true if the program was successfully set, false if it was not set (typically indicating that one of the inputs was invalid).
For example, to record a program starting at 8PM, ending at 9:30PM, on channel 9, the function call would be:
set_timed_program(20, 00, 21, 30, 9);