Learning GO

This commit is contained in:
Zakaria
2026-08-31 14:57:35 -04:00
commit d307eb2698
19 changed files with 310 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
package main
import (
"fmt"
"hello"
"os"
)
func main() {
fmt.Println(hello.Say(os.Args[1:]))
}
+3
View File
@@ -0,0 +1,3 @@
module hello
go 1.26.5
+13
View File
@@ -0,0 +1,13 @@
package hello
import (
"strings"
)
func Say(names []string) string {
if len(names) == 0 {
names = []string{"world"}
}
return "Hello, " + strings.Join(names, ", ") + "!"
}
+30
View File
@@ -0,0 +1,30 @@
package hello
import (
"testing"
)
func TestSayHello(t *testing.T) {
subtests := []struct {
items []string
result string
}{
{
result: "Hello, world!",
},
{
items: []string{"Leena"},
result: "Hello, Leena!",
},
{
items: []string{"Zack", "Sami", "Sara"},
result: "Hello, Zack, Sami, Sara!",
},
}
for _, st := range subtests {
if s := Say(st.items); s != st.result {
t.Errorf("wanted %s (%v), got %s", st.result, st.items, s)
}
}
}