SE450
:
Class Invariants
[53/57]
Example: Circular array queue
0 <= head && head < elements.length
First check it's true for constructor
Sets
head = 0
Need precondition
size > 0
!
Check mutators. Start withÂ
remove
Sets
head
new
= (head
old
+ 1) % elements.length
We know
head
old
>= 0 (Why?)
%
operator property:
0 <= head
new
&& head
new
< elements.length
What's the use? Array accesses are correct!
return elements[head];