-
-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathrma_test.go
41 lines (31 loc) · 896 Bytes
/
rma_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 TestRma(t *testing.T) {
type Data struct {
Close float64
Rma float64
}
input, err := helper.ReadFromCsvFile[Data]("testdata/rma.csv", true)
if err != nil {
t.Fatal(err)
}
inputs := helper.Duplicate(input, 2)
closing := helper.Map(inputs[0], func(d *Data) float64 { return d.Close })
expected := helper.Map(inputs[1], func(d *Data) float64 { return d.Rma })
rma := trend.NewRma[float64]()
rma.Period = 15
actual := rma.Compute(closing)
actual = helper.RoundDigits(actual, 2)
expected = helper.Skip(expected, rma.IdlePeriod())
err = helper.CheckEquals(actual, expected)
if err != nil {
t.Fatal(err)
}
}