Replace `if` invariant tests with assertions.