github.com/cybriq/giocore@v0.0.7-0.20210703034601-cfb9cb5f3900/internal/fling/extrapolation_test.go (about) 1 // SPDX-License-Identifier: Unlicense OR MIT 2 3 package fling 4 5 import "testing" 6 7 func TestDecomposeQR(t *testing.T) { 8 A := &matrix{ 9 rows: 3, cols: 3, 10 data: []float32{ 11 12, 6, -4, 12 -51, 167, 24, 13 4, -68, -41, 14 }, 15 } 16 Q, Rt, ok := decomposeQR(A) 17 if !ok { 18 t.Fatal("decomposeQR failed") 19 } 20 R := Rt.transpose() 21 QR := Q.mul(R) 22 if !A.approxEqual(QR) { 23 t.Log("A\n", A) 24 t.Log("Q\n", Q) 25 t.Log("R\n", R) 26 t.Log("QR\n", QR) 27 t.Fatal("Q*R not approximately equal to A") 28 } 29 } 30 31 func TestFit(t *testing.T) { 32 X := []float32{-1, 0, 1} 33 Y := []float32{2, 0, 2} 34 35 got, ok := polyFit(X, Y) 36 if !ok { 37 t.Fatal("polyFit failed") 38 } 39 want := coefficients{0, 0, 2} 40 if !got.approxEqual(want) { 41 t.Fatalf("polyFit: got %v want %v", got, want) 42 } 43 }