Ooops ... I've broken the tests
When I look back at the code I realise that I’ve done two things wrong.
First, the loop should be <= 3, not < 3. I change that, recalc the tests and 3 is fixed.
But what about 4 – 8? They’re still broken. And, no wonder, the i2r = “” before the loop destroys them.
I fix the code for the current tests by moving i2r= “” to the top of the code.
When I recalc the spreadsheet … all of the tests work! The tests are very comforting … a safety net.
Public Function i2r(i As Integer) As String
Application.Volatile
i2r = ""
If i = 4 Then
i2r = "IV"
ElseIf i = 5 Then
i2r = "V"
ElseIf i = 6 Then
i2r = "VI"
ElseIf i = 7 Then
i2r = "VII"
ElseIf i = 8 Then
i2r = "VIII"
End If
While i <= 3 And i > 0
i2r = i2r + "I"
i = i - 1
Wend
End Function
So. The 2nd Refactoring. Hmmm. I want to change the code so that 6, 7, and 8 are 5 + 1, 2, or 3.