-
-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathmass_index_test.go
41 lines (32 loc) · 1016 Bytes
/
mass_index_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
// Copyright (c) 2021-2024 Onur Cinar.
// The source code is provided under GNU AGPLv3 License.
// https://github.com/cinar/indicator
package trend_test
import (
"testing"
"github.com/cinar/indicator/v2/helper"
"github.com/cinar/indicator/v2/trend"
)
func TestMassIndex(t *testing.T) {
type Data struct {
Open float64
Close float64
MassIndex float64
}
input, err := helper.ReadFromCsvFile[Data]("testdata/mass_index.csv", true)
if err != nil {
t.Fatal(err)
}
inputs := helper.Duplicate(input, 3)
openings := helper.Map(inputs[0], func(d *Data) float64 { return d.Open })
closings := helper.Map(inputs[1], func(d *Data) float64 { return d.Close })
expected := helper.Map(inputs[2], func(d *Data) float64 { return d.MassIndex })
mi := trend.NewMassIndex[float64]()
actual := mi.Compute(openings, closings)
actual = helper.RoundDigits(actual, 2)
actual = helper.Shift(actual, mi.IdlePeriod(), 0)
err = helper.CheckEquals(actual, expected)
if err != nil {
t.Fatal(err)
}
}