-
-
Notifications
You must be signed in to change notification settings - Fork 301
/
Copy pathpivotlow_test.go
51 lines (40 loc) · 1.65 KB
/
pivotlow_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package indicator
import (
"testing"
"github.com/stretchr/testify/assert"
)
func Test_calculatePivotLow(t *testing.T) {
t.Run("normal", func(t *testing.T) {
low, ok := calculatePivotLow([]float64{15.0, 13.0, 12.0, 10.0, 14.0, 15.0}, 2, 2)
// ^left ----- ^pivot ---- ^right
assert.True(t, ok)
assert.Equal(t, 10.0, low)
low, ok = calculatePivotLow([]float64{15.0, 13.0, 12.0, 10.0, 14.0, 9.0}, 2, 2)
// ^left ----- ^pivot ---- ^right
assert.False(t, ok)
low, ok = calculatePivotLow([]float64{15.0, 9.0, 12.0, 10.0, 14.0, 15.0}, 2, 2)
// ^left ----- ^pivot ---- ^right
assert.False(t, ok)
})
t.Run("different left and right", func(t *testing.T) {
low, ok := calculatePivotLow([]float64{11.0, 12.0, 16.0, 15.0, 13.0, 12.0, 10.0, 14.0, 15.0}, 5, 2)
// ^left ---------------------- ^pivot ---- ^right
assert.True(t, ok)
assert.Equal(t, 10.0, low)
low, ok = calculatePivotLow([]float64{9.0, 8.0, 16.0, 15.0, 13.0, 12.0, 10.0, 14.0, 15.0}, 5, 2)
// ^left ---------------------- ^pivot ---- ^right
// 8.0 < 10.0
assert.False(t, ok)
assert.Equal(t, 0.0, low)
})
t.Run("right window same", func(t *testing.T) {
low, ok := calculatePivotLow([]float64{15.0, 13.0, 12.0, 10.0, 14.0, 15.0}, 2, 2)
assert.True(t, ok)
assert.Equal(t, 10.0, low)
})
t.Run("insufficient length", func(t *testing.T) {
low, ok := calculatePivotLow([]float64{15.0, 13.0, 12.0, 10.0, 14.0, 15.0}, 3, 3)
assert.False(t, ok)
assert.Equal(t, 0.0, low)
})
}