Why does it equal 4?
As far as I can see, this should be 2.
By the way, I would rather add the assert just after each change (one line 55 and the other one here).