forked from sdcoffey/techan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rule_increase_decrease_test.go
65 lines (47 loc) · 1.59 KB
/
rule_increase_decrease_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package techan
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestIncreaseRule(t *testing.T) {
t.Run("returns false when index == 0", func(t *testing.T) {
rule := IncreaseRule{}
assert.False(t, rule.IsSatisfied(0, nil))
})
t.Run("returns true when increase", func(t *testing.T) {
series := mockTimeSeries("1", "2")
rule := IncreaseRule{NewClosePriceIndicator(series)}
assert.True(t, rule.IsSatisfied(1, nil))
})
t.Run("returns false when same", func(t *testing.T) {
series := mockTimeSeries("1", "1")
rule := IncreaseRule{NewClosePriceIndicator(series)}
assert.False(t, rule.IsSatisfied(1, nil))
})
t.Run("returns false when decrease", func(t *testing.T) {
series := mockTimeSeries("1", "0")
rule := IncreaseRule{NewClosePriceIndicator(series)}
assert.False(t, rule.IsSatisfied(1, nil))
})
}
func TestDecreaseRule(t *testing.T) {
t.Run("returns false when index == 0", func(t *testing.T) {
rule := DecreaseRule{}
assert.False(t, rule.IsSatisfied(0, nil))
})
t.Run("returns true when decrease", func(t *testing.T) {
series := mockTimeSeries("1", "0")
rule := DecreaseRule{NewClosePriceIndicator(series)}
assert.True(t, rule.IsSatisfied(1, nil))
})
t.Run("returns false when decrease", func(t *testing.T) {
series := mockTimeSeries("1", "2")
rule := DecreaseRule{NewClosePriceIndicator(series)}
assert.False(t, rule.IsSatisfied(1, nil))
})
t.Run("returns false when same", func(t *testing.T) {
series := mockTimeSeries("1", "1")
rule := IncreaseRule{NewClosePriceIndicator(series)}
assert.False(t, rule.IsSatisfied(1, nil))
})
}