mirror of
https://github.com/rwinkhart/convertroman.git
synced 2026-09-03 07:37:14 -04:00
added examples
This commit is contained in:
@@ -1 +1,21 @@
|
|||||||
# Go Roman Numerals
|
# 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
|
package romannumeral
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"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 {
|
for input, expected := range testCases {
|
||||||
out, err := ToInt(input)
|
out, err := ToInt(input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -72,3 +73,19 @@ func BenchmarkToInteger(b *testing.B) {
|
|||||||
_, _ = ToInt("DCCCXLIX")
|
_, _ = 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