SYSC-4101_Lab6

.pdf

School

Carleton University *

*We aren’t endorsed by this school

Course

1805A

Subject

Computer Science

Date

Feb 20, 2024

Type

pdf

Pages

3

Uploaded by DeaconMoon9640 on coursehero.com

Page 1 SYSC 4101 Laboratory 6 Exercise 1 (10 marks) Create the control flow graph for the following two Java methods: use the condensed form; label control flow nodes after line number(s); label branches with Y or N depending on conditions. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 protected static final String addEscapes(String str) { StringBuilder retval = new StringBuilder(); char ch; for (int i = 0; i < str.length(); i++) { switch (str.charAt(i)) { case '\b': retval.append("\\b"); continue; case '\t': retval.append("\\t"); continue; case '\n': retval.append("\\n"); continue; case '\f': retval.append("\\f"); continue; case '\r': retval.append("\\r"); continue; case '\"': retval.append("\\\""); continue; case '\'': retval.append("\\\'"); continue; case '\\': retval.append("\\\\"); continue; default: if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { String s = "0000" + Integer.toString(ch, 16); retval.append("\\u" + s.substring(s.length() - 4, s.length())); } else { retval.append(ch); } continue; } } return retval.toString(); } 1 2 3 4 5 6 7 8 9 10 11 12 void foo() { Random r = new Random(); Set<Integer> aSet= new HashSet<Integer>(); int anInt; do { anInt = r.nextInt(10); if (anInt % 2 == 0) continue; System.out.println(anInt); } while (aSet.add(anInt)); System.out.println(aSet); }
Page 2 Exercise 2 (50 marks) Consider the graph below: it has 7 nodes and 8 edges; it has one initial node, namely node 1, and one final node, namely node 7. Nodes and edges are labeled with data flow information, specifically uses and definitions of variables x and y. The order of appearance (top to bottom) of uses and definitions in labels for nodes 4 and 5 indicates the actual order of executions of the uses and definitions at those nodes. Question 1: [5 marks] List the round trip paths for this graph. Question 2: [5 marks] List the test requirements (a.k.a. test objectives) for the Simple-Round-Trip criterion. Question 3: [5 marks] Create a set of test paths, i.e., paths from the initial node to the final node, that is adequate for the Simple-Round-Trip criterion. Question 4: [5 marks] Is the Simple-Round-Trip adequate test suite you created in the previous question adequate for the Complete-Round-Trip criterion? Justify. Question 5: [5 marks] List the test requirements (a.k.a. test objectives) for the All-Defs criterion. (Remember to account for both variables x and y.) Question 6: [5 marks] Create a set of test paths, i.e., paths from the initial node to the final node, that is adequate for the All-Defs criterion.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help