// Homework 34, problem 3: Average. // // TestOf already has a table. One row fails until you fix average.go. // // TODO: write TestOfEmpty. It calls Of with an empty slice, and uses // errors.Is to check that the error is ErrEmpty. package average import "testing" func TestOf(t *testing.T) { tests := []struct { name string numbers []int want float64 }{ {"one number", []int{7}, 7}, {"whole result", []int{2, 4, 6}, 4}, {"half result", []int{1, 2}, 1.5}, } for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { got, err := Of(tc.numbers) if err != nil { t.Fatalf("Of(%v) gave the error %v", tc.numbers, err) } if got != tc.want { t.Errorf("Of(%v) = %v, want %v", tc.numbers, got, tc.want) } }) } }