Tests 9, 10 and 11
I add the test 9 = IX. It fails. I make it work by adding another ifelse, just like the 4. Can’t see any way to refactor it.
I add the test 10 = X. It fails. Again I add it as another ifelse, just like the 4 and 9.
Public Function i2r(i As Integer) As String
Application.Volatile
i2r = ""
If i = 4 Then
i2r = "IV"
ElseIf i = 9 Then
i2r = "IX"
ElseIf i = 10 Then
i2r = "X"
ElseIf i >= 5 Then
i2r = "V"
i = i - 5
End If
While i <= 3 And i > 0
i2r = i2r + "I"
i = i - 1
Wend
End Function
As I add the test 11 = XI, I notice the i following the x and I think about the 12 and 13. This looks like it’s the good old repeating “I” situation.
I’m tempted to add the 12 and 13 test cases in too, but I decided not to. Why? After all, it seems easy enough to do, but then I’d move into trying to make 3 tests work at once and although they’d probably work I suspect that it’s not the intention of TDD. And besides, it is easy enough to add the 12 and 13 in afterwards.
I make the 11 test work very easily
Public Function i2r(i As Integer) As String
Application.Volatile
i2r = ""
If i = 4 Then
i2r = "IV"
ElseIf i = 9 Then
i2r = "IX"
ElseIf i >= 10 Then
i2r = "X"
i = i - 10
ElseIf i >= 5 Then
i2r = "V"
i = i - 5
End If
While i <= 3 And i > 0
i2r = i2r + "I"
i = i - 1
Wend
End Function
Do you want to see what happens with Tests 12 -15? I break the code.