mirror of
https://github.com/rwinkhart/convertroman.git
synced 2026-08-28 04:46:32 -04:00
added examples
This commit is contained in:
@@ -1 +1,21 @@
|
||||
# Go Roman Numerals
|
||||
|
||||
Convert to and from roman numerals in Go.
|
||||
|
||||
```go
|
||||
func ExampleToInt() {
|
||||
integer, err := ToInt("IV")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(integer == 4)
|
||||
}
|
||||
|
||||
func ExampleFromInt() {
|
||||
roman, err := FromInt(4)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(roman == "IV")
|
||||
}
|
||||
```
|
||||
|
||||
+18
-1
@@ -1,6 +1,7 @@
|
||||
package romannumeral
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -45,7 +46,7 @@ func TestFromInt(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestToInteger(t *testing.T) {
|
||||
func TestToInt(t *testing.T) {
|
||||
for input, expected := range testCases {
|
||||
out, err := ToInt(input)
|
||||
if err != nil {
|
||||
@@ -72,3 +73,19 @@ func BenchmarkToInteger(b *testing.B) {
|
||||
_, _ = ToInt("DCCCXLIX")
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleToInt() {
|
||||
integer, err := ToInt("IV")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(integer == 4)
|
||||
}
|
||||
|
||||
func ExampleFromInt() {
|
||||
roman, err := FromInt(4)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(roman == "IV")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user