Course outline

Software QA / Basic: reasoning and test design / Lesson 7

Build independent expected results for small examples

Develop independent expected results and use contrasting examples to reveal weak assertions.

About 22 min read20 worked examples20 practice exercisesContent reviewed
On this page

Lesson goals

  • Calculate expected results from an agreed rule.
  • Distinguish assertions that detect different failures.
  • Explain the limits of a small example set.
  • Derive an independent result from an agreed sorting rule and state its assumptions.
  • Use counterexamples to distinguish ordering, preservation, and stability assertions.

Start with an agreed rule

A test oracle is the basis for deciding whether an observation is acceptable. Before exercising a feature, write the rule in terms that a reviewer can understand and identify any open decisions. Suppose a course catalog sorts numeric priorities from smallest to largest while retaining duplicates. This is a teaching rule for an isolated example, not a claim about every catalog. An independent calculation on a few small inputs can reveal errors that a result copied from the implementation would repeat. Record the rule version alongside the examples.

Work through contrasting cases

Begin with the empty list, a single value, and an unsorted list containing a duplicate. Compute each expected list by hand before viewing the actual output. The third case checks more than order: both occurrences of 3 must remain. A list that is already sorted is still useful, but a function that simply returns its input would pass it. Pairing that case with an unsorted input makes the set more discriminating without pretending to cover every possible input.

text Examples derived from the teaching rule
Input | Expected output
empty list | empty list
one item | unchanged item
[3, 1, 3] | [1, 3, 3]

The third expected result is ordered and retains the two occurrences of 3.

Choose observations that detect plausible errors

A check that merely confirms the result is a list would accept many incorrect outputs. Compare the complete expected sequence for the small example, and consider properties separately for a broader set: the result should be ordered and preserve the input values with their counts. An ordering check alone accepts an empty list, while a preservation check alone accepts the original unsorted list. Think of each plausible wrong behavior as a question: which assertion would fail and why?

text Relate plausible defects to observations
Defect | Expected check
drop duplicates | multiset preserved
reverse order | ascending order
return input | unsorted example changes

Each row names a distinct wrong behavior and the kind of observation that can expose it.

Keep assumptions and uncertainty visible

The examples do not decide how missing values, text, very large inputs, or malformed values should be handled. Ask the owner whether those inputs are allowed and what the contract promises before inventing an expectation. Also identify the scope of the observation: a pure sorting function can be checked independently, but a catalog screen adds filtering, persistence, localization and presentation. A passing function example is evidence about that function for the selected input; it is not evidence that the entire screen is correct.

Review and maintain the oracle

Have a second person derive at least one result from the rule without consulting the implementation. If their answer differs, resolve the ambiguity in the rule and update both the expected result and its rationale. When the product changes from ascending to descending order, review all linked examples instead of changing a failing expected value automatically. Preserve a case that exposed a real defect as a regression check and state its purpose so that future maintainers do not remove it as redundant.

Make the oracle independent

An oracle is the basis for deciding whether an observed result is acceptable. Begin with an agreed rule and derive the expected result before running the implementation. In this lesson the synthetic rule sorts numeric priorities ascending and retains every occurrence. For [4, 1, 4], order the three input values by hand to obtain [1, 4, 4]; copying whatever the function returns would allow its defect to become the expected result. Record the rule revision and the assumptions about valid input.

Independence is a matter of source and reasoning, not merely using a second screen. Two screens that read the same wrongly sorted field can agree. A trusted example computed by a separate reviewer can challenge a result, but even a reviewer can misread an ambiguous requirement. Resolve disagreements with the rule owner and preserve the calculation so it can be reviewed.

Choose cases that distinguish wrong behaviors

A small example set should separate plausible implementations, not merely contain several inputs. An empty list checks the empty case; a single value checks preservation; an already sorted list checks stability of the result; an unsorted list distinguishes sorting from simply returning the input. Include duplicates to expose accidental deduplication and negative values if the agreed numeric domain includes them. Each case needs an exact expected output and a reason for its inclusion.

