Hello, Gofinity
Easy1 solution
- Open dcodes's solution00 votesdcodes
1 solutionby score
module gofinity/hello
go 1.24
package main
import "fmt"
func Greet(name string) string {
if name == "" {
name = "World"
}
return fmt.Sprintf("Hello, %s!", name)
}
func main() {
fmt.Println(Greet("Gofinity"))
}package main
import "testing"
func TestGreet(t *testing.T) {
tests := []struct {
name string
input string
want string
}{
{name: "a name", input: "Gofinity", want: "Hello, Gofinity!"},
{name: "another name", input: "Ada", want: "Hello, Ada!"},
{name: "empty falls back to World", input: "", want: "Hello, World!"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Greet(tt.input); got != tt.want {
t.Errorf("Greet(%q) = %q, want %q", tt.input, got, tt.want)
}
})
}
}
0 votes3 files42 lines