Reading Equality Checks and Updates
An assignment changes a binding. An equality expression produces a truth value that can guide a later decision.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 2 min
In this article4 chapters
Use both operations in context
With count = 3, evaluating count == 3 gives True and leaves the binding as it was. Evaluating count == 4 gives False. A language may allow assignment and comparison in related syntactic positions, so inspect the actual operator. A program trace can put truth values in a separate column from the updated data.
Follow the expected state transition
A retry counter equal to two becomes three after incrementing. Comparing it with three before the increment reports false, and comparing it afterward reports true. Choose which check expresses the intended rule about trying again, and cover that point with a boundary test.[1][2]
Record the value read by the decision
A counter for completed tasks can be two just before a third completion. An equality test against three then evaluates false. After the update it evaluates true. A statement saving the Boolean before the increment can preserve that earlier false value as an observation, even though the count changes after it. To trace the program, write separate columns for the numeric count and the result of the comparison. See program state by hand.
Now suppose an interface needs to emit exactly one alert when completion first reaches three. A comparison after every update can work if counts advance one at a time and only once per completion. If a bulk update can advance from two to four, equality after that update misses the crossing. Checking both the prior and new relation to the threshold expresses that different requirement.
Check what the operator means to the language
Python ordinary assignment targets a location and does not produce an equality result. The equality operator asks a question under the type's comparison rules. A list equality test can succeed on two separate lists with the same values. An identity test asks whether they refer to one object. Object identity and equality covers that distinction.
In a review, select examples that can distinguish checking before and after the change, including the last value below a threshold. If an action can be repeated, check its effects too. A false report and an unintended update are different defects.