A case can detect a defect only when its assertion observes the relevant difference. For [4, 1, 4], an ordering-only check accepts [1, 4], even though one occurrence was lost. Comparing the complete expected sequence detects both the wrong order and the missing value for that input. Do not infer that one passing example proves every size or data type.

Combine complementary properties

Two useful properties for sorting are ascending order and preservation of the input multiset: every value must appear the same number of times. Neither property alone is sufficient. The empty list is ordered but fails preservation for a nonempty input; the unchanged input preserves values but fails ordering if it was unsorted. Together, under a defined numeric comparison rule, they constrain the result more strongly.

Exact examples and properties serve different purposes. A complete expected output gives a readable, independently calculated oracle for one small input. A property can be checked across additional selected inputs without manually listing every result, but its implementation must itself be reviewed. If the contract specifies stable ordering for equal keys, a separate observation of attached identifiers is needed; numeric value preservation alone cannot reveal a stability defect.

Expose assumptions about comparison and representation

The simple numeric rule does not automatically define behavior for missing values, strings, mixed types, or non-finite values. Ask whether these inputs are allowed and, if so, how they compare before writing expected outputs. Lexicographic text order and numeric order differ: strings "10" and "2" can be ordered differently from numbers 10 and 2. Do not silently convert between them or assume a locale-specific order.

Clarify whether the function may mutate its input and whether equal-key records retain their original relative order. These are separate obligations from the numeric sequence. When input mutation is prohibited, preserve a copy before the call and compare it afterward. If no such promise exists, an in-place implementation is not necessarily a defect. An example is useful only when its expected behavior follows an authorized rule.

Use counterexamples to evaluate assertions

Imagine a wrong implementation and ask whether a proposed assertion rejects it. A function returning [] for every input passes a bare ascending-order check but fails multiset preservation for [2, 1]. A function returning its input passes preservation but fails ascending order for [2, 1]. A function returning a set sorted ascending can satisfy order while dropping the second occurrence in [2, 1, 2]. These counterexamples expose exactly what each assertion can and cannot detect.

Do not confuse a hypothetical wrong result with an executed test failure. Record the synthetic input, proposed output, violated rule, and assertion that would distinguish it. A passing check on an already sorted input cannot disprove a return-input defect. Pair the assertion with an input that makes the behavior observable, then retain that case as a regression test if an actual defect is later confirmed.

Review scope and maintain expected results

A report should identify the rule version, selected input, expected sequence, actual output if observed, and the comparison used. If only examples have been designed, call them planned. A passing pure function case does not establish correct filtering, localization, display, or persistence in a catalog interface. Record untested representations and boundaries so a reader can judge the claim.

When a rule changes from ascending to descending, recompute linked examples independently and update their rationale. Do not automatically replace expected values with current output. Review empty and duplicate cases as well as nonempty order; some expectations remain unchanged while their purpose persists. A second reviewer can check the derivation and identify ambiguous comparisons before the test becomes a misleading regression guard.

20 worked examples

1. Empty input

Problem: Analyze the synthetic empty input scenario and derive its expected result or oracle limit.

  1. There are no values to reorder or preserve.
  2. The output must therefore contain no values. This applies to the stated synthetic input and rule.
text Synthetic scenario, not an execution record
rule: ascending numeric sort; retain occurrences
input=[]

The hypothetical fixture supplies the input and rule for independent derivation.

Expected result: Expected [].

Why this result follows: The empty case defines the zero-element boundary without implying behavior for nonempty inputs.

2. Single value

Problem: Analyze the synthetic single value scenario and derive its expected result or oracle limit.

  1. One value is already in ascending order.
  2. Preservation requires that the same occurrence remains in the result.
text Synthetic scenario, not an execution record
rule: ascending numeric sort; retain occurrences
input=[7]

The hypothetical fixture supplies the input and rule for independent derivation.

Expected result: Expected [7].

Why this result follows: The singleton detects a function that always returns an empty result. This conclusion follows from the stated rule and input.

