예제 #1
0
func TestDotInt64WithDiffLength(t *testing.T) {
	N := 1000 + rand.Intn(1000000)
	M := 1000 + rand.Intn(1000000)
	a := make([]int64, N)
	b := make([]int64, M)
	Expected := int64(0)
	for i := range a {
		if i < N {
			a[i] = gomath.ScaleInt64(LowInt64, HighInt64, 0, HighInt64, rand.Int63n(HighInt64))
		}
		if i < M {
			b[i] = gomath.ScaleInt64(LowInt64, HighInt64, 0, HighInt64, rand.Int63n(HighInt64))
		}

		if i < N && i < M {
			Expected += a[i] * b[i]
		}
	}

	Computed := DotInt64(a, b)

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