|
| 1 | +package indicatorv2 |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | + |
| 8 | + "github.com/c9s/bbgo/pkg/types" |
| 9 | +) |
| 10 | + |
| 11 | +func TestMAX(t *testing.T) { |
| 12 | + source := types.NewFloat64Series() |
| 13 | + maxIndicator := MAX(source, 3) |
| 14 | + |
| 15 | + // Test case 1: Fill the window |
| 16 | + source.PushAndEmit(1.0) |
| 17 | + assert.Equal(t, 1.0, maxIndicator.Last(0)) |
| 18 | + |
| 19 | + source.PushAndEmit(3.0) |
| 20 | + assert.Equal(t, 3.0, maxIndicator.Last(0)) |
| 21 | + |
| 22 | + source.PushAndEmit(2.0) |
| 23 | + assert.Equal(t, 3.0, maxIndicator.Last(0)) |
| 24 | + |
| 25 | + // Test case 2: Sliding window |
| 26 | + source.PushAndEmit(1.0) |
| 27 | + // Window is [3.0, 2.0, 1.0], max is 3.0 |
| 28 | + assert.Equal(t, 3.0, maxIndicator.Last(0)) |
| 29 | + |
| 30 | + source.PushAndEmit(0.5) |
| 31 | + // Window is [2.0, 1.0, 0.5], max is 2.0 |
| 32 | + assert.Equal(t, 2.0, maxIndicator.Last(0)) |
| 33 | + |
| 34 | + source.PushAndEmit(4.0) |
| 35 | + // Window is [1.0, 0.5, 4.0], max is 4.0 |
| 36 | + assert.Equal(t, 4.0, maxIndicator.Last(0)) |
| 37 | +} |
0 commit comments