You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.2 KiB

package inttoroman_test
import (
"fmt"
"testing"
"git.jxs.me/leetgo/inttoroman"
"github.com/stretchr/testify/require"
)
func TestZero(t *testing.T) {
require.Equal(t, "", inttoroman.Convert(0))
}
func TestOne(t *testing.T) {
require.Equal(t, "I", inttoroman.Convert(1))
}
func TestTwo(t *testing.T) {
require.Equal(t, "II", inttoroman.Convert(2))
}
func TestFour(t *testing.T) {
require.Equal(t, "IV", inttoroman.Convert(4))
}
func TestFive(t *testing.T) {
require.Equal(t, "V", inttoroman.Convert(5))
}
func TestSix(t *testing.T) {
require.Equal(t, "VI", inttoroman.Convert(6))
}
func TestNine(t *testing.T) {
require.Equal(t, "IX", inttoroman.Convert(9))
}
func TestEleven(t *testing.T) {
require.Equal(t, "XI", inttoroman.Convert(11))
}
func TestIntToRoman(t *testing.T) {
cases := map[string]int{
"": 0,
"I": 1,
"II": 2,
"IV": 4,
"V": 5,
"IX": 9,
"X": 10,
"XX": 20,
"XII": 12,
"XL": 40,
"L": 50,
"XC": 90,
"C": 100,
"LVIII": 58,
"DCXIII": 613,
"MCMXCIV": 1994,
}
for roman, decimal := range cases {
t.Run(fmt.Sprint(decimal), func(t *testing.T) {
require.Equal(t, roman, inttoroman.Convert(decimal))
})
}
}