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

Function TestTernaryMax

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

Source from the content-addressed store, hash-verified

12}
13
14func TestTernaryMax(t *testing.T) {
15
16 var tests = []struct {
17 f func(x float64) float64
18 a float64
19 b float64
20 expected float64
21 }{
22 {f: func(x float64) float64 { return -x * x }, a: 1, b: -1, expected: 0},
23 {f: func(x float64) float64 { return -2*x*x - x + 1 }, a: -1, b: 1, expected: 1.125},
24 }
25 for _, test := range tests {
26 result, err := TernaryMax(test.a, test.b, EPS, test.f)
27 if err != nil {
28 t.Errorf("error occurred: %v", err)
29 }
30 if !equal(result, test.expected) {
31 t.Errorf("Wrong result! Expected:%v, returned:%v ", test.expected, result)
32 }
33 }
34}
35
36func TestTernaryMin(t *testing.T) {
37

Callers

nothing calls this directly

Calls 2

TernaryMaxFunction · 0.85
equalFunction · 0.85

Tested by

no test coverage detected