Typorithm · medium

11. Combined filters and complete pagination

qatestingtest-designindependent-practice
Saved on this device
Full lesson · 3 learning steps Open any exercise for focused practice
1

Step 1 of 3 · intro card

11. Combined filters and complete pagination

0%

Concept and contract

Check the whole result set for omissions, duplicates and incorrect filter semantics.

A page can be correct in isolation while the complete traversal is wrong. Pagination checks need a known ordered dataset, a continuation rule and an expected union of ids. Counts alone cannot reveal that one record was duplicated while another was omitted.

Combined filters add another dimension: this lab requires country AND normalized title query. A test of each filter separately does not prove their conjunction. Use at least one record that matches only the country and one that matches only the query.

Mechanism and worked example

The worked fixture returns r1 for UA plus qa.

The worked fixture returns r1 for UA plus qa. A country-only implementation would also return r3; a query-only implementation would also return r4. These carefully chosen exclusions make the combined test distinguish the intended rule from plausible wrong alternatives.

For traversal, keep ordering deterministic and follow the supplied cursor until it is absent. Check uniqueness and completeness separately. This small lab uses a stable snapshot; mutable production datasets need an explicit consistency or snapshot policy.

Complete worked example

json

{
  "filters": {
    "country": "UA",
    "q": "qa"
  },
  "expectedIds": [
    "r1"
  ],
  "excludedCountryOnly": [
    "r3"
  ],
  "excludedQueryOnly": [
    "r4"
  ]
}
Reasoning
The fixture includes records that distinguish conjunction from either individual filter.

Counterexamples and common mistakes

The weak result checks only that two rows were returned.

The weak result checks only that two rows were returned. A duplicate page can satisfy that count while losing an expected id. Likewise, stopping after the first nonempty page says nothing about later matching records.

Avoid assuming a short page always means the feed is complete unless the provider’s contract says so. Follow its continuation metadata, respect rate limits and do not probe external feeds for this exercise. The companion API supplies all test data locally.

Counterexample: what this check misses

json

{
  "pages": [
    [
      "r1"
    ],
    [
      "r1"
    ]
  ],
  "assertion": "Total received count is two",
  "misses": "Duplicate r1 and missing r2"
}
Reasoning
A row count cannot establish unique complete membership.

Independent practice: small task

Fetch all local roles with page size one and collect ids in order.

Fetch all local roles with page size one and collect ids in order. Expect r1 through r4 exactly once. Then apply UA plus qa and expect only r1. Begin with the first page and inspect its next cursor before writing a traversal loop.

Record both the complete id list and its uniqueness. Optional extension: change the fixture between pages and explain why a snapshot contract matters. Do not claim the simple offset cursor solves concurrent ingestion behavior.

Step 1: Read the first page’s continuation value. Step 2: Compare the completed unique list and the combined subset.

Practice starter: solve before reading the solution

json

{
  "pageSize": 1,
  "expectedAllIds": "TODO",
  "combined": {
    "country": "UA",
    "q": "qa",
    "expectedIds": "TODO"
  }
}
Reasoning
Inspect the cursor before generalizing a traversal.
  • Hint 1: Counts can hide duplicate-and-omission pairs.
  • Hint 2: Do not send this exercise to a real feed.

Solution, tests and trade-offs

The solution names the complete expected traversal and the separate combined-filter subset.

The solution names the complete expected traversal and the separate combined-filter subset. The verifier follows local continuation metadata and rejects duplicate ids. A mutation using OR instead of AND is detected by the combined case.

A finite fixture cannot prove every provider’s pagination semantics. Its value is an explicit, reproducible contract and an independent oracle. Extend the cases when a real source has multiple locations, unstable sort keys or a different termination rule.

Practice solution and acceptance checks

json

{
  "pageSize": 1,
  "expectedAllIds": [
    "r1",
    "r2",
    "r3",
    "r4"
  ],
  "expectedUniqueCount": 4,
  "combined": {
    "country": "UA",
    "q": "qa",
    "expectedIds": [
      "r1"
    ]
  },
  "termination": "nextCursor is null"
}
Reasoning
The expected ordered ids and uniqueness are independent checks.

Interview reasoning and next step

In interviews, explain how a count can stay correct while membership is wrong.

In interviews, explain how a count can stay correct while membership is wrong. Give a concrete OR-versus-AND counterexample and describe the chosen consistency assumption. Discuss rate limiting as part of responsible traversal.

Next, use SQL fixtures to inspect stored state independently. A query can provide a useful oracle only when its schema, null behavior and expected rows are understood.

Optional stretch — after the core task works: Describe a snapshot policy for a changing dataset.

Computer practice: download the companion lab at https://applydjinn.com/typorithm/qa-lab-20261105.zip. Read its README, install the pinned tools and run the accepted examples before attempting a starter. The mobile reader preserves your reading and self-check progress; the local lab runs browser tests separately.

Check the whole result set for omissions, duplicates and incorrect filter semantics.