Refactor XOR code to use an iterator.
Refactor Gate tests.