Question: 1 . 3. The Java program compress below takes two parameters: a string s and an integer factor, which indicates how many consecutive occurences of
1 . 3. 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 is the number of consecutive occurrences of c. The program compresses the input string s by the given compression factor and return the re- sulting compressed string. For example, given the input string "ahhb* and a factor 2, the resulting compressed string will be 23*, but it the factor is instead, then the sequence of two a's is not compressed and the resulting string will be able public static string compress (Strings, int factor if factor 2 throw new IllegalArgumentException compression factor must be 23 if is.length) C2) returns: char last - sehatan int count ! String current - String.valot Last String result - for (int i = tic.ength; i++) charcs.ch if ( clast) Current C counts: else if (count > factor result - last + String valued count); else results current lasti current - String valueof(c): count - 1 11 12 11 15 16 11 18 1 21 34 21 21 if (count factor) result - last String, vaiet count) else results current: return result: 24 (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) factor Expected Output Lines covered value for value for factor expected return value eg. 1-3, 4, 6-9 1 2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
