MCPcopy
hub / github.com/tdewolff/canvas / TestSolveCubicFormula

Function TestSolveCubicFormula

util_test.go:313–338  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

311}
312
313func TestSolveCubicFormula(t *testing.T) {
314 var tests = []struct {
315 a, b, c, d float64
316 x1, x2, x3 float64
317 }{
318 {0.0, 1.0, 1.0, 0.25, -0.5, math.NaN(), math.NaN()}, // is quadratic formula
319 {1.0, -15.0, 75.0, -125.0, 5.0, math.NaN(), math.NaN()}, // c0 == 0, c1 == 0
320 {1.0, -3.0, -6.0, 8.0, -2.0, 1.0, 4.0}, // c0 == 0, c1 < 0
321 {1.0, -15.0, 75.0, -124.0, 4.0, math.NaN(), math.NaN()}, // c1 == 0, 0 < c0
322 {1.0, -15.0, 75.0, -126.0, 6.0, math.NaN(), math.NaN()}, // c1 == 0, c0 < 0
323 {1.0, 0.0, -7.0, 6.0, -3.0, 1.0, 2.0}, // 0 < delta
324 {1.0, -3.0, -9.0, -5.0, -1.0, 5.0, math.NaN()}, // delta == 0
325 {1.0, -4.0, 2.0, -8.0, 4.0, math.NaN(), math.NaN()}, // delta < 0, 0 < tmp
326 {1.0, -4.0, 2.0, 7.0, -1.0, math.NaN(), math.NaN()}, // delta < 0, tmp < 0
327 {16.0, -24.0, 24.0, -8.0, 0.5, math.NaN(), math.NaN()},
328 }
329
330 for _, tt := range tests {
331 t.Run(fmt.Sprintf("(%v %v %v %v)", tt.a, tt.b, tt.c, tt.d), func(t *testing.T) {
332 x1, x2, x3 := solveCubicFormula(tt.a, tt.b, tt.c, tt.d)
333 test.Float(t, x1, tt.x1)
334 test.Float(t, x2, tt.x2)
335 test.Float(t, x3, tt.x3)
336 })
337 }
338}
339
340func TestGaussLegendre(t *testing.T) {
341 test.Float(t, gaussLegendre3(math.Log, 0.0, 1.0), -0.9476723836)

Callers

nothing calls this directly

Calls 2

solveCubicFormulaFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected