NivaarExam PrepOfficial exam papers ↗

19-Soft-A6 Software Quality Assurance · May 2016

Question 8 of 8

Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer)

Notes on this paper

04-Soft-A6, Software Quality Assurance — National Exams, May 2016 (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).

Reference texts: Pressman, Software Engineering: A Practitioner's Approach, 9th ed. (SQA planning, review, testing strategies/techniques, cyclomatic complexity, basis path testing); Sommerville, Software Engineering, 10th ed. (software process, agile practice, configuration management); ISO/IEC 25010 SQuaRE (software quality characteristics); ISO/IEC 12207 (life-cycle/configuration-management processes).

Question 8 (10 marks)

Question text not reproduced: the examination questions are © Engineers and Geoscientists BC. Open the official past paper (linked at the top of this page) to read the question, then follow the worked solution below.

Given. The unit under test is the Appendix A main function's nested-if leap-year logic: three sequential decisions — year % 4 == 0, then (nested inside it) year % 100 == 0, then (nested inside that) year % 400 == 0 — each guarding one of four printf outcomes.

Find. The cyclomatic complexity V(G) of the unit, and a minimal basis path testing suite of V(G) independent test cases (one input year each) that together execute every independent path through the control-flow graph.

1 2 3 4 5 6 7 8 9 read year T (%4==0) F (%4≠0) T (%100==0) F (%100≠0) T (%400==0) F (%400≠0) leap (400T) not leap (400F) leap (100F) not leap (4F) V(G) = E - N + 2 = 11 - 9 + 2 = 4
Control-flow graph of the leap-year unit. Node 1: read year. Node 2: year%4==0. Node 3: year%100==0. Node 4: year%400==0. Node 5: print "leap" (400 true). Node 6: print "not leap" (400 false). Node 7: print "leap" (100 false — divisible by 4, not by 100). Node 8: print "not leap" (4 false). Node 9: exit. Nodes 2, 3 and 4 are the three predicate (decision) nodes.

Approach. Draw the flow graph of the triple-nested decision, compute V(G) two independent ways (they must agree), then derive V(G) independent basis paths — flipping one prior decision outcome at a time from a baseline — and pick the classic century-year test inputs that force each path.

  1. Build the flow graph and count nodes/edges. Nine nodes (1: read; 2,3,4: the three nested decisions; 5,6,7,8: the four printf outcomes; 9: exit) and eleven edges: 1→2; 2→3(T); 2→8(F); 3→4(T); 3→7(F); 4→5(T); 4→6(F); 5→9; 6→9; 7→9; 8→9.
  2. Compute V(G) two independent ways. $$V(G) = E - N + 2 = 11 - 9 + 2 = \boxed{4}$$ $$V(G) = 1 + \sum_{\text{predicates}}(\text{out-degree}-1) = 1 + (2-1) + (2-1) + (2-1) = \boxed{4}$$ Both formulas agree at V(G) = 4, matching the three nested binary decisions (each predicate node contributes one extra independent path). Exactly 4 basis-path test cases are required.
  3. Path 1: not divisible by 4 (nodes 1-2-8-9). The outer decision alone determines the outcome, both inner decisions are never reached.
    Input: year = 2015 → 2015 % 4 = 3 ≠ 0 → Expected output: "2015 is not a leap year."
  4. Path 2: divisible by 4, not by 100 (nodes 1-2-3-7-9). An ordinary (non-century) leap year — the inner %400 test is never reached.
    Input: year = 2016 → 2016 % 4 = 0, 2016 % 100 = 16 ≠ 0 → Expected output: "2016 is a leap year."
  5. Path 3: divisible by 4, 100 and 400 (nodes 1-2-3-4-5-9). A century year that IS a leap year — all three decisions are true.
    Input: year = 2000 → 2000 % 4 = 0, 2000 % 100 = 0, 2000 % 400 = 0 → Expected output: "2000 is a leap year."
  6. Path 4: divisible by 4 and 100, not 400 (nodes 1-2-3-4-6-9). A century year that is NOT a leap year — the case the algorithm exists specifically to catch (a naive "divisible by 4" check alone would wrongly call this a leap year).
    Input: year = 1900 → 1900 % 4 = 0, 1900 % 100 = 0, 1900 % 400 = 300 ≠ 0 → Expected output: "1900 is not a leap year."
Basis-path test suite for the leap-year unit
PathNodes traversedInput yearExpected output
11-2-8-92015"2015 is not a leap year."
21-2-3-7-92016"2016 is a leap year."
31-2-3-4-5-92000"2000 is a leap year."
41-2-3-4-6-91900"1900 is not a leap year."
Check: assumes normal numeric console input for year — a full test plan would add a robustness case for non-numeric scanf input, which is a black-box/error-handling concern (Q7's technique) outside the 4 basis paths of the arithmetic decision logic itself.
Back to the paper →