|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package govector
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"math"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
@ -648,3 +649,67 @@ func TestExtrapolate(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestNeville(t *testing.T) {
|
|
|
|
|
knownFails := []struct {
|
|
|
|
|
points []Point2d
|
|
|
|
|
ts []float64
|
|
|
|
|
t float64
|
|
|
|
|
expected Point2d
|
|
|
|
|
err error
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
points: []Point2d{
|
|
|
|
|
{0, 0},
|
|
|
|
|
{1, 1},
|
|
|
|
|
{2, 2},
|
|
|
|
|
},
|
|
|
|
|
ts: []float64{
|
|
|
|
|
1.0 / 3.0,
|
|
|
|
|
2.0 / 3.0,
|
|
|
|
|
},
|
|
|
|
|
err: errors.New("Incompatable slice lengths len(P): 3 != len(ts): 2"),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
for _, test := range knownFails {
|
|
|
|
|
p, err := Neville(test.points, test.ts, test.t)
|
|
|
|
|
if p != nil {
|
|
|
|
|
t.Errorf("p should've been nil: %+v", p)
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if err.Error() != test.err.Error() {
|
|
|
|
|
t.Errorf("expected err: '%s', unexpectd err: '%s'", test.err, err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
tests := []struct {
|
|
|
|
|
points []Point2d
|
|
|
|
|
ts []float64
|
|
|
|
|
t float64
|
|
|
|
|
expected Point2d
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
points: []Point2d{
|
|
|
|
|
{0, 0},
|
|
|
|
|
{1, 1},
|
|
|
|
|
{2, 2},
|
|
|
|
|
},
|
|
|
|
|
ts: []float64{
|
|
|
|
|
0.0,
|
|
|
|
|
1.0 / 3.0,
|
|
|
|
|
2.0 / 3.0,
|
|
|
|
|
},
|
|
|
|
|
t: 1.0,
|
|
|
|
|
expected: Point2d{3, 3},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
for _, test := range tests {
|
|
|
|
|
p, err := Neville(test.points, test.ts, test.t)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Errorf("yeah, this should've been nil: %s", err)
|
|
|
|
|
}
|
|
|
|
|
if p == nil {
|
|
|
|
|
} else if *p != test.expected {
|
|
|
|
|
t.Errorf("wrong: expected: %+v, actual: %+v", test.expected, p)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|