3. Already sorted

Problem: Analyze the synthetic already sorted scenario and derive its expected result or oracle limit.

  1. Each value is no greater than the next.
  2. The sequence already meets the rule and all occurrences must remain.
text Synthetic scenario, not an execution record
rule: ascending numeric sort; retain occurrences
input=[1, 2, 3]

The hypothetical fixture supplies the input and rule for independent derivation.

Expected result: Expected [1, 2, 3].

Why this result follows: This case checks the existing order but cannot distinguish a return-input defect by itself.

4. Unsorted pair

Problem: Analyze the synthetic unsorted pair scenario and derive its expected result or oracle limit.

  1. One is smaller than two and must appear first.
  2. Both input values occur once and remain once in the result.
text Synthetic scenario, not an execution record
rule: ascending numeric sort; retain occurrences
input=[2, 1]

The hypothetical fixture supplies the input and rule for independent derivation.

Expected result: Expected [1, 2].

Why this result follows: The reversed pair distinguishes sorting from simply returning the original input. This conclusion follows from the stated rule and input.

5. Duplicate preservation

Problem: Analyze the synthetic duplicate preservation scenario and derive its expected result or oracle limit.

  1. One precedes four in ascending order.
  2. Both occurrences of four must be retained in the output.
text Synthetic scenario, not an execution record
rule: ascending numeric sort; retain occurrences
input=[4, 1, 4]

The hypothetical fixture supplies the input and rule for independent derivation.

Expected result: Expected [1, 4, 4].

Why this result follows: A complete expected sequence exposes both incorrect ordering and dropped duplicates for this input.

6. Negative numbers

Problem: Analyze the synthetic negative numbers scenario and derive its expected result or oracle limit.

  1. Negative two is less than zero, which is less than one.
  2. Each of the three input values occurs once.
text Synthetic scenario, not an execution record
rule: ascending numeric sort; negative values allowed
input=[0, -2, 1]

The hypothetical fixture supplies the input and rule for independent derivation.

Expected result: Expected [-2, 0, 1].

Why this result follows: This case checks that signed numeric comparison follows the agreed domain and order.

7. All equal

Problem: Analyze the synthetic all equal scenario and derive its expected result or oracle limit.

  1. The three values are equal and already satisfy ascending order.
  2. Preservation requires all three occurrences, not one.
text Synthetic scenario, not an execution record
rule: ascending numeric sort; retain occurrences
input=[3, 3, 3]

The hypothetical fixture supplies the input and rule for independent derivation.

Expected result: Expected [3, 3, 3].

Why this result follows: An all-equal input reveals deduplication even though order alone cannot distinguish the result.

8. Descending input

Problem: Analyze the synthetic descending input scenario and derive its expected result or oracle limit.

  1. One is smallest and five is largest.
  2. Reversing this specific descending input gives the independently calculated ascending order.
text Synthetic scenario, not an execution record
rule: ascending numeric sort; retain occurrences
input=[5, 3, 1]

The hypothetical fixture supplies the input and rule for independent derivation.

Expected result: Expected [1, 3, 5].

Why this result follows: A descending input exposes a function that leaves already reversed values unchanged.

9. Ordering-only weakness

Problem: Analyze the synthetic ordering-only weakness scenario and derive its expected result or oracle limit.

  1. An empty sequence has no adjacent out-of-order pair.
  2. It omits both input values and therefore violates multiset preservation.
text Synthetic scenario, not an execution record
input=[2, 1]; proposed output=[]
assertion: output is ascending

The hypothetical fixture supplies the input and rule for independent derivation.

Expected result: Ordering assertion passes; preservation must fail.

Why this result follows: A vacuously ordered result can still be completely wrong for a nonempty input.

10. Preservation-only weakness

Problem: Analyze the synthetic preservation-only weakness scenario and derive its expected result or oracle limit.

  1. Both values occur once in both sequences.
  2. Two appears before the smaller one, so the result is not ascending.
