-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(series): move to individual module
- Loading branch information
1 parent
23b1be0
commit 2879dc5
Showing
7 changed files
with
83 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package series | ||
|
||
type Series []float64 | ||
|
||
func (s Series) Values() []float64 { | ||
return s | ||
} | ||
|
||
func (s Series) Last(position int) float64 { | ||
return s[len(s)-1-position] | ||
} | ||
|
||
func (s Series) LastValues(size int) []float64 { | ||
if l := len(s); l > size { | ||
return s[l-size:] | ||
} | ||
return s | ||
} | ||
|
||
func (s Series) Crossover(ref Series) bool { | ||
return s.Last(0) > ref.Last(0) && s.Last(1) <= ref.Last(1) | ||
} | ||
|
||
func (s Series) Crossunder(ref Series) bool { | ||
return s.Last(0) <= ref.Last(0) && s.Last(1) > ref.Last(1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package series | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestSeries_Last(t *testing.T) { | ||
series := Series([]float64{1, 2, 3, 4, 5}) | ||
require.Equal(t, 5.0, series.Last(0)) | ||
require.Equal(t, 3.0, series.Last(2)) | ||
} | ||
|
||
func TestSeries_LastValues(t *testing.T) { | ||
t.Run("with value", func(t *testing.T) { | ||
series := Series([]float64{1, 2, 3, 4, 5}) | ||
require.Equal(t, []float64{4, 5}, series.LastValues(2)) | ||
}) | ||
|
||
t.Run("empty", func(t *testing.T) { | ||
series := Series([]float64{}) | ||
require.Empty(t, series.LastValues(2)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters