Add Welsh

This commit is contained in:
Oliver Davies 2022-01-27 00:11:38 +00:00
parent d4bc9ae15f
commit a92fffd81e
2 changed files with 15 additions and 4 deletions

View file

@ -4,14 +4,18 @@ import "fmt"
const englishHelloPrefix = "Hello, " const englishHelloPrefix = "Hello, "
func Hello(name string) string { func Hello(name string, language string) string {
if name == "" { if name == "" {
name = "World" name = "World"
} }
if language == "Welsh" {
return "Helo, " + name
}
return englishHelloPrefix + name return englishHelloPrefix + name
} }
func main() { func main() {
fmt.Println(Hello("Oliver")) fmt.Println(Hello("Oliver", ""))
} }

View file

@ -12,16 +12,23 @@ func TestHello(t *testing.T) {
} }
t.Run("saying hello to people", func (t *testing.T) { t.Run("saying hello to people", func (t *testing.T) {
got := Hello("Oliver") got := Hello("Oliver", "")
want := "Hello, Oliver" want := "Hello, Oliver"
assertCorrectMessage(t, got, want) assertCorrectMessage(t, got, want)
}) })
t.Run("say 'Hello, World' when an empty string is supplied", func (t *testing.T) { t.Run("say 'Hello, World' when an empty string is supplied", func (t *testing.T) {
got := Hello("") got := Hello("", "")
want := "Hello, World" want := "Hello, World"
assertCorrectMessage(t, got, want) assertCorrectMessage(t, got, want)
}) })
t.Run("in Welsh", func (t *testing.T) {
got := Hello("Oliver", "Welsh")
want := "Helo, Oliver"
assertCorrectMessage(t, got, want)
})
} }