MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / TestTernaryMin

Function TestTernaryMin

search/ternary_test.go:36–56  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

34}
35
36func TestTernaryMin(t *testing.T) {
37
38 var tests = []struct {
39 f func(x float64) float64
40 a float64
41 b float64
42 expected float64
43 }{
44 {f: func(x float64) float64 { return x * x }, a: -1, b: 1, expected: 0},
45 {f: func(x float64) float64 { return 2*x*x + x + 1 }, a: -1, b: 1, expected: 0.875},
46 }
47 for _, test := range tests {
48 result, err := TernaryMin(test.a, test.b, EPS, test.f)
49 if err != nil {
50 t.Errorf("error occurred: %v", err)
51 }
52 if !equal(result, test.expected) {
53 t.Errorf("Wrong result! Expected:%v, returned:%v ", test.expected, result)
54 }
55 }
56}

Callers

nothing calls this directly

Calls 2

TernaryMinFunction · 0.85
equalFunction · 0.85

Tested by

no test coverage detected