aboutsummaryrefslogtreecommitdiffstats
path: root/layout/math_test.go
blob: 7ff6b78599cbc2134b525951f1834eff09b80cda (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
package layout

import "testing"

func TestSum(t *testing.T) {
	t.Parallel()
	testSum(t, []int{}, 0)
	testSum(t, []int{0}, 0)
	testSum(t, []int{1}, 1)
	testSum(t, []int{12, 34}, 46)
	testSum(t, []int{12, 34, 56}, 102)
}

func testSum[N number](t *testing.T, s []N, want N) {
	n := sum(s)
	if n != want {
		t.Errorf("sum(%v) = %v; want %v", s, n, want)
	}
}