forked from cinar/indicator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnvi_test.go
39 lines (31 loc) · 992 Bytes
/
nvi_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
// Copyright (c) 2021-2024 Onur Cinar.
// The source code is provided under GNU AGPLv3 License.
// https://github.com/cinar/indicator
package volume_test
import (
"testing"
"github.com/cinar/indicator/v2/helper"
"github.com/cinar/indicator/v2/volume"
)
func TestNvi(t *testing.T) {
type NviData struct {
Close float64
Volume int64
Nvi float64
}
input, err := helper.ReadFromCsvFile[NviData]("testdata/nvi.csv", true)
if err != nil {
t.Fatal(err)
}
inputs := helper.Duplicate(input, 3)
closings := helper.Map(inputs[0], func(m *NviData) float64 { return m.Close })
volumes := helper.Map(inputs[1], func(m *NviData) float64 { return float64(m.Volume) })
expected := helper.Map(inputs[2], func(m *NviData) float64 { return m.Nvi })
nvi := volume.NewNvi[float64]()
actual := helper.RoundDigits(nvi.Compute(closings, volumes), 2)
expected = helper.Skip(expected, nvi.IdlePeriod())
err = helper.CheckEquals(actual, expected)
if err != nil {
t.Fatal(err)
}
}