Skip to content

Instantly share code, notes, and snippets.

@hibri
Created February 18, 2021 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hibri/815325c7c52c280a5bcd906631d114bb to your computer and use it in GitHub Desktop.
Save hibri/815325c7c52c280a5bcd906631d114bb to your computer and use it in GitHub Desktop.
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