text Synthetic scenario, not an execution record
input=[2, 1]; proposed output=[2, 1]
assertion: same multiset

The hypothetical fixture supplies the input and rule for independent derivation.

Expected result: Preservation passes; ascending-order assertion must fail.

Why this result follows: A multiset check alone cannot determine whether a sequence was sorted. This conclusion follows from the stated rule and input.

11. Dropped duplicate

Problem: Analyze the synthetic dropped duplicate scenario and derive its expected result or oracle limit.

  1. The proposed output is ascending.
  2. It contains only one occurrence of two although the input contains two.
text Synthetic scenario, not an execution record
input=[2, 1, 2]; proposed output=[1, 2]
rule: retain occurrences

The hypothetical fixture supplies the input and rule for independent derivation.

Expected result: Reject proposed output; expected [1, 2, 2].

Why this result follows: Count preservation catches a sorted result that silently drops a duplicate. This conclusion follows from the stated rule and input.

12. Extra value

Problem: Analyze the synthetic extra value scenario and derive its expected result or oracle limit.

  1. The proposed output is ascending but introduces two.
  2. The input contains no occurrence of that value.
text Synthetic scenario, not an execution record
input=[1, 3]; proposed output=[1, 2, 3]
rule: preserve multiset

The hypothetical fixture supplies the input and rule for independent derivation.

Expected result: Reject proposed output; expected [1, 3].

Why this result follows: Preservation checks additions as well as losses from the original input. This conclusion follows from the stated rule and input.

13. Descending defect

Problem: Analyze the synthetic descending defect scenario and derive its expected result or oracle limit.

  1. The proposed output preserves all input values.
  2. Its adjacent values descend rather than follow the required ascending order.
text Synthetic scenario, not an execution record
input=[1, 3, 2]; proposed output=[3, 2, 1]
rule: ascending

The hypothetical fixture supplies the input and rule for independent derivation.

Expected result: Reject proposed output; expected [1, 2, 3].

Why this result follows: Order and preservation assertions catch different classes of wrong output. This conclusion follows from the stated rule and input.

14. Text versus numeric

Problem: Analyze the synthetic text versus numeric scenario and derive its expected result or oracle limit.

  1. The inputs are strings, not the numeric values 10 and 2.
  2. Numeric and lexicographic ordering can produce different sequences.
text Synthetic scenario, not an execution record
input=["10", "2"]
contract: text comparison unspecified

The hypothetical fixture supplies the input and rule for independent derivation.

Expected result: Ask the owner for the string comparison rule.

Why this result follows: An independent oracle cannot be derived until the applicable comparison is agreed.

15. Missing value unspecified

Problem: Analyze the synthetic missing value unspecified scenario and derive its expected result or oracle limit.

  1. The numeric rule describes ordering numbers.
  2. It does not say whether null is rejected or where it belongs.
text Synthetic scenario, not an execution record
input=[1, null, 2]
contract: null handling unspecified

The hypothetical fixture supplies the input and rule for independent derivation.

Expected result: Expected outcome is unresolved.

Why this result follows: Explicit uncertainty prevents an implementation choice from becoming an invented requirement. This conclusion follows from the stated rule and input.

16. Stable equal keys

Problem: Analyze the synthetic stable equal keys scenario and derive its expected result or oracle limit.

  1. The key 1 record comes before key 2 records.
  2. Among equal key 2 records, A preceded C and must remain first.
text Synthetic scenario, not an execution record
rule: ascending key; preserve relative order of equal keys
input=[(2,A), (1,B), (2,C)]

The hypothetical fixture supplies the input and rule for independent derivation.

Expected result: Expected [(1,B), (2,A), (2,C)].

Why this result follows: Identifiers reveal a stability failure that comparing only numeric keys would miss.

17. Input mutation

Problem: Analyze the synthetic input mutation scenario and derive its expected result or oracle limit.

  1. The returned sequence is correctly sorted.
  2. The original input changed even though the stated contract prohibits mutation.
