-
Notifications
You must be signed in to change notification settings - Fork 6
/
multi_test.go
39 lines (29 loc) · 981 Bytes
/
multi_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
package movavg_test
import (
. "github.com/mxmCherry/movavg"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("Multi", func() {
var _ MultiMA = Multi(nil)
It("groups several moving average calculators", func() {
subject := Multi{
NewSMA(2),
NewSMA(3),
NewSMA(4),
}
// zero until values added:
Expect(subject.Avg()).To(Equal([]float64{0, 0, 0}))
// load initial value
Expect(subject.Add(2)).To(Equal([]float64{2, 2, 2}))
Expect(subject.Avg()).To(Equal([]float64{2, 2, 2}))
Expect(subject.Add(4)).To(Equal([]float64{3, 3, 3}))
Expect(subject.Avg()).To(Equal([]float64{3, 3, 3}))
Expect(subject.Add(6)).To(Equal([]float64{5, 4, 4}))
Expect(subject.Avg()).To(Equal([]float64{5, 4, 4}))
Expect(subject.Add(8)).To(Equal([]float64{7, 6, 5}))
Expect(subject.Avg()).To(Equal([]float64{7, 6, 5}))
Expect(subject.Add(10)).To(Equal([]float64{9, 8, 7}))
Expect(subject.Avg()).To(Equal([]float64{9, 8, 7}))
})
})