diff --git a/README.md b/README.md index 2ce280b..0cad8f3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This package was adapted from [romannumeral](https://github.com/brandenc40/romannumeral) to fit my specific minimal use-case. -All functionality except for the ability to convert integers to roman numerals has been removed. +All functionality except for the ability to convert integers to **lowercase** roman numerals has been removed. If you need any additional functionality or further documentation, please see the original package. @@ -13,9 +13,9 @@ goos: linux goarch: amd64 pkg: github.com/rwinkhart/convertroman cpu: AMD Ryzen 9 3900X 12-Core Processor -BenchmarkFromInt-24 62046414 21.08 ns/op 0 B/op 0 allocs/op +BenchmarkFromInt-24 61993154 20.82 ns/op 0 B/op 0 allocs/op PASS -ok github.com/rwinkhart/convertroman 1.332s +ok github.com/rwinkhart/convertroman 1.827s ``` ### Example @@ -29,9 +29,9 @@ import ( ) func ExampleFromInt() { - roman, err := rom.FromInt(4) - if err != nil { - panic(err) + roman := FromInt(4) + if roman == "OOB" { + panic("Input integer is out of bounds") } fmt.Println(roman == "IV") // True } diff --git a/convertroman.go b/convertroman.go index ed96903..3fdc8af 100644 --- a/convertroman.go +++ b/convertroman.go @@ -7,10 +7,10 @@ package convertroman var ( // lookup arrays used for converting from an int to a roman numeral extremely quickly. // method from here: https://rosettacode.org/wiki/Roman_numerals/Encode#Go - r0 = [10]string{"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"} - r1 = [10]string{"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"} - r2 = [10]string{"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"} - r3 = [4]string{"", "M", "MM", "MMM"} + r0 = [10]string{"", "i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix"} + r1 = [10]string{"", "x", "xx", "xxx", "xl", "l", "lx", "lxx", "lxxx", "xc"} + r2 = [10]string{"", "c", "cc", "ccc", "cd", "d", "dc", "dcc", "dccc", "cm"} + r3 = [4]string{"", "m", "mm", "mmm"} ) // FromInt converts an integer value to a roman numeral string. diff --git a/convertroman_test.go b/convertroman_test.go index 861d948..ecf859c 100644 --- a/convertroman_test.go +++ b/convertroman_test.go @@ -6,22 +6,22 @@ import ( ) var testCases = map[string]int{ - "I": 1, "II": 2, "III": 3, "IV": 4, "V": 5, "VI": 6, - "VII": 7, "VIII": 8, "IX": 9, "X": 10, "XI": 11, "XII": 12, - "XIII": 13, "XIV": 14, "XV": 15, "XVI": 16, "XVII": 17, - "XVIII": 18, "XIX": 19, "XX": 20, "XXXI": 31, "XXXII": 32, - "XXXIII": 33, "XXXIV": 34, "XXXV": 35, "XXXVI": 36, "XXXVII": 37, - "XXXVIII": 38, "XXXIX": 39, "XL": 40, "XLI": 41, "XLII": 42, - "XLIII": 43, "XLIV": 44, "XLV": 45, "XLVI": 46, "XLVII": 47, - "XLVIII": 48, "XLIX": 49, "L": 50, "LXXXIX": 89, "XC": 90, - "XCI": 91, "XCII": 92, "XCIII": 93, "XCIV": 94, "XCV": 95, - "XCVI": 96, "XCVII": 97, "XCVIII": 98, "XCIX": 99, "C": 100, - "CI": 101, "CII": 102, "CIII": 103, "CIV": 104, "CV": 105, - "CVI": 106, "CVII": 107, "CVIII": 108, "CIX": 109, "CXLIX": 149, - "CCCXLIX": 349, "CDLVI": 456, "D": 500, "DCIV": 604, "DCCLXXXIX": 789, - "DCCCXLIX": 849, "CMIV": 904, "M": 1000, "MVII": 1007, "MLXVI": 1066, - "MCCXXXIV": 1234, "MDCCLXXVI": 1776, "MMXXI": 2021, "MMDCCCVI": 2806, - "MMCMXCIX": 2999, "MMM": 3000, "MMMCMLXXIX": 3979, "MMMCMXCIX": 3999, + "i": 1, "ii": 2, "iii": 3, "iv": 4, "v": 5, "vi": 6, + "vii": 7, "viii": 8, "ix": 9, "x": 10, "xi": 11, "xii": 12, + "xiii": 13, "xiv": 14, "xv": 15, "xvi": 16, "xvii": 17, + "xviii": 18, "xix": 19, "xx": 20, "xxxi": 31, "xxxii": 32, + "xxxiii": 33, "xxxiv": 34, "xxxv": 35, "xxxvi": 36, "xxxvii": 37, + "xxxviii": 38, "xxxix": 39, "xl": 40, "xli": 41, "xlii": 42, + "xliii": 43, "xliv": 44, "xlv": 45, "xlvi": 46, "xlvii": 47, + "xlviii": 48, "xlix": 49, "l": 50, "lxxxix": 89, "xc": 90, + "xci": 91, "xcii": 92, "xciii": 93, "xciv": 94, "xcv": 95, + "xcvi": 96, "xcvii": 97, "xcviii": 98, "xcix": 99, "c": 100, + "ci": 101, "cii": 102, "ciii": 103, "civ": 104, "cv": 105, + "cvi": 106, "cvii": 107, "cviii": 108, "cix": 109, "cxlix": 149, + "cccxlix": 349, "cdlvi": 456, "d": 500, "dciv": 604, "dcclxxxix": 789, + "dcccxlix": 849, "cmiv": 904, "m": 1000, "mvii": 1007, "mlxvi": 1066, + "mccxxxiv": 1234, "mdcclxxvi": 1776, "mmxxi": 2021, "mmdcccvi": 2806, + "mmcmxcix": 2999, "mmm": 3000, "mmmcmlxxix": 3979, "mmmcmxcix": 3999, } func TestFromInt(t *testing.T) {