Description
Assignment Specifications: 1. (13 pts.) Draw a Structural Graph that represents the below piece of source code. You must indicate how each node and edge corresponds to the code. Then, find the test paths (First you need to find all the prime paths and then you can create the test paths from them) int count_spaces(char∗ str) { int length , i , count; count = 0; length = strlen(str ); for(i=1; i<length; i++) { if(str[i] == ’ ’) { count++; } } } CSE 5321-001 Assignment 4 Summer 2018 2. (24 pts.) Consider the following fragment of code: public int foobar(int x, int y,int z) { int k = 0; for(int i=0; i < z; i++) { for(int j=0; j<y; j++) { if(i<j) { k=k*y+x; } else { k–; } } } return(k); } a) Draw a structural control flow graph that represents the above piece of source code. (5 pts.) b) For you graph, enumerate a complete set of paths that guarantee node coverage. (5 pts.) c) Construct a finite set of test cases that guarantee node coverage. For each test case indicate which execution path is covered. (5 pts.) d) For the above fragment of code is there any difference in requiring complete edge coverage rather than node coverage? Justify your answer. (5 pts.) e) Enumerate all the prime paths of the graph you have constructed. (5 pts.) f) For each prime path that you have found construct a test case for that path. Indicate which prime path is covered by your test cases. (5 pts.) 3. Below are four graphs, each of which is defined by the sets of nodes, initial nodes, final nodes, edges, and defs and uses. Each graph also contains a collection of test paths. Answer the following questions about each graph (12 points for each graph – Total 48 pts.) a) Draw the graph. b) List all of the du-paths with respect to x. (Note: Include all du-paths, even those that are sub-paths of some other du-path). c) For each test path, determine which du-paths that test path tours. For this part of the exercise, you should consider both direct touring and side-trips. Hint: A table is a convenient format for describing this relationship. d) List a minimal test set that satisfies all-defs coverage with respect to x. (Direct tours only.) Use the given test paths. e) List a minimal test set that satisfies all-uses coverage with respect to x. (Direct tours only.) Use the given test paths. f) List a minimal test set that satisfies all-du-paths coverage with respect to x. (Direct tours only.) Use the given test paths. 4. (15 pts.) Use the following program fragment for questions a-e below. a) Draw a control flow graph for this program fragment. Use the node numbers given above. b) Which nodes have defs for variable w? c) Which nodes have uses for variable w? d) Are there any du-paths with respect to variable w from node 1 to node 7? If not, explain why not. If any exist, show one. e) Enumerate all of the du-paths for variables w and x.

