forked from sdcoffey/techan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rule_cross_test.go
41 lines (31 loc) · 1.09 KB
/
rule_cross_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
package techan
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestCrossUpIndicatorRule(t *testing.T) {
upInd := NewFixedIndicator(3, 4, 5, 6)
dnInd := NewFixedIndicator(6, 5, 4, 3)
rule := NewCrossUpIndicatorRule(dnInd, upInd)
t.Run("always returns false when index == 0", func(t *testing.T) {
assert.False(t, rule.IsSatisfied(0, nil))
})
t.Run("Returns true when lower indicator crosses upper indicator", func(t *testing.T) {
assert.False(t, rule.IsSatisfied(1, nil))
assert.True(t, rule.IsSatisfied(2, nil))
assert.True(t, rule.IsSatisfied(3, nil))
})
}
func TestCrossDownIndicatorRule(t *testing.T) {
upInd := NewFixedIndicator(3, 4, 5, 6)
dnInd := NewFixedIndicator(6, 5, 4, 3)
rule := NewCrossDownIndicatorRule(dnInd, upInd)
t.Run("returns false when index == 0", func(t *testing.T) {
assert.False(t, rule.IsSatisfied(0, nil))
})
t.Run("returns true when upper indicator crosses below lower indicator", func(t *testing.T) {
assert.False(t, rule.IsSatisfied(1, nil))
assert.True(t, rule.IsSatisfied(2, nil))
assert.True(t, rule.IsSatisfied(3, nil))
})
}