Created
February 18, 2021 12:56
-
-
Save hibri/815325c7c52c280a5bcd906631d114bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"testing" | |
"github.com/pkg/errors" | |
"github.com/stretchr/testify/assert" | |
) | |
func TestAlwaysTrue(t *testing.T) { | |
assert.True(t, true) | |
} | |
func Test0ReturnsError(t *testing.T) { | |
_, err := convertToRomanNumeral(0) | |
assert.Error(t, err) | |
} | |
func Test1ReturnsI(t *testing.T) { | |
AssertRoman(t, "I", 1) | |
} | |
func Test2ReturnsII(t *testing.T) { | |
AssertRoman(t, "II", 2) | |
} | |
func Test3ReturnsIII(t *testing.T) { | |
AssertRoman(t, "III", 3) | |
} | |
func AssertRoman(t *testing.T, expected string, what int) { | |
numeral, _ := convertToRomanNumeral(what) | |
assert.Equal(t, expected, numeral) | |
} | |
func convertToRomanNumeral(n int) (string, error) { | |
var translate = map[int]string{ | |
1: "I", | |
2: "II", | |
3: "III", | |
} | |
if 0 == n { | |
return "", errors.New("0 invalid") | |
} | |
return translate[n], nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment