예제 #1
0
func TestDotInt32WithDiffLength(t *testing.T) {
	N := 1000 + rand.Intn(1000000)
	M := 1000 + rand.Intn(1000000)
	a := make([]int32, N)
	b := make([]int32, M)
	expected64 := int64(0)
	for i := range a {
		if i < N {
			a[i] = gomath.ScaleInt32(LowInt32, HighInt32, 0, HighInt32, rand.Int31n(HighInt32))
		}
		if i < M {
			b[i] = gomath.ScaleInt32(LowInt32, HighInt32, 0, HighInt32, rand.Int31n(HighInt32))
		}

		if i < N && i < M {
			expected64 += int64(a[i]) * int64(b[i])
		}
	}

	Expected := int32(expected64)
	Computed := DotInt32(a, b)

	if Computed != Expected {
		t.Logf("Expected %d but computed %d\n", Expected, Computed)
		t.FailNow()
	}
}
예제 #2
0
func genInt32Array(n int, min, max int32) []int32 {
	A := make([]int32, n)
	for i := 0; i < n; i++ {
		A[i] = gomath.ScaleInt32(min, max, 0, 1, rand.Int31())
	}
	return A
}