Consider the following code:
if ((a >= b) && (a >= c)) max = a;
if ((b >= a) && (b >= c)) max = b;
if ((c >= a) && (c >= b)) max = c;
(a) Draw the flow graph for this code segment. (5 Pts)
(b) Calculate the cyclomatic complexity for this code (2 Pts)
(c) Identify one infeasible path if any. (1 Pts)
(d) Identify all feasible paths (2 Pts)
(e) Write white-box test cases for all the feasible paths (5 Pts)
Show answerJawab dekhein
(a) Nodes: 1 = if1; 2 = max = a; 3 = if2; 4 = max = b; 5 = if3; 6 = max = c; 7 = end. Edges: 1-2 (T), 1-3 (F), 2-3, 3-4 (T), 3-5 (F), 4-5, 5-6 (T), 5-7 (F), 6-7.
(b) Three decisions, so V(G) = 3 + 1 = 4 (E - N + 2 = 9 - 7 + 2 = 4).
(c) Infeasible: F F F (1-3-5-7), because one of a, b, c is always the largest, so at least one condition is true.
(d) Feasible (if1, if2, if3): TFF, FTF, FFT, TTF, TFT, FTT, TTT.
(e) TFF: a=3,b=2,c=1 -> max=3; FTF: a=1,b=3,c=2 -> 3; FFT: a=1,b=2,c=3 -> 3; TTF: a=3,b=3,c=1 -> 3; TFT: a=3,b=1,c=3 -> 3; FTT: a=1,b=3,c=3 -> 3; TTT: a=2,b=2,c=2 -> 2.