text Synthetic scenario, not an execution record
rule: return sorted copy; do not mutate input
input before=[2, 1]; output=[1, 2]; input after=[1, 2]

The hypothetical fixture supplies the input and rule for independent derivation.

Expected result: Output order matches; input mutation violates the rule.

Why this result follows: A separate before-and-after observation checks an obligation beyond output order. This conclusion follows from the stated rule and input.

18. Mutation unspecified

Problem: Analyze the synthetic mutation unspecified scenario and derive its expected result or oracle limit.

  1. The input changed in the synthetic observation.
  2. The stated rule does not promise that the original remains unchanged.
text Synthetic scenario, not an execution record
rule: output ascending; mutation policy unspecified
input before=[2, 1]; input after=[1, 2]

The hypothetical fixture supplies the input and rule for independent derivation.

Expected result: Do not call mutation a defect without an agreed policy.

Why this result follows: A plausible preference is not an authorized oracle for input mutation. This conclusion follows from the stated rule and input.

19. Changed order rule

Problem: Analyze the synthetic changed order rule scenario and derive its expected result or oracle limit.

  1. Under descending order three precedes two and one.
  2. The same input had a different expected sequence under the old rule.
text Synthetic scenario, not an execution record
old rule: ascending; new rule: descending
input=[1, 3, 2]

The hypothetical fixture supplies the input and rule for independent derivation.

Expected result: New expected output is [3, 2, 1].

Why this result follows: A versioned oracle must be recomputed when the governing comparison changes. This conclusion follows from the stated rule and input.

20. Scope of a pure check

Problem: Analyze the synthetic scope of a pure check scenario and derive its expected result or oracle limit.

  1. The observed output matches the independent expected sequence for the stated input.
  2. No evidence is provided for the catalog interface or other inputs.
text Synthetic scenario, not an execution record
pure function input=[2, 1]; output=[1, 2]
catalog filtering and display=not checked

The hypothetical fixture supplies the input and rule for independent derivation.

Expected result: The result supports this function case only.

Why this result follows: A bounded claim prevents a local calculation from being mistaken for end-to-end proof.

Common errors and fixes

Copying the actual output into the expected value

Why it happens
The implementation becomes its own oracle.
How to fix it
Derive the result from the approved rule independently.
Prevent it next time
Review expected values before running the implementation.

Checking only that the result is ordered

Why it happens
Ordering does not prove values and duplicates were retained.
How to fix it
Also compare the multiset or complete expected sequence.
Prevent it next time
List plausible wrong behaviors while designing assertions.

Treating three examples as exhaustive

Why it happens
Small examples are confused with the full input space.
How to fix it
State the tested inputs and investigate relevant boundaries.
Prevent it next time
Review assumptions and gaps with the rule owner.

20 practice exercises

1. For [2, 1, 2], calculate the expected result and explain one defect the example can reveal.

Show hint

Order values and count every occurrence.

Show worked solution

The result is [1, 2, 2]. It reveals an implementation that removes duplicates, provided the complete sequence or value counts are checked.

Under ascending order 1 comes first and both occurrences of 2 remain, giving [1, 2, 2]. The example detects dropped duplicates when the complete sequence or counts are compared; ordering alone would incorrectly accept [1, 2].

Check your solution

  • Expected output is [1, 2, 2].
  • Both occurrences of 2 are preserved.

2. A function returns [] for every input and passes an ordering assertion. What additional check is needed?

Show hint

Compare the output multiset with the nonempty input.

Show worked solution

Check that the output contains the same values with the same counts as the input. For [2, 1], the empty result violates preservation even though it is trivially ordered.

The empty list can satisfy an ordering check because it has no out-of-order pair. It does not preserve either value of [2, 1]; add a multiset assertion or compare the independently derived complete output [1, 2].

Check your solution

  • [] does not preserve 1 and 2.
  • The complete expected output is [1, 2].

3. Under ascending numeric order with duplicates retained, calculate the complete result for [5, 2, 5].

Show hint

Order values and count both fives.

Show worked solution

