chore: initialize containerized Go learning workbook (2026 DevOps/SRE)
This commit is contained in:
commit
84be3e5d77
64 files changed
+1382
No files matched your search
@@ -0,0 +1,25 @@
|
||||
package generics
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMax(t *testing.T) {
|
||||
if _, ok := Max([]int{}); ok {
|
||||
t.Fatal("expected false for empty slice")
|
||||
}
|
||||
if got, ok := Max([]int{3, 9, 1, 7}); !ok || got != 9 {
|
||||
t.Fatalf("got (%d, %v), want (9, true)", got, ok)
|
||||
}
|
||||
if got, ok := Max([]string{"a", "z", "m"}); !ok || got != "z" {
|
||||
t.Fatalf("got (%q, %v), want (z, true)", got, ok)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilter(t *testing.T) {
|
||||
got := Filter([]int{1, 2, 3, 4, 5}, func(n int) bool { return n%2 == 0 })
|
||||
if !reflect.DeepEqual(got, []int{2, 4}) {
|
||||
t.Fatalf("got %v, want [2 4]", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user