# Tests 12 -15

Here's the code as it currently stands:

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

• I look to see if I can refactor anything. I can’t see anything. Hmmm ...

• I add in the 12 = XII test case. It works straight away. As does the 13 = XIII.

• I add in the 14 = XIV test case. Now the easiest way to make this test work is to put in an if i = 14 and I do this. But when I go to refactor I realise that it’s really just 10 + 4, so I move the if i =4 out of the string of if’s and move it after the 5 and between the 3 , 2 and 1 code. It should just trickle through. My tests still all run after making the change.

Public Function i2r(i As Integer) As String

Application.Volatile

i2r = ""

If 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

If i = 4 Then

i2r = i2r + "IV"

End If

While i <= 3 And i > 0

i2r = i2r + "I"

i = i - 1

Wend

End Function

• I look for ways to refactoring but I (with my limited coding ability) can’t see any that I can do with confidence.

• I add the 15 = XV test case. I’m starting to see a pattern here and I change the code easily.

Public Function i2r(i As Integer) As String

Application.Volatile

i2r = ""

If i = 9 Then

i2r = "IX"

ElseIf i >= 10 Then

i2r = "X"

i = i - 10

End If

If i >= 5 Then

i2r = "V"

i = i - 5

End If

If i = 4 Then

i2r = i2r + "IV"

End If

While i <= 3 And i > 0

i2r = i2r + "I"

i = i - 1

Wend

End Function

But 15 doesn’t work and the test for 9 breaks. Let me show you.