The expected output is [2, 5, 5]: two is smallest and both occurrences of five remain. Compare the complete sequence rather than checking order alone. A sorted result of [2, 5] would miss one occurrence and violate the preservation rule.

Check your solution

  • Expected sequence is [2, 5, 5]
  • Both occurrences of 5 remain

4. A sorter returns its input unchanged. Choose an input that exposes it and derive the expected output.

Show hint

An already sorted input will not distinguish it.

Show worked solution

Use the unsorted input [3, 1] and independently expect [1, 3]. The return-input implementation produces [3, 1], which preserves both values but is not ascending. Record this as a planned counterexample unless the behavior was actually observed in a run.

Check your solution

  • Input is unsorted
  • Expected sequence is [1, 3]

5. A function returns [] for input [3, 1]. Explain why an ordering assertion is insufficient and add a check.

Show hint

Empty output has no out-of-order pair.

Show worked solution

The empty output satisfies a simple adjacent-order property vacuously, but it omits both input values. Add a multiset-preservation assertion or compare the complete expected output [1, 3]. This distinguishes the empty result without claiming that every possible input is covered.

Check your solution

  • Empty output is ordered
  • Preservation fails for [3, 1]

6. A result [1, 2] is returned for [2, 1, 2]. Determine which property fails.

Show hint

Count occurrences, not just distinct values.

Show worked solution

The output is ascending, but it contains one occurrence of 2 while the input contains two. Multiset preservation fails and the exact expected result is [1, 2, 2]. Checking only distinct membership or order would miss the dropped duplicate.

Check your solution

  • Order passes
  • Count of 2 is incorrect

7. The sorter returns [1, 2, 3] for input [3, 1]. Assess order and preservation independently.

Show hint

Look for values introduced by the result.

Show worked solution

The result is ascending but introduces 2, which was not in the input. The preservation property fails even though no original value is missing. The independently expected result is [1, 3], so a complete-sequence assertion also detects the extra value.

Check your solution

  • Order passes
  • Extra 2 violates preservation

8. Given numeric ascending order, derive the expected result for [-1, 2, 0] and state the domain assumption.

Show hint

Compare negative, zero, and positive values.

Show worked solution

The expected sequence is [-1, 0, 2] because negative one is less than zero and zero is less than two. This expectation assumes the agreed numeric domain permits negative values. If negatives are excluded, ask for the rejection rule instead of applying this oracle.

Check your solution

  • Expected order is [-1, 0, 2]
  • Negative values must be allowed

9. A function is tested only with [1, 2, 3]. Name a wrong implementation that passes and a contrasting case.

Show hint

Consider an implementation that does no work.

Show worked solution

A function that returns its input unchanged passes the already sorted example. Add [3, 2, 1] with independently expected [1, 2, 3]; the unchanged result then fails the order assertion. Retain the original case too if the contract expects already sorted inputs to remain correct.

Check your solution

  • Return-input passes the original case
  • Descending input exposes it

10. The contract says sort numbers but does not define null. What should be expected for [1, null]?

Show hint

Do not invent null ordering.

Show worked solution

The expected outcome is unresolved: the contract does not say whether null is invalid or where it belongs. Ask the rule owner and document the decision before writing an assertion. Record [1, null] as a proposed case, not a passing or failing test.

Check your solution

  • Null behavior is unresolved
  • Owner supplies the missing rule

11. A list of strings contains "10" and "2". Explain why numeric ordering cannot be assumed.

Show hint

Representation affects comparison.

Show worked solution

The values are strings, and a text comparison can order them differently from the numeric values 10 and 2. Ask which comparison and conversion the contract requires before deriving an expected sequence. Do not silently parse the strings merely to reuse a numeric oracle.

Check your solution

  • Inputs are strings
  • Comparison policy must be agreed

12. A stable ascending-key sort receives [(2,A), (1,B), (2,C)]. Derive the output and explain stability.

Show hint

Keep equal keys in their original relative order.

Show worked solution

