github.com/influxdata/influxdb/v2@v2.7.6/influxql/query/internal/gota/rsi_test.go (about) 1 package gota 2 3 import "testing" 4 5 func TestRSI(t *testing.T) { 6 list := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1} 7 8 // expList is generated by the following code: 9 // expList, _ := talib.Rsi(list, 10, nil) 10 expList := []float64{100, 100, 100, 100, 100, 90, 81, 72.89999999999999, 65.61, 59.04899999999999, 53.144099999999995, 47.82969, 43.04672099999999, 38.74204889999999, 34.86784400999999, 31.381059608999994, 28.242953648099995, 25.418658283289997, 22.876792454961} 11 12 rsi := NewRSI(10, WarmSMA) 13 var actList []float64 14 for _, v := range list { 15 if vOut := rsi.Add(v); rsi.Warmed() { 16 actList = append(actList, vOut) 17 } 18 } 19 20 if diff := diffFloats(expList, actList, 0.0000001); diff != "" { 21 t.Errorf("unexpected floats:\n%s", diff) 22 } 23 }