Wrote tests for the RSI function

This commit is contained in:
Luke I. Wilson
2023-05-19 17:03:00 -05:00
parent d851061d1f
commit ba92a650fb
3 changed files with 46 additions and 3 deletions

19
indicators_test.go Normal file
View File

@@ -0,0 +1,19 @@
package autotrader
import (
"testing"
)
func TestRSI(t *testing.T) {
prices := NewDataSeriesFloat("Prices", 1, 0, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 7, 6)
rsi := RSI(prices, 14)
if rsi.Len() != 14 {
t.Errorf("RSI length is %d, expected 14", rsi.Len())
}
if !EqualApprox(rsi.Float(0), 100) {
t.Errorf("RSI[0] is %f, expected 0", rsi.Float(0))
}
if !EqualApprox(rsi.Float(-1), 61.02423) {
t.Errorf("RSI[-1] is %f, expected 100", rsi.Float(-1))
}
}