The expected result is [(1,B), (2,A), (2,C)]: key 1 precedes key 2, and A remains before C among equal key 2 records. Comparing keys alone would miss a swap of A and C, so retain identifiers in the assertion.

Check your solution

  • B comes first
  • A remains before C

13. A function promises a sorted copy without mutating its input. Design observations for [3, 1].

Show hint

Observe both output and original.

Show worked solution

Preserve a copy of [3, 1] before the call. Expect returned output [1, 3] and original input still [3, 1] afterward. These are separate assertions: the output can be correctly sorted while the function still violates the no-mutation promise.

Check your solution

  • Output is [1, 3]
  • Original remains [3, 1]

14. The contract specifies only ascending output; the function mutates its input. Can that alone be reported as a defect?

Show hint

Check whether mutation is prohibited.

Show worked solution

The observed mutation is real in this hypothetical case, but the stated contract does not prohibit it. Ask the owner whether callers require a sorted copy or permit in-place sorting before judging it a defect. Record the observation and missing rule separately from the output-order result.

Check your solution

  • Mutation is observed
  • No-mutation rule is not stated

15. The rule changes from ascending to descending. Recompute the result for [2, 4, 2].

Show hint

Preserve duplicate counts under the new order.

Show worked solution

The new expected result is [4, 2, 2], because four comes first in descending order and both twos remain. Update the linked rule revision and rationale rather than copying the implementation’s new output. Review other cases, including those whose expected sequence does not change.

Check your solution

  • Expected output is [4, 2, 2]
  • Both twos remain

16. A proposed output [1, 1, 3] is compared with input [3, 1, 1]. Which two properties hold?

Show hint

Check neighboring order and counts.

Show worked solution

The output is ascending because 1 is no greater than 1 and 3. It also preserves one 3 and two occurrences of 1, matching the input. For this specific example both properties hold, but that result does not establish correctness for other inputs or representations.

Check your solution

  • Ascending order holds
  • Counts match the input

17. A sorter returns [3, 2, 1] for input [1, 2, 3]. Identify the failing and passing properties.

Show hint

Separate order from the multiset.

Show worked solution

The output contains each input value exactly once, so preservation holds. It is descending rather than ascending, so the ordering property fails. The expected complete output under the stated rule is [1, 2, 3]; the two checks reveal different facts about the same result.

Check your solution

  • Preservation holds
  • Ascending order fails

18. A reviewer calculates [1, 2, 2] for [2, 1, 2] while another proposes [1, 2]. How should they resolve it?

Show hint

Return to the agreed duplicate rule.

Show worked solution

Consult the agreed rule that retains every occurrence and count the input values independently. There are two occurrences of 2, so [1, 2, 2] is correct and [1, 2] loses one. Record the reasoning and rule version; do not choose whichever output the implementation currently returns.

Check your solution

  • Two occurrences of 2 are counted
  • Rule version and derivation are recorded

19. A function case passes for [2, 1], but a catalog screen has not been tested. Write a bounded claim.

Show hint

Name the observed scope.

Show worked solution

If the observed function output is [1, 2], report that the pure sorting case matches the ascending rule for [2, 1] on the recorded build. Do not claim that catalog filtering, display, or persistence works; those layers and other inputs need separate evidence.

Check your solution

  • Claim names the function input
  • Catalog interface remains untested

20. You prepared expected results for empty and duplicate inputs but have not run them. How should the report describe them?

Show hint

A derived oracle is not an execution result.

Show worked solution

List the independently derived expected outputs and label both cases planned or not executed. State the rule version and the intended environment, then record actual outputs only after execution. Reviewed examples improve test design but do not constitute passing evidence by themselves.

Check your solution

  • Both cases are planned
  • No passing execution is claimed

Key takeaways

  • Derive expected results independently from an agreed rule.
  • Use complementary assertions and disclose untested cases.
  • Compute expected results from the rule rather than copying the implementation.
  • Order and multiset preservation are complementary properties.
  • A planned example or passing function case does not prove the whole interface.

Official references