I tried TDD for Roman Numerals (under 40). Am I cooked? (F#)

I don't really know F# and TDD but it somehow works for numbers < 40. But I don't understand why it works. Maybe it's not working?

module RomanNumerals

let Conv5 (letters:string) = letters.Replace("IIIII", "V")

let Conv4 (letters: string) = letters.Replace("IIII", "IV")

let Conv9 (letters: string) = letters.Replace("VIV", "IX")

let Conv10 (letters: string) = letters.Replace("VV", "X")

let StrToRomanNumeral inp = Conv10 (Conv9 ( Conv4( Conv5 (String.replicate inp "I"))))

Tests: [<Fact>] let conv3 () = Assert.Equal("III", StrToRomanNumeral 3)

[<Fact>] let conv2 () = Assert.Equal("II", StrToRomanNumeral 2)

[<Fact>] let conv7 () = Assert.Equal("VII", StrToRomanNumeral 7)

[<Fact>] let conv4 () = Assert.Equal("IV", StrToRomanNumeral 4)

[<Fact>] let conv6 () = Assert.Equal("VI", StrToRomanNumeral 6)

[<Fact>] let conv8 () = Assert.Equal("VIII", StrToRomanNumeral 8)

[<Fact>] let conv9 () = Assert.Equal("IX", StrToRomanNumeral 9)

[<Fact>] let conv10 () = Assert.Equal("X", StrToRomanNumeral 10)

[<Fact>] let conv21 () = Assert.Equal("XXI", StrToRomanNumeral 21)

[<Fact>] let conv35 () = Assert.Equal("XXXV", StrToRomanNumeral 35)

[<Fact>] let conv29 () = Assert.Equal("XXIX", StrToRomanNumeral 29)

Posted Apr 8, 2025, 9:22 PM UTC

04
Loading comments…