Question: The Java program compress below takes two parameters: a string s and an integer factor, which indicates how many consecutive occurences of any character c
The Java program compress below takes two parameters: a string s and an integer factor, which indicates how many consecutive occurences of any character c should be compressed in the form cn where n is the number of consecutive occurrences of c. The program compresses the input string s by the given compression factor and return the resulting compressed string. For example, given the input string "aabbb" and a factor 2, the resulting compressed string will be "a2b3", but it the factor is 3 instead, then the sequence of two as is not compressed and the resulting string will be "aab3". 1 public static String compress(String s, int factor) { 2 if (factor < 2) 3 throw new IllegalArgumentException("compression factor must be >=2"); 4 if (s.length() = factor) 17 result += last + String.valueOf(count); 18 else 19 result += current; 20 last = c; 21 current = String.valueOf(c); 22 count = 1; 23 } 24 } 25 if (count >= factor) 26 result += last + String.valueOf(count); 27 else 28 result += current; 29 return result; 30 } (a) Measurement: Draw a control flow graph for the given program and compute its cyclomatic complexity. [10 marks] (b) Coverage: Write exactly four test cases and indicate which lines of code each of them covers. Use the following table as template for your tests. You are not required to write JUnit test code. [10 marks] # s factor Expected Output Lines covered value for s value for factor expected return value e.g., 1-3, 4, 6-9 1 ... ... ... ... 2 ... ... ... ... ... ... ... ... ... Version 1 Page 4 of 11 CO3095/7095/7508 All candidates (c) Data-flow Testing: For all the variables contained in the compress method above, list all the definition-use pairs, distinguishing between predicate (p-use) and computational uses (c-use). You can use the following table as template. Variable Def-use pairs (p-use) Def-use pairs (c-use) s (1,2), ... (3,4), ... factor (5,6), ... (7,8), ...
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
