floats: Implement ScaleTo (#765)

Fixes #737
This commit is contained in:
Brendan Tracey
2018-12-14 18:46:30 +00:00
committed by GitHub
parent 9d66d7e8f5
commit 004553317c
2 changed files with 27 additions and 0 deletions

View File

@@ -1341,6 +1341,22 @@ func TestScale(t *testing.T) {
areSlicesEqual(t, truth, s, "Bad scaling")
}
func TestScaleTo(t *testing.T) {
s := []float64{3, 4, 1, 7, 5}
sCopy := make([]float64, len(s))
copy(sCopy, s)
c := 5.0
truth := []float64{15, 20, 5, 35, 25}
dst := make([]float64, len(s))
ScaleTo(dst, c, s)
if !Same(dst, truth) {
t.Errorf("Scale to does not match. Got %v, want %v", dst, truth)
}
if !Same(s, sCopy) {
t.Errorf("Source modified during call. Got %v, want %v", s, sCopy)
}
}
func TestSpan(t *testing.T) {
receiver1 := make([]float64, 5)
truth := []float64{1, 2, 3, 4, 5}