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) } }