NivaarExam PrepOfficial exam papers ↗

25-Comp-A6 Software Engineering · December 2013

Question 5 of 9: Software Testing

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

Notes on this paper

National Exams — December 2013 — 98-Comp-A6 Software Engineering. Three-hour, closed-book exam, no calculator permitted. Format: nine questions, candidates answer any five of the nine (all questions equal weight — each of the five counted questions is worth 20%; only the first five questions as they appear in the answer book are marked). All nine questions are solved below for completeness.

Reference texts: Sommerville, Software Engineering (10th ed., Pearson) — software process models, object-oriented and function-oriented design, requirements engineering, software testing, software reuse, rapid development and prototyping, client-server architectures, software validation; Pressman, Software Engineering: A Practitioner's Approach (9th ed.) — supplementary process, testing and architecture coverage; Gamma, Helm, Johnson & Vlissides, Design Patterns — object-oriented design/reuse vocabulary.

Question 5: Software Testing (a) 10, (b) 10 — 20 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.

(a) Black-Box vs. White-Box Testing

Black-box (functional/specification-based) testing derives test cases purely from the component's specified behaviour — its inputs, outputs and stated requirements — with no reference to how it is implemented internally. White-box (structural) testing derives test cases from the component's internal structure, aiming to exercise specific statements, branches, or paths through the code. Black-box testing's strengths are that it can be designed as soon as the specification exists (even before the code is written), that it is independent of implementation details and so survives a refactor of the internals unchanged, and that it directly checks whether the software does what it is supposed to do. Its weakness is that it cannot guarantee any particular code coverage — a path through the code may simply never be exercised by any test derived purely from the spec, and defects arising from unusual internal states invisible at the interface can be missed. White-box testing's strength is the reverse: it can systematically guarantee coverage of statements, branches or paths, catching internal logic errors, dead code, and off-by-one conditions that a black-box view would never reveal. Its weakness is that it is tied to a specific implementation (a refactor with unchanged behaviour still requires new white-box tests), it requires access to source and specialised coverage tooling, and passing every internal path proves nothing about whether the code actually implements the intended requirement — a consistently-wrong implementation can have 100% white-box coverage and still fail every black-box case.

(b) Black-Box Test Cases

1. Integer array sort routine

Test casePurpose
Empty arrayBoundary: zero elements
Single-element arrayBoundary: trivially sorted
Already-sorted arrayBest-case / no-op behaviour
Reverse-sorted arrayWorst-case ordering
Array with duplicate valuesStability/tie-handling of equal keys
Array with negative and positive valuesCorrect ordering across sign
Array with all identical elementsDegenerate case, no distinct ordering
Array containing INT_MIN / INT_MAXBoundary values of the integer type
Large random arrayGeneral-case correctness at scale

2. Non-blank character counter

Test casePurpose
Empty lineBoundary: zero-length input, expect count 0
Line of all blanksExpect count 0
Line with no blanks at allExpect count = line length
Line with mixed blank and non-blank charactersGeneral case
Line with leading and/or trailing blanksBlanks at the boundary of the string, not just interior
Line containing tab charactersClarifies whether "blank" means space only or any whitespace
Line with punctuation/special charactersConfirms non-space, non-alphanumeric characters are counted as non-blank
Single-character lineBoundary: smallest non-empty input
Very long lineGeneral-case correctness / buffer handling at scale

3. STRING abstract data type

OperationTest cases
length()Empty string (0); single character (1); typical string; string containing special/whitespace characters
concatenation()Both operands non-empty; one operand empty (identity check: s + "" = s); both operands empty (result empty); result length equals sum of operand lengths
sub-string selection()Substring at the very start; substring at the very end; the whole string; a zero-length substring; a single-character substring; out-of-range indices (start beyond length, negative start, end before start) to confirm defined error behaviour