From 43212f871fb8b1f812e08b94587058ac107df966 Mon Sep 17 00:00:00 2001 From: Will Charczuk Date: Wed, 26 Apr 2017 00:27:11 -0700 Subject: [PATCH] poly tests! --- polynomial_regression_test.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 polynomial_regression_test.go diff --git a/polynomial_regression_test.go b/polynomial_regression_test.go new file mode 100644 index 0000000..cde86d0 --- /dev/null +++ b/polynomial_regression_test.go @@ -0,0 +1,35 @@ +package chart + +import ( + "testing" + + assert "github.com/blendlabs/go-assert" + "github.com/wcharczuk/go-chart/matrix" +) + +func TestPolynomialRegression(t *testing.T) { + assert := assert.New(t) + + var xv []float64 + var yv []float64 + + for i := 0; i < 100; i++ { + xv = append(xv, float64(i)) + yv = append(yv, float64(i*i)) + } + + values := ContinuousSeries{ + XValues: xv, + YValues: yv, + } + + poly := &PolynomialRegressionSeries{ + InnerSeries: values, + Degree: 2, + } + + for i := 0; i < 100; i++ { + _, y := poly.GetValue(i) + assert.InDelta(float64(i*i), y, matrix.DefaultEpsilon) + } +}