Refactor test code and add self-documented names for loop count variables