Skip to content

Commit

Permalink
Create linear_regression_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
TimLai666 committed Nov 2, 2024
1 parent 02cd3b2 commit 2e6a24b
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions stats/linear_regression_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package stats

import (
"reflect"
"testing"

"github.com/HazelnutParadise/insyra"
)

func TestLinearRegression(t *testing.T) {
dlX := insyra.NewDataList(1, 4, 9, 110, 8)
dlY := insyra.NewDataList(3, 6, 8, 6, 2)
result := LinearRegression(dlX, dlY)

var expectedValues = LinearRegressionResult{
Slope: 0.013102128241352597,
Intercept: 4.654103814428291,
RSquared: 0.06278103115648115,
PValue: 0.6843455560821862,
StandardError: 0.029227221522309617,
TValue: 0.4482851108974395,
AdjustedRSquared: -0.2496252917913584,
Residuals: []float64{-1.6672059426696437, 1.2934876726062985, 3.2279770313995355, -0.0953379209770766, -2.758920840359112},
}

if result == nil {
t.Error("LinearRegression returned nil")
} else if !reflect.DeepEqual(result, &expectedValues) {
t.Errorf("LinearRegression result mismatch: expected %v, got %v", expectedValues, result)
}
}

0 comments on commit 2e6a24b

Please sign in to comment.