forked from sdcoffey/techan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
indicator_basic_test.go
46 lines (34 loc) · 1.04 KB
/
indicator_basic_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
package techan
import (
"testing"
"time"
"github.com/sdcoffey/big"
"github.com/stretchr/testify/assert"
)
func TestNewVolumeIndicator(t *testing.T) {
assert.NotNil(t, NewVolumeIndicator(NewTimeSeries()))
}
func TestVolumeIndicator_Calculate(t *testing.T) {
series := NewTimeSeries()
candle := NewCandle(TimePeriod{
Start: time.Now(),
End: time.Now().Add(time.Minute),
})
candle.Volume = big.NewFromString("1.2080")
series.AddCandle(candle)
indicator := NewVolumeIndicator(series)
assert.EqualValues(t, "1.208", indicator.Calculate(0).FormattedString(3))
}
func TestTypicalPriceIndicator_Calculate(t *testing.T) {
series := NewTimeSeries()
candle := NewCandle(TimePeriod{
Start: time.Now(),
End: time.Now().Add(time.Minute),
})
candle.MinPrice = big.NewFromString("1.2080")
candle.MaxPrice = big.NewFromString("1.22")
candle.ClosePrice = big.NewFromString("1.215")
series.AddCandle(candle)
typicalPrice := NewTypicalPriceIndicator(series).Calculate(0)
assert.EqualValues(t, "1.2143", typicalPrice.FormattedString(4))
}