Exemple #1
0
func TestDotFloat64WithSameLength(t *testing.T) {
	N := 500000

	a := genFloat64Array(N, LowFloat64, HighFloat64)
	b := genFloat64Array(N, LowFloat64, HighFloat64)

	Expected := 0.0
	for i := range a {
		Expected += a[i] * b[i]
	}

	computed := DotFloat64(a, b)

	if gomath.AbsFloat64(computed-Expected) < LowFloat64 {
		t.Logf("Expected %f but computed %f\n", Expected, computed)
		t.FailNow()
	}

}
Exemple #2
0
func TestDotFloat64WithDiffLength(t *testing.T) {
	N := 1000 + rand.Intn(1000000)
	M := 1000 + rand.Intn(1000000)
	if N == M {
		N++
	}
	a := genFloat64Array(N, LowFloat64, HighFloat64)
	b := genFloat64Array(M, LowFloat64, HighFloat64)
	Expected := 0.0
	for i := range a {
		if i < N && i < M {
			Expected += a[i] * b[i]
		} else {
			break
		}
	}

	computed := DotFloat64(a, b)

	if gomath.AbsFloat64(computed-Expected) < LowFloat64 {
		t.Logf("Expected %f but computed %f\n", Expected, computed)
		t.FailNow()
	}
}