diff --git a/romannumeral.go b/romannumeral.go index 70663d1..e62023e 100644 --- a/romannumeral.go +++ b/romannumeral.go @@ -28,12 +28,18 @@ type numeral struct { // _numerals are all unique numerals ordered from largest to smallest var _numerals = []numeral{ - {1000, []byte("M")}, {900, []byte("CM")}, - {500, []byte("D")}, {400, []byte("CD")}, - {100, []byte("C")}, {90, []byte("XC")}, - {50, []byte("L")}, {40, []byte("XL")}, - {10, []byte("X")}, {9, []byte("IX")}, - {5, []byte("V")}, {4, []byte("IV")}, + {1000, []byte("M")}, + {900, []byte("CM")}, + {500, []byte("D")}, + {400, []byte("CD")}, + {100, []byte("C")}, + {90, []byte("XC")}, + {50, []byte("L")}, + {40, []byte("XL")}, + {10, []byte("X")}, + {9, []byte("IX")}, + {5, []byte("V")}, + {4, []byte("IV")}, {1, []byte("I")}, } diff --git a/romannumeral_test.go b/romannumeral_test.go index 7baa8b5..cf04ff4 100644 --- a/romannumeral_test.go +++ b/romannumeral_test.go @@ -119,9 +119,10 @@ func BenchmarkStringToInt(b *testing.B) { } func BenchmarkBytesToInt(b *testing.B) { + in := []byte("MMMCMXCIX") b.ReportAllocs() for i := 0; i < b.N; i++ { - _, _ = BytesToInt([]byte("MMMCMXCIX")) + _, _ = BytesToInt(in) } } @@ -130,7 +131,16 @@ func ExampleStringToInt() { if err != nil { panic(err) } - fmt.Println(integer == 4) + fmt.Println(integer == 4) // True +} + +func ExampleBytesToInt() { + input := []byte("IV") + integer, err := BytesToInt(input) + if err != nil { + panic(err) + } + fmt.Println(integer == 4) // True } func ExampleIntToString() { @@ -138,5 +148,5 @@ func ExampleIntToString() { if err != nil { panic(err) } - fmt.Println(roman == "IV") + fmt.Println(roman == "IV") // True }