Compare commits
4 Commits
3cae1bd3d7
...
3172b5db04
| Author | SHA1 | Date | |
|---|---|---|---|
| 3172b5db04 | |||
| 5ddfccf226 | |||
| 16fd3683ea | |||
| ca6357acdb |
16
hello.go
16
hello.go
@@ -1,16 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
const englishHelloPrefix = "Hello, "
|
|
||||||
|
|
||||||
func Hello(name string) string {
|
|
||||||
if name == "" {
|
|
||||||
name = "World"
|
|
||||||
}
|
|
||||||
return englishHelloPrefix + name
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.Println(Hello("Hoborg"))
|
|
||||||
}
|
|
||||||
36
hello/hello.go
Normal file
36
hello/hello.go
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
const (
|
||||||
|
spanish = "Spanish"
|
||||||
|
french = "French"
|
||||||
|
englishHelloPrefix = "Hello, "
|
||||||
|
spanishHelloPrefix = "Hola, "
|
||||||
|
frenchHelloPrefix = "Bonjour, "
|
||||||
|
)
|
||||||
|
|
||||||
|
func Hello(name, language string) string {
|
||||||
|
if name == "" {
|
||||||
|
name = "World"
|
||||||
|
}
|
||||||
|
|
||||||
|
prefix := greetingPrefix(language)
|
||||||
|
return prefix + name
|
||||||
|
}
|
||||||
|
|
||||||
|
func greetingPrefix(language string) (prefix string) {
|
||||||
|
switch language {
|
||||||
|
case french:
|
||||||
|
prefix = frenchHelloPrefix
|
||||||
|
case spanish:
|
||||||
|
prefix = spanishHelloPrefix
|
||||||
|
default:
|
||||||
|
prefix = englishHelloPrefix
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println(Hello("Hoborg", ""))
|
||||||
|
}
|
||||||
@@ -4,13 +4,23 @@ import "testing"
|
|||||||
|
|
||||||
func TestHello(t *testing.T) {
|
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("Hoborg")
|
got := Hello("Hoborg", "")
|
||||||
want := "Hello, Hoborg"
|
want := "Hello, Hoborg"
|
||||||
assertMessage(t, got, want)
|
assertMessage(t, got, want)
|
||||||
})
|
})
|
||||||
t.Run("say 'Hello, World' when an empty string is given", func(t *testing.T) {
|
t.Run("say 'Hello, World' when an empty string is given", func(t *testing.T) {
|
||||||
got := Hello("")
|
got := Hello("", "")
|
||||||
want := "Hello, Worldi"
|
want := "Hello, World"
|
||||||
|
assertMessage(t, got, want)
|
||||||
|
})
|
||||||
|
t.Run("hello in Spanish", func(t *testing.T) {
|
||||||
|
got := Hello("Elodie", "Spanish")
|
||||||
|
want := "Hola, Elodie"
|
||||||
|
assertMessage(t, got, want)
|
||||||
|
})
|
||||||
|
t.Run("hello in French", func(t *testing.T) {
|
||||||
|
got := Hello("Émile", "French")
|
||||||
|
want := "Bonjour, Émile"
|
||||||
assertMessage(t, got, want)
|
assertMessage(t, got, want)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user