Inclusive and Exclusive Comparison Boundaries

Whether a comparison includes an endpoint can decide which quantities are admitted and whether two categories overlap.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
2 min
In this article4 chapters
  1. State the half-open rule
  2. Check three neighbors
  3. Model a range by the boundaries a reader sees
  4. Choose adjacent tests to distinguish the inequalities

State the half-open rule

A venue can admit a ticket if its seat number is at least 1 and at most 120. Both endpoints are valid. For a zero-indexed row of 120 items, the upper bound is excluded because the final offset is 119. The index convention determines which comparison matches.

Check three neighbors

For “free shipping on 50 or more,” try 49, 50, and 51 in the same unit. Only the middle input distinguishes inclusive and exclusive tests while the neighbors verify which side is eligible. This forms a basic set of boundary test cases.[1][2]

Model a range by the boundaries a reader sees

A series of numbered slots starts at 0 and uses ten possible positions. The valid indices are exactly \(0\le i<10\). A label displayed to a customer can instead read seat 1 through seat 10. Validate the label using inclusive endpoints and subtract one when converting it into an array offset. Applying the array rule directly to the ticket label would allow zero and exclude ten. Zero-based indexing explains where the two conventions meet.

Choose adjacent tests to distinguish the inequalities

For a delivery fee waived at fifty credits, test 49, 50, and 51 under the actual numeric unit. A “greater than” check and an “at least” check agree at 49 and 51, so the exact threshold is essential. For time intervals a half-open rule can put midnight into one day without including it in the day before. Use the correct date and time zone before comparing. See date conditions. If fractional quantities are allowed, choose an adjacent representable or meaningful increment for the domain. Record that unit and scale rather than assuming every comparison changes at the nearest integer.

References

  1. Python Software Foundation, Python Tutorial: Control Flow ↩
  2. Python Software Foundation, Python Language Reference: Expressions ↩