Partitioning Records into Disjoint Groups

A partition places each input item into exactly one group. A grouping rule can otherwise duplicate a row across overlapping labels.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Try an overlapping assignment
  2. Verify conservation
  3. Check whether each record has exactly one destination
  4. Make the fallback rule cover every input

Try an overlapping assignment

A note tagged both home and urgent can appear in both tag groups. If the report requires each note to count once, choose one primary group per note. Overlapping conditions help expose the difference.

Verify conservation

Sum group sizes and compare with the source length under a declared one-group policy. Also test membership for a known overlapping candidate because a duplicated row and a lost row can cancel in that sum. Function invariants support checks beyond totals.[1]

Check whether each record has exactly one destination

Suppose tickets carry a priority of high or normal. Placing each ticket in its priority bucket makes disjoint groups if the input contains each ticket once and the key assignment gives exactly one result. Tags behave differently because a ticket can belong to both a photo group and a transport group. Compare the sum of bucket lengths with the input count when the intended model is a partition. See grouping records with maps.

Make the fallback rule cover every input

If priority may be absent, a residual group can preserve that ticket for later repair. Silently dropping it violates exhaustive coverage. If two rules can assign different buckets, decide which rule wins before processing. Test an ordinary record, one satisfying two rules and one satisfying none. Check bucket membership as well as sizes because moving two tickets in opposite directions leaves sizes unchanged. See exhaustive conditions.

References

  1. Python Software Foundation, Python Standard Library: Built-in Types ↩