Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer)
Notes on this paper
04-Soft-A6, Software Quality Assurance — National Exams, May 2015 (3 hours, open book, 8 questions of equal value; the first FIVE as they appear in the answer book are marked — all eight are solved here as a study resource).
Given. The unit under test is the nested-loop body of GeneratePyramidExample.main (Appendix B, lines 21–31): an outer loop for(i=0; i<=as; i++) containing an inner loop for(j=1; j≤i; j++) that prints a running total y (initialised once, outside both loops, and never reset).
Find. The cyclomatic complexity V(G) of the unit, and a minimal set of V(G) basis-path test cases (each input pair (as, x) plus its exact expected console output) that together execute every independent path through the control-flow graph.
Control-flow graph of the pyramid unit. Node 1: y=0. Node 2: outer for-test. Node 3: inner for-test. Node 4: print(y);y+=x. Node 5: println(""). Node 6: exit. Nodes 2 and 3 are the two predicate (decision) nodes.
Approach. Draw the flow graph of the nested-loop unit, compute V(G) by both the edge–node formula and the predicate-node formula (they must agree), then derive V(G) independent basis paths by taking a baseline path and flipping one decision outcome at a time, and choose concrete (as, x) inputs that force each path.
Compute V(G) two independent ways.
$$V(G) = E - N + 2 = 7 - 6 + 2 = \boxed{3}$$
$$V(G) = 1 + \sum_{\text{predicates}}(\text{out-degree}-1) = 1 + (2-1) + (2-1) = \boxed{3}$$
Both formulas agree at V(G) = 3, so exactly 3 independent basis-path test cases are required.
Path 1: outer test fails immediately (nodes 1-2-6). The outer loop body never executes at all — this requires as < 0, since i starts at 0 and i ≤ as must be false on the very first check.
Input: as = -1, x = 5 → Expected console output: (nothing printed — zero rows)
Path 2: outer loop runs, inner test fails on its only visit (nodes 1-2-3-5-2-6). This is forced by as = 0: the single outer iteration has i = 0, so the inner test j ≤ i (i.e. 1 ≤ 0) is false immediately, the inner body never runs, and only the row-ending println("") executes before the outer loop exits.
Input: as = 0, x = 5 → Expected console output: one blank line
Path 3: inner loop body executes at least once (nodes 1-2-3-4-3-5-2-6). This requires an outer iteration with i ≥ 1. Substituting as = 2, x = 1 and tracing by hand: i=0 → inner skipped, blank row; i=1 → inner runs once, prints y=0 then y becomes 1, row = "0\t"; i=2 → inner runs twice, prints y=1 (then y→2) and y=2 (then y→3), row = "1\t2\t".
Input: as = 2, x = 1 → Expected console output (3 lines): (blank) 0 (tab) 1 2 (tabs)
Note that y is declared once before the outer loop and is never reset per row — it is a running total across the ENTIRE pyramid, not a fresh count restarting at 0 on each row, which is why row i=2 continues 1, 2 rather than restarting at 0, 1.
Basis-path test suite for GeneratePyramidExample
Path
Nodes traversed
Input (as, x)
Expected output
1
1-2-6
(−1, 5)
No rows printed
2
1-2-3-5-2-6
(0, 5)
One blank row
3
1-2-3-4-3-5-2-6
(2, 1)
Rows: "", "0\t", "1\t2\t"
Check: assumes a normal (non-exceptional) input for as and x — a full test plan would add an error-handling path for non-numeric console input (Integer.parseInt throwing NumberFormatException), which is outside the 3 basis paths of the arithmetic control flow itself and would be covered separately by black-box/robustness testing (Q7's technique), not by this white-box